使用 mssql-conf 工具配置 Linux 上的 SQL ServerConfigure SQL Server on Linux with the mssql-conf tool

本主题适用于: 是SQL Server (仅限 Linux)没有Azure SQL 数据库没有Azure SQL 数据仓库没有并行数据仓库 THIS TOPIC APPLIES TO: yesSQL Server (Linux only)noAzure SQL DatabasenoAzure SQL Data WarehousenoParallel Data Warehouse

mssql conf是将与 SQL Server 2017 为 Red Hat Enterprise Linux、 SUSE Linux 企业服务器和 Ubuntu 安装的配置脚本。mssql-conf is a configuration script that installs with SQL Server 2017 for Red Hat Enterprise Linux, SUSE Linux Enterprise Server, and Ubuntu. 可以使用此实用工具设置以下参数:You can use this utility to set the following parameters:

代理Agent 启用 SQL Server 代理Enable SQL Server Agent
排序规则Collation 在 Linux 上,为 SQL Server 设置新的排序规则。Set a new collation for SQL Server on Linux.
客户反馈Customer feedback 选择 SQL Server 向 Microsoft 发送反馈。Choose whether or not SQL Server sends feedback to Microsoft.
数据库邮件配置文件Database Mail Profile 设置在 Linux 上的 SQL Server 的默认数据库邮件配置文件Set the default database mail profile for SQL Server on Linux
默认数据目录Default data directory 更改新的 SQL Server 数据库数据文件 (.mdf) 的默认目录。Change the default directory for new SQL Server database data files (.mdf).
默认日志目录Default log directory 更改新的 SQL Server 数据库日志 (.ldf) 文件的默认目录。Changes the default directory for new SQL Server database log (.ldf) files.
默认 master 数据库文件目录Default master database file directory 更改现有的 SQL 安装上的 master 数据库文件的默认目录。Changes the default directory for the master database files on existing SQL installation.
默认 master 数据库文件名称Default master database file name 更改 master 数据库文件的名称。Changes the name of master database files.
默认转储目录Default dump directory 更改新内存转储和其他故障排除的文件的默认目录。Change the default directory for new memory dumps and other troubleshooting files.
默认错误日志目录Default error log directory 更改新的 SQL Server 错误日志、 默认事件探查器跟踪、 系统运行状况会话 XE,和 Hekaton 会话 XE 文件的默认目录。Changes the default directory for new SQL Server ErrorLog, Default Profiler Trace, System Health Session XE, and Hekaton Session XE files.
默认备份目录Default backup directory 更改新的备份文件的默认目录。Change the default directory for new backup files.
转储类型Dump type 选择要收集的转储内存转储文件的类型。Choose the type of dump memory dump file to collect.
高可用性High availability 启用可用性组。Enable Availability Groups.
本地审核目录Local Audit directory 设置要添加本地审核文件的目录。Set a a directory to add Local Audit files.
区域设置Locale 设置 SQL Server 以使用的区域设置。Set the locale for SQL Server to use.
内存限制Memory limit 设置 SQL Server 的内存限制。Set the memory limit for SQL Server.
TCP 端口TCP port 更改 SQL Server 侦听的连接的端口。Change the port where SQL Server listens for connections.
TLSTLS 配置传输级安全。Configure Transport Level Security.
跟踪标志Traceflags 设置服务要使用这些跟踪标志。Set the traceflags that the service is going to use.

提示

其中某些设置还可以使用环境变量配置。Some of these settings can also be configured with environment variables. 有关详细信息,请参阅与环境变量配置 SQL Server 设置For more information, see Configure SQL Server settings with environment variables.

使用提示Usage tips

  • 有关 Alwayson 可用性组和共享的磁盘群集,始终在每个节点上进行相同的配置更改。For Always On Availability Groups and shared disk clusters, always make the same configuration changes on each node.

  • 对于共享的磁盘群集方案,请不要尝试重新启动mssql server服务以应用更改。For the shared disk cluster scenario, do not attempt to restart the mssql-server service to apply changes. SQL Server 正在运行为应用程序。SQL Server is running as an application. 相反,使资源脱机再然后恢复联机。Instead, take the resource offline and then back online.

  • 运行 mssql-conf 通过这些示例指定完整路径: /opt/mssql/bin/mssql-confThese examples run mssql-conf by specify the full path: /opt/mssql/bin/mssql-conf. 如果你选择请改为导航到该路径,在当前目录的上下文中运行 mssql conf: 。 / mssql confIf you choose to navigate to that path instead, run mssql-conf in the context of the current directory: ./mssql-conf.

启用 SQL Server 代理Enable SQL Server Agent

Sqlagent.enabled设置可让SQL Server 代理The sqlagent.enabled setting enables SQL Server Agent. 默认情况下,SQL Server 代理为禁用状态。By default, SQL Server Agent is disabled. 如果sqlagent.enabled中不存在 mssql.conf 设置文件,然后 SQL Server 内部假定是否启用了 SQL Server 代理。If sqlagent.enabled is not present in the mssql.conf settings file, then SQL Server internally assumes that SQL Server Agent is enabled.

若要更改此设置,请使用以下步骤:To change this settings, use the following steps:

  1. 启用 SQL Server 代理:Enable the SQL Server Agent:

    sudo /opt/mssql/bin/mssql-conf set sqlagent.enabled true 
    
  2. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    

更改 SQL Server 排序规则Change the SQL Server collation

集排序规则选项的排序规则值更改为任何支持的排序规则。The set-collation option changes the collation value to any of the supported collations.

  1. 第一个备份任何用户数据库你的服务器上。First backup any user databases on your server.

  2. 然后使用sp_detach_db存储过程来分离用户数据库。Then use the sp_detach_db stored procedure to detach the user databases.

  3. 运行集排序规则选项并按照提示进行操作:Run the set-collation option and follow the prompts:

    sudo /opt/mssql/bin/mssql-conf set-collation
    
  4. Mssql conf 实用程序将尝试将更改为指定的排序规则值并重新启动服务。The mssql-conf utility will attempt to change to the specified collation value and restart the service. 如果不存在任何错误,它将回滚排序规则到以前的值。If there are any errors, it rolls back the collation to the previous value.

  5. 还原用户数据库备份。Retore your user database backups.

支持的排序列表,请运行sys.fn_helpcollations函数: SELECT Name from sys.fn_helpcollations()For a list of supported collations, run the sys.fn_helpcollations function: SELECT Name from sys.fn_helpcollations().

配置客户反馈Configure customer feedback

Telemetry.customerfeedback是否 SQL Server 向 Microsoft 发送反馈,或不设置更改。The telemetry.customerfeedback setting changes whether SQL Server sends feedback to Microsoft or not. 默认情况下,此值设置为trueBy default, this value is set to true. 若要更改的值,请运行以下命令:To change the value, run the following commands:

  1. Mssql conf 脚本作为根与运行设置命令telemetry.customerfeedbackRun the mssql-conf script as root with the set command for telemetry.customerfeedback. 下面的示例通过指定关闭客户反馈falseThe following example turns off customer feedback by specifying false.

    sudo /opt/mssql/bin/mssql-conf set telemetry.customerfeedback false
    
  2. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    

有关详细信息,请参阅在 Linux 上的 SQL Server 的客户反馈For more information, see Customer Feedback for SQL Server on Linux.

默认数据或日志目录位置更改Change the default data or log directory location

Filelocation.defaultdatadirfilelocation.defaultlogdir设置更改其中创建新的数据库和日志文件的位置。The filelocation.defaultdatadir and filelocation.defaultlogdir settings change the location where the new database and log files are created. 默认情况下,此位置为 /var/opt/mssql/data。By default, this location is /var/opt/mssql/data. 若要更改这些设置,请使用以下步骤:To change these settings, use the following steps:

  1. 创建新数据库的目标目录数据和日志文件。Create the target directory for new database data and log files. 下面的示例创建一个新/tmp/数据目录:The following example creates a new /tmp/data directory:

    sudo mkdir /tmp/data
    
  2. 更改所有者和到的目录组mssql用户:Change the owner and group of the directory to the mssql user:

    sudo chown mssql /tmp/data
    sudo chgrp mssql /tmp/data
    
  3. 使用 mssql conf 更改使用的默认数据目录设置命令:Use mssql-conf to change the default data directory with the set command:

    sudo /opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /tmp/data
    
  4. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    
  5. 现在,已创建的新数据库的所有数据库文件都将存储在此新位置。Now all the database files for the new databases created will be stored in this new location. 如果要更改新数据库的日志文件 (.ldf) 位置,可以使用下面的“set”命令:If you would like to change the location of the log (.ldf) files of the new databases, you can use the following "set" command:

    sudo /opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /tmp/log
    
  6. 此命令还假定/tmp/日志目录存在,并且它位于用户和组mssqlThis command also assumes that a /tmp/log directory exists, and that it is under the user and group mssql.

更改默认 master 数据库文件目录位置Change the default master database file directory location

Filelocation.masterdatafilefilelocation.masterlogfile设置 SQL Server 引擎查找 master 数据库文件的位置的更改。The filelocation.masterdatafile and filelocation.masterlogfile setting changes the location where the SQL Server engine looks for the master database files. 默认情况下,此位置为 /var/opt/mssql/data。By default, this location is /var/opt/mssql/data.

若要更改这些设置,请使用以下步骤:To change these settings, use the following steps:

  1. 创建新的错误日志文件的目标目录。Create the target directory for new error log files. 下面的示例创建一个新/tmp/masterdatabasedir目录:The following example creates a new /tmp/masterdatabasedir directory:

    sudo mkdir /tmp/masterdatabasedir
    
  2. 更改所有者和到的目录组mssql用户:Change the owner and group of the directory to the mssql user:

    sudo chown mssql /tmp/masterdatabasedir
    sudo chgrp mssql /tmp/masterdatabasedir
    
  3. 使用 mssql conf 更改使用的主数据和日志文件的默认 master 数据库目录设置命令:Use mssql-conf to change the default master database directory for the master data and log files with the set command:

    sudo /opt/mssql/bin/mssql-conf set filelocation.masterdatafile /tmp/masterdatabasedir/master.mdf
    sudo /opt/mssql/bin/mssql-conf set filelocation.masterlogfile /tmp/masterdatabasedir/mastlog.ldf
    
  4. 停止 SQL Server 服务:Stop the SQL Server service:

    sudo systemctl stop mssql-server
    
  5. 将 master.mdf 和 masterlog.ldf 移动:Move the master.mdf and masterlog.ldf:

    sudo mv /var/opt/mssql/data/master.mdf /tmp/masterdatabasedir/master.mdf 
    sudo mv /var/opt/mssql/data/mastlog.ldf /tmp/masterdatabasedir/mastlog.ldf
    
  6. 启动 SQL Server 服务:Start the SQL Server service:

    sudo systemctl start mssql-server
    

备注

如果 SQL Server 找不到指定目录中的 master.mdf 和 mastlog.ldf 文件,将在指定的目录中,自动创建模板化副本的系统数据库和 SQL Server 已成功启动。If SQL Server cannot find master.mdf and mastlog.ldf files in the specified directory, a templated copy of the system databases will be automatically created in the specified directory, and SQL Server will successfully start up. 但是,元数据,例如用户数据库、 服务器登录名、 服务器证书、 加密密钥、 SQL 代理作业或旧 SA 登录密码将不会在新的 master 数据库中更新。However, metadata such as user databases, server logins, server certificates, encryption keys, SQL agent jobs, or old SA login password will not be updated in the new master database. 你将需要停止 SQL Server 并重将你的旧 master.mdf 和 mastlog.ldf 移动到新的指定位置,然后启动 SQL Server 以继续使用现有元数据。You will have to stop SQL Server and move your old master.mdf and mastlog.ldf to the new specified location and start SQL Server to continue using the existing metadata.

更改 master 数据库文件的名称。Change the name of master database files.

Filelocation.masterdatafilefilelocation.masterlogfile设置 SQL Server 引擎查找 master 数据库文件的位置的更改。The filelocation.masterdatafile and filelocation.masterlogfile setting changes the location where the SQL Server engine looks for the master database files. 默认情况下,此位置为 /var/opt/mssql/data。By default, this location is /var/opt/mssql/data. 若要更改这些设置,请使用以下步骤:To change these settings, use the following steps:

  1. 停止 SQL Server 服务:Stop the SQL Server service:

    sudo systemctl stop mssql-server
    
  2. 使用 mssql conf 更改使用的主数据和日志文件的主数据库的预期的名称设置命令:Use mssql-conf to change the expected master database names for the master data and log files with the set command:

    sudo /opt/mssql/bin/mssql-conf set filelocation.masterdatafile /var/opt/mssql/data/masternew.mdf
    sudo /opt/mssql/bin/mssql-conf set filelocation.mastlogfile /var/opt/mssql/data /mastlognew.ldf
    
  3. 更改 master 数据库数据和日志文件的名称Change the name of the master database data and log files

    sudo mv /var/opt/mssql/data/master.mdf /var/opt/mssql/data/masternew.mdf
    sudo mv /var/opt/mssql/data/mastlog.ldf /var/opt/mssql/data/mastlognew.ldf
    
  4. 启动 SQL Server 服务:Start the SQL Server service:

    sudo systemctl start mssql-server
    

更改默认转储目录位置Change the default dump directory location

Filelocation.defaultdumpdir设置的内存和 SQL 转储生成崩溃时的默认位置的更改。The filelocation.defaultdumpdir setting changes the default location where the memory and SQL dumps are generated whenever there is a crash. 默认情况下,这些文件在 /var/opt/mssql/log 中生成。By default, these files are generated in /var/opt/mssql/log.

若要设置此新位置,请使用以下命令:To set up this new location, use the following commands:

  1. 创建新的转储文件的目标目录。Create the target directory for new dump files. 下面的示例创建一个新/tmp/转储目录:The following example creates a new /tmp/dump directory:

    sudo mkdir /tmp/dump
    
  2. 更改所有者和到的目录组mssql用户:Change the owner and group of the directory to the mssql user:

    sudo chown mssql /tmp/dump
    sudo chgrp mssql /tmp/dump
    
  3. 使用 mssql conf 更改使用的默认数据目录设置命令:Use mssql-conf to change the default data directory with the set command:

    sudo /opt/mssql/bin/mssql-conf set filelocation.defaultdumpdir /tmp/dump
    
  4. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    

更改默认错误日志文件目录位置Change the default error log file directory location

Filelocation.errorlogfile设置创建新的错误日志、 默认事件探查器跟踪、 系统运行状况会话 XE 和 Hekaton 会话 XE 文件的位置的更改。The filelocation.errorlogfile setting changes the location where the new error log, default profiler trace, system health session XE and Hekaton session XE files are created. 默认情况下,此位置是 /var/opt/mssql/log。By default, this location is /var/opt/mssql/log. 在其中设置 SQL 错误日志文件的目录将成为其他日志的默认日志目录。The directory in which SQL errorlog file is set becomes the default log directory for other logs.

若要更改这些设置:To change these settings:

  1. 创建新的错误日志文件的目标目录。Create the target directory for new error log files. 下面的示例创建一个新/tmp/logs目录:The following example creates a new /tmp/logs directory:

    sudo mkdir /tmp/logs
    
  2. 更改所有者和到的目录组mssql用户:Change the owner and group of the directory to the mssql user:

    sudo chown mssql /tmp/logs
    sudo chgrp mssql /tmp/logs
    
  3. 使用 mssql conf 更改的默认错误日志文件名设置命令:Use mssql-conf to change the default errorlog filename with the set command:

    sudo /opt/mssql/bin/mssql-conf set filelocation.errorlogfile /tmp/logs/errorlog
    
  4. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    

更改默认备份目录位置Change the default backup directory location

Filelocation.defaultbackupdir设置中生成的备份文件的默认位置的更改。The filelocation.defaultbackupdir setting changes the default location where the backup files are generated. 默认情况下,这些文件在 /var/opt/mssql/data 中生成。By default, these files are generated in /var/opt/mssql/data.

若要设置此新位置,请使用以下命令:To set up this new location, use the following commands:

  1. 创建新的备份文件的目标目录。Create the target directory for new backup files. 下面的示例创建一个新/tmp/备份目录:The following example creates a new /tmp/backup directory:

    sudo mkdir /tmp/backup
    
  2. 更改所有者和到的目录组mssql用户:Change the owner and group of the directory to the mssql user:

    sudo chown mssql /tmp/backup
    sudo chgrp mssql /tmp/backup
    
  3. 使用 mssql-conf 通过“set”命令更改默认备份目录:Use mssql-conf to change the default backup directory with the "set" command:

    sudo /opt/mssql/bin/mssql-conf set filelocation.defaultbackupdir /tmp/backup
    
  4. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    

指定核心转储设置Specify core dump settings

如果一个 SQL Server 进程中发生异常,SQL Server 会创建内存转储。If an exception occurs in one of the SQL Server processes, SQL Server creates a memory dump.

有两个选项的 SQL Server 收集控制的一种内存转储: coredump.coredumptypecoredump.captureminiandfullThere are two options for controlling the type of memory dumps that SQL Server collects: coredump.coredumptype and coredump.captureminiandfull. 这两个选项与核心转储捕获的两个阶段相关。These relate to the two phases of core dump capture.

第一个阶段捕获受coredump.coredumptype设置,确定在异常过程中生成的转储文件的类型。The first phase capture is controlled by the coredump.coredumptype setting, which determines the type of dump file generated during an exception. 第二个阶段时,启用选项coredump.captureminiandfull设置。The second phase is enabled when the coredump.captureminiandfull setting. 如果coredump.captureminiandfull设置为 true,转储文件指定coredump.coredumptype生成,并且还生成第二个的小型转储。If coredump.captureminiandfull is set to true, the dump file specified by coredump.coredumptype is generated and a second mini dump is also generated. 设置coredump.captureminiandfull为 false 则禁止尝试第二个捕获。Setting coredump.captureminiandfull to false disables the second capture attempt.

  1. 决定是否要捕获与微型和完整转储coredump.captureminiandfull设置。Decide whether to capture both mini and full dumps with the coredump.captureminiandfull setting.

    sudo /opt/mssql/bin/mssql-conf set coredump.captureminiandfull <true or false>
    

    默认值: falseDefault: false

  2. 指定的转储文件的类型coredump.coredumptype设置。Specify the type of dump file with the coredump.coredumptype setting.

    sudo /opt/mssql/bin/mssql-conf set coredump.coredumptype <dump_type>
    

    默认值: miniplusDefault: miniplus

    下表列出可能coredump.coredumptype值。The following table lists the possible coredump.coredumptype values.

    类型Type DescriptionDescription
    迷你mini mini 是最小的转储文件类型。Mini is the smallest dump file type. 它使用 Linux 系统信息确定进程中的线程和模块。It uses the Linux system information to determine threads and modules in the process. 转储仅包含主机环境线程堆栈和模块。The dump contains only the host environment thread stacks and modules. 不包含间接内存引用或全局变量。It does not contain indirect memory references or globals.
    miniplusminiplus MiniPlus 与 mini 相似,但它包括更多内存。MiniPlus is similar to mini, but it includes additional memory. 它理解 SQLPAL 和主机环境中,将以下的内存区域添加到转储的内部结构:It understands the internals of SQLPAL and the host environment, adding the following memory regions to the dump:
    -各种全局函数- Various globals
    的所有内存超过 64 TB- All memory above 64TB
    -All 名为区域中找到/proc/$ pid/映射- All named regions found in /proc/$pid/maps
    双向从线程和堆栈的间接内存- Indirect memory from threads and stacks
    线程信息- Thread information
    -关联 Teb 的和 Peb 的- Associated Teb’s and Peb’s
    模块信息- Module Information
    VMM 和 VAD 树- VMM and VAD tree
    filteredfiltered filtered 采用基于减法的设计,包括进程中的所有内存,除非专门排除某些内存。Filtered uses a subtraction-based design where all memory in the process is included unless specifically excluded. 此设计理解 SQLPAL 的内部机制和宿主环境,从转储中排除某些区域。The design understands the internals of SQLPAL and the host environment, excluding certain regions from the dump.
    fullfull 完整的整个过程转储中包括所有区域位于/proc/$ pid/映射Full is a complete process dump that includes all regions located in /proc/$pid/maps. 这不受coredump.captureminiandfull设置。This is not controlled by coredump.captureminiandfull setting.

设置在 Linux 上的 SQL Server 的默认数据库邮件配置文件Set the default database mail profile for SQL Server on Linux

Sqlpagent.databasemailprofile可以设置电子邮件警报的默认数据库邮件配置文件。The sqlpagent.databasemailprofile allows you to set the default DB Mail profile for email alerts.

sudo /opt/mssq/bin/mssql-conf set sqlagent.databasemailprofile <profile_name>

高可用性High Availability

Hadr.hadrenabled选项使您的 SQL Server 实例上的可用性组。The hadr.hadrenabled option enables availability groups on your SQL Server instance. 以下命令通过设置可使可用性组hadr.hadrenabled为 1。The following command enables availability groups by setting hadr.hadrenabled to 1. 必须重启 SQL Server,该设置才能生效。You must restart SQL Server for the setting to take effect.

sudo /opt/mssql/bin/mssql-conf set hadr.hadrenabled  1
sudo systemctl restart mssql-server

有关如何将此项用于可用性组的信息,请参阅以下两个主题。For information how this is used with availability groups, see the following two topics.

设置本地审核目录Set local audit directory

Telemetry.userrequestedlocalauditdirectory设置启用本地审核和创建的允许你设置目录,其中本地的审核日志。The telemetry.userrequestedlocalauditdirectory setting enables Local Audit and lets you set the directory where the Local Audit logs are created.

  1. 创建新的本地审核日志的目标目录。Create a target directory for new Local Audit logs. 下面的示例创建一个新/tmp/审核目录:The following example creates a new /tmp/audit directory:

    sudo mkdir /tmp/audit
    
  2. 更改所有者和到的目录组mssql用户:Change the owner and group of the directory to the mssql user:

    sudo chown mssql /tmp/audit
    sudo chgrp mssql /tmp/audit
    
  3. Mssql conf 脚本作为根与运行设置命令telemetry.userrequestedlocalauditdirectory:Run the mssql-conf script as root with the set command for telemetry.userrequestedlocalauditdirectory:

    sudo /opt/mssql/bin/mssql-conf set telemetry.userrequestedlocalauditdirectory /tmp/audit
    
  4. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    

有关详细信息,请参阅在 Linux 上的 SQL Server 的客户反馈For more information, see Customer Feedback for SQL Server on Linux.

更改 SQL Server 区域设置Change the SQL Server locale

Language.lcid将更改的 SQL Server 区域设置设置为任何受支持的语言标识符 (LCID)。The language.lcid setting changes the SQL Server locale to any supported language identifier (LCID).

  1. 下面的示例更改为法语的区域设置 (1036):The following example changes the locale to French (1036):

    sudo /opt/mssql/bin/mssql-conf set language.lcid 1036
    
  2. 重新启动 SQL Server 服务以应用所做的更改:Restart the SQL Server service to apply the changes:

    sudo systemctl restart mssql-server
    

设置内存限制Set the memory limit

Memory.memorylimitmb将控件设置为 SQL Server 的物理内存量 (以 mb 为单位) 可用。The memory.memorylimitmb setting controls the amount physical memory (in MB) available to SQL Server. 默认值为 80%的物理内存。The default is 80% of the physical memory.

  1. Mssql conf 脚本作为根与运行设置命令memory.memorylimitmbRun the mssql-conf script as root with the set command for memory.memorylimitmb. 下面的示例更改为 SQL Server 到 3.25 GB (3328 MB) 的可用内存。The following example changes the memory available to SQL Server to 3.25 GB (3328 MB).

    sudo /opt/mssql/bin/mssql-conf set memory.memorylimitmb 3328
    
  2. 重新启动 SQL Server 服务以应用所做的更改:Restart the SQL Server service to apply the changes:

    sudo systemctl restart mssql-server
    

更改 TCP 端口Change the TCP port

Network.tcpport设置 SQL Server 侦听的连接的 TCP 端口的更改。The network.tcpport setting changes the TCP port where SQL Server listens for connections. 默认情况下,此端口设置为 1433。By default, this port is set to 1433. 若要更改端口,请运行以下命令:To change the port, run the following commands:

  1. 使用“network.tcpport”的“set”命令以根用户身份运行 mssql-conf 脚本:Run the mssql-conf script as root with the "set" command for "network.tcpport":

    sudo /opt/mssql/bin/mssql-conf set network.tcpport <new_tcp_port>
    
  2. 重新启动 SQL Server 服务:Restart the SQL Server service:

    sudo systemctl restart mssql-server
    
  3. 现在连接到 SQL Server,你必须指定自定义端口逗号 (,) 后的主机名或 IP 地址。When connecting to SQL Server now, you must specify the custom port with a comma (,) after the hostname or IP address. 例如,要使用 SQLCMD 进行连接,则需使用以下命令:For example, to connect with SQLCMD, you would use the following command:

    sqlcmd -S localhost,<new_tcp_port> -U test -P test
    

指定 TLS 设置Specify TLS settings

以下选项在 Linux 上运行的 SQL Server 实例配置 TLS。The following options configure TLS for an instance of SQL Server running on Linux.

选项Option DescriptionDescription
network.forceencryptionnetwork.forceencryption 如果为 1,然后 SQL ServerSQL Server强制所有连接进行加密。If 1, then SQL ServerSQL Server forces all connections to be encrypted. 默认情况下,此选项为 0。By default, this option is 0.
network.tlscertnetwork.tlscert 证书的绝对路径文件 SQL ServerSQL Server用于 TLS。The absolute path to the certificate file that SQL ServerSQL Server uses for TLS. 示例:/etc/ssl/certs/mssql.pem证书文件必须是可由 mssql 帐户访问。Example: /etc/ssl/certs/mssql.pem The certificate file must be accessible by the mssql account. Microsoft 建议限制访问文件使用chown mssql:mssql <file>; chmod 400 <file>Microsoft recommends restricting access to the file using chown mssql:mssql <file>; chmod 400 <file>.
network.tlskeynetwork.tlskey 私钥的绝对路径文件 SQL ServerSQL Server用于 TLS。The absolute path to the private key file that SQL ServerSQL Server uses for TLS. 示例:/etc/ssl/private/mssql.key证书文件必须是可由 mssql 帐户访问。Example: /etc/ssl/private/mssql.key The certificate file must be accessible by the mssql account. Microsoft 建议限制访问文件使用chown mssql:mssql <file>; chmod 400 <file>Microsoft recommends restricting access to the file using chown mssql:mssql <file>; chmod 400 <file>.
network.tlsprotocolsnetwork.tlsprotocols 哪些 TLS 协议都允许 SQL Server 的逗号分隔的列表。A comma-separated list of which TLS protocols are allowed by SQL Server. SQL ServerSQL Server 始终尝试协商允许的最高协议。 always attempts to negotiate the strongest allowed protocol. 如果客户端不支持任何允许的协议, SQL ServerSQL Server拒绝连接尝试。If a client does not support any allowed protocol, SQL ServerSQL Server rejects the connection attempt. 为了实现兼容,默认情况下,(1.2、 1.1、 1.0) 允许所有支持的协议。For compatibility, all supported protocols are allowed by default (1.2, 1.1, 1.0). 如果你的客户端支持 TLS 1.2,Microsoft 建议允许仅 TLS 1.2。If your clients support TLS 1.2, Microsoft recommends allowing only TLS 1.2.
network.tlsciphersnetwork.tlsciphers 指定允许哪些密码 SQL ServerSQL Servertls。Specifies which ciphers are allowed by SQL ServerSQL Server for TLS. 此字符串的格式必须设置每个OpenSSL 的密码的列表格式This string must be formatted per OpenSSL's cipher list format. 一般情况下,你应该不需要更改此选项。In general, you should not need to change this option.
默认情况下,允许以下密码:By default, the following ciphers are allowed:
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
network.kerberoskeytabfilenetwork.kerberoskeytabfile Kerberos keytab 文件路径Path to the Kerberos keytab file

使用 TLS 设置的示例,请参阅Encrypting connections to Linux 上的 SQL Server 连接For an example of using the TLS settings, see Encrypting Connections to SQL Server on Linux.

启用/禁用跟踪标志Enable/Disable traceflags

跟踪标志选项启用或禁用跟踪标志为 SQL Server 服务启动。This traceflag option enables or disables traceflags for the startup of the SQL Server service. 若要启用/禁用跟踪标志,请使用以下命令:To enable/disable a traceflag use the following commands:

  1. 启用跟踪标志,使用以下命令。Enable a traceflag using the following command. 例如,对于跟踪标志 1234:For example, for Traceflag 1234:

    sudo /opt/mssql/bin/mssql-conf traceflag 1234 on
    
  2. 可以通过单独指定跟踪标志来启用多个跟踪标志:You can enable multiple traceflags by specifying them separately:

    sudo /opt/mssql/bin/mssql-conf traceflag 2345 3456 on
    
  3. 在类似的方式,您可以通过指定它们并添加禁用一个或多个启用的跟踪标志关闭参数:In a similar way, you can disable one or more enabled traceflags by specifying them and adding the off parameter:

    sudo /opt/mssql/bin/mssql-conf traceflag 1234 2345 3456 off
    
  4. 重新启动 SQL Server 服务以应用所做的更改:Restart the SQL Server service to apply the changes:

    sudo systemctl restart mssql-server
    

删除该设置Remove a setting

使用的任何设置进行以取消设置mssql-conf set,调用mssql confunset选项和设置的名称。To unset any setting made with mssql-conf set, call mssql-conf with the unset option and the name of the setting. 这将清除该设置,有效地将其返回到其默认值。This clears the setting, effectively returning it to its default value.

  1. 下面的示例清除network.tcpport选项。The following example clears the network.tcpport option.

    sudo /opt/mssql/bin/mssql-conf unset network.tcpport
    
  2. 重新启动 SQL Server 服务。Restart the SQL Server service.

    sudo systemctl restart mssql-server
    

查看当前设置View current settings

若要查看任何配置设置,请运行以下命令以输出的内容mssql.conf文件:To view any configured settings, run the following command to output the contents of the mssql.conf file:

sudo cat /var/opt/mssql/mssql.conf

请注意,未在此文件中显示的所有设置均使用其默认值。Note that any settings not shown in this file are using their default values. 下一节提供一个示例mssql.conf文件。The next section provides a sample mssql.conf file.

mssql.conf formatmssql.conf format

以下/var/opt/mssql/mssql.conf文件提供了为每个设置的一个示例。The following /var/opt/mssql/mssql.conf file provides an example for each setting. 可以使用此格式可以手动更改到mssql.conf文件根据需要。You can use this format to manually make changes to the mssql.conf file as needed. 如果你手动更改此文件,必须重新启动 SQL Server,才能将应用所做的更改。If you do manually change the file, you must restart SQL Server before the changes are applied. 若要使用mssql.conf文件使用 Docker,你必须具有 Docker保存数据To use the mssql.conf file with Docker, you must have Docker persist your data. 第一次添加整个mssql.conf到你的主机目录文件,然后运行容器。First add a complete mssql.conf file to your host directory and then run the container. 没有在此示例客户反馈There is an example of this in Customer Feedback.

[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

后续步骤Next steps

若要改为使用环境变量使这些配置更改的某些项目,请参阅与环境变量配置 SQL Server 设置To instead use environment variables to make some of these configuration changes, see Configure SQL Server settings with environment variables.

其他管理工具和方案,请参阅管理在 Linux 上的 SQL ServerFor other management tools and scenarios, see Manage SQL Server on Linux.