1. 前言 前一篇配置SQL Server on Linux(1),地址:http://www.cnblogs.com/fishparadise/p/8125203.html ,是關於更改資料庫排序規則的。實現的原理跟在Windows平臺差不多,都是需要備份用戶資料庫,重建系統資料庫來實現的,不過操 ...
1. 前言
前一篇配置SQL Server on Linux(1),地址:http://www.cnblogs.com/fishparadise/p/8125203.html ,是關於更改資料庫排序規則的。實現的原理跟在Windows平臺差不多,都是需要備份用戶資料庫,重建系統資料庫來實現的,不過操作過程簡化了。下麵的配置是一些常規的設置,比如最大記憶體,預設數據文件位置,等。
2. 環境
Linux: CentOS 7.4,SQL Server 2017 (RC2) - 14.0.900.75 (X64)
3. 更改設置
3.1 記憶體限制
使用mssql-conf工具
/opt/mssql/bin/mssql-conf set memory.memorylimitmb 3500
重啟資料庫實例
systemctl restart mssql-server
疑問
以上方法是官方的步驟,但使用SSMS去查看實例的記憶體設置,發現最大記憶體限制還是沒有改變。不知道為什麼。使用sys.sp_configure去配置最大記憶體則生效了。
EXEC sys.sp_configure N'show advanced options', N'1' RECONFIGURE WITH OVERRIDE GO EXEC sys.sp_configure N'max server memory (MB)', N'3500' GO RECONFIGURE WITH OVERRIDE GO EXEC sys.sp_configure N'show advanced options', N'0' RECONFIGURE WITH OVERRIDE GO
3.2 設置預設數據或日誌目錄位置
創建自定義目錄及更改目錄許可權
[root@134test ~]# mkdir -p /data/mssql_data/ [root@134test ~]# chown -R mssql:mssql /data/mssql_data/
使用mssql-conf工具
[root@134test ~]# /opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /data/mssql_data/ SQL Server needs to be restarted in order to apply this setting. Please run 'systemctl restart mssql-server.service'.
重啟資料庫實例生效
systemctl restart mssql-server
測試(數據和日誌文件都在這個目錄下)
4> create database db2; 5> go
[root@134test ~]# cd /data/mssql_data/ [root@134test /data/mssql_data]# ll db* -rw-rw---- 1 mssql mssql 3932160 2017-12-27 12:31 db1_log.ldf -rw-rw---- 1 mssql mssql 12582912 2017-12-27 12:31 db1.mdf -rw-rw---- 1 mssql mssql 8388608 2017-12-27 12:37 db2_log.ldf -rw-rw---- 1 mssql mssql 8388608 2017-12-27 12:33 db2.mdf
如果需要單獨更改日誌的目錄(如/tmp)
/opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /tmp/
3.3 更改 TCP 埠
使用mssql-conf工具
/opt/mssql/bin/mssql-conf set network.tcpport <new_tcp_port>
重啟實例生效
[root@134test ~]# systemctl restart mssql-server
測試
[root@134test ~# /opt/mssql/bin/mssql-conf set network.tcpport 1444 SQL Server needs to be restarted in order to apply this setting. Please run 'systemctl restart mssql-server.service'. [root@134test ~]# systemctl restart mssql-server
[root@134test ~]# sqlcmd -S localhost -U sa Password: Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2749. Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred
while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct
and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
[root@134test ~]# sqlcmd -S localhost,1444 -U sa Password: 1>
3.4 刪除設置
使用mssql-conf工具的unset命令
/opt/mssql/bin/mssql-conf unset network.tcpport /opt/mssql/bin/mssql-conf unset memory.memorylimitmb ……
重啟實例生效
[root@134test ~]# systemctl restart mssql-server
3.5 查看當前設置及配置文件
cat /var/opt/mssql/mssql.conf
以下是官方提供的一個示例配置。可根據實際需要直接修改/var/opt/mssql/mssql.conf,最後重啟資料庫實例生效。未在此文件中顯示的所有設置均使用其預設值。
[EULA] accepteula = Y [coredump] captureminiandfull = true coredumptype = full [filelocation] defaultbackupdir = /var/opt/mssql/data/ defaultdatadir = /var/opt/mssql/data/ defaultdumpdir = /var/opt/mssql/data/ defaultlogdir = /var/opt/mssql/data/ [hadr] hadrenabled = 0 [language] lcid = 1033 [memory] memorylimitmb = 4096 [network] forceencryption = 0 ipaddress = 10.192.0.0 kerberoskeytabfile = /var/opt/mssql/secrets/mssql.keytab tcpport = 1401 tlscert = /etc/ssl/certs/mssql.pem tlsciphers = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA tlskey = /etc/ssl/private/mssql.key tlsprotocols = 1.2,1.1,1.0 [sqlagent] databasemailprofile = default errorlogfile = /var/opt/mssql/log/sqlagentlog.log errorlogginglevel = 7 [telemetry] customerfeedback = true userrequestedlocalauditdirectory = /tmp/audit [traceflag] traceflag0 = 1204 traceflag1 = 2345 traceflag = 3456
4. 參考
更多的配置,請參考微軟的官方文檔:https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-configure-mssql-conf