在 Linux 上安装 SQL Server 代理Install SQL Server Agent on Linux

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) - Linux适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) - Linux

本文介绍如何在 Linux 上启用或安装 SQL Server 代理。This article describes how to enable or install the SQL Server Agent on Linux.

SQL Server 代理运行计划的 SQL Server 作业。The SQL Server Agent runs scheduled SQL Server jobs. 从 SQL Server 2017 CU4 开始,SQL Server 代理包含在 mssql-server 包中,默认情况下处于禁用状态。Starting with SQL Server 2017 CU4, SQL Server Agent is included with the mssql-server package and is disabled by default. 若要了解此版本 SQL Server 代理支持的功能和版本信息,请参阅发行说明For information on the features supported for this release of the SQL Server Agent along with version information, see the Release Notes.

InstructionsInstructions

必须先按照以下步骤在 Linux 上启用或安装 SQL Server 代理后,才能使用该代理。Before using the SQL Server Agent on Linux, use the following steps to enable or install it.

  1. /etc/hosts 文件中添加主机名(包含和不包含域)。Add your hostname (with and without domain) in the /etc/hosts files. 以下行展示了这些条目的格式:The following lines show an example of the format for these entries:

    "IP Address" "hostname"
    "IP Address" "hostname.domain.com"
    
  2. 根据你的 SQL Server 版本,按照以下某个部分中的说明进行操作:Follow the instructions in one of the following sections based on your version of SQL Server:

    版本Versions InstructionsInstructions
    SQL Server 2017 CU4 及更高版本SQL Server 2017 CU4 and higher
    SQL Server 2019SQL Server 2019
    启用 SQL Server 代理Enable the SQL Server Agent
    SQL Server 2017 CU3 及更低版本SQL Server 2017 CU3 and lower 安装 SQL Server 代理Install the SQL Server Agent

启用 SQL Server 代理Enable the SQL Server Agent

对于 SQL Server 2019 和 SQL Server 2017 CU4 及更高版本,只需启用 SQL Server 代理。For SQL Server 2019 and SQL Server 2017 CU4 and higher, you only need to enable the SQL Server Agent. 无需安装单独的包。You do not need to install a separate package.

若要启用 SQL Server 代理,请执行以下步骤。To enable SQL Server Agent, follow the steps below.

sudo /opt/mssql/bin/mssql-conf set sqlagent.enabled true 
sudo systemctl restart mssql-server

备注

如果是在安装了代理的情况下从 2017 CU3 或更低版本进行升级,将自动启用 SQL Server 代理并卸载以前的代理包。If you are upgrading from 2017 CU3 or below with Agent installed, SQL Server Agent will be enabled automatically and previous Agent packages will be uninstalled.

安装 SQL Server 代理Install the SQL Server Agent

对于 SQL Server 2017 CU3 及更低版本,必须安装 SQL Server 代理包。For SQL Server 2017 CU3 and earlier, you must install the SQL Server Agent package.

备注

下面的安装说明适用于 SQL Server 版本 2017 CU3 及更低版本。The install instructions below apply to SQL Server Versions 2017 CU3 and below. 在安装 SQL Server 代理前,首先请安装 SQL ServerBefore installing SQL Server Agent, first install SQL Server. 这将配置安装 mssql-server-agent 包时要用到的密钥和存储库****。This configures the keys and repositories that you use when you install the mssql-server-agent package.

为以下平台安装 SQL Server 代理:Install the SQL Server Agent for your platform:

在 RHEL 上安装Install on RHEL

通过下列步骤在 Red Hat Enterprise Linux 上安装 mssql-server-agent****。Use the following steps to install the mssql-server-agent on Red Hat Enterprise Linux.

sudo yum install mssql-server-agent
sudo systemctl restart mssql-server

如果已安装 mssql-server-agent,则可使用下列命令将其更新至最新版本****:If you already have mssql-server-agent installed, you can update to the latest version with the following commands:

sudo yum check-update
sudo yum update mssql-server-agent
sudo systemctl restart mssql-server

如果需要脱机安装,请在发行说明中找到 SQL Server 代理包下载。If you need an offline installation, locate the SQL Server Agent package download in the Release notes. 然后执行与文章安装 SQL Server 所述相同的脱机安装步骤。Then use the same offline installation steps described in the article Install SQL Server.

在 Ubuntu 上安装Install on Ubuntu

通过下列步骤在 Ubuntu 上安装 mssql-server-agent****。Use the following steps to install the mssql-server-agent on Ubuntu.

sudo apt-get update 
sudo apt-get install mssql-server-agent
sudo systemctl restart mssql-server

如果已安装 mssql-server-agent,则可使用下列命令将其更新至最新版本****:If you already have mssql-server-agent installed, you can update to the latest version with the following commands:

sudo apt-get update 
sudo apt-get install mssql-server-agent
sudo systemctl restart mssql-server

如果需要脱机安装,请在发行说明中找到 SQL Server 代理包下载。If you need an offline installation, locate the SQL Server Agent package download in the Release notes. 然后执行与文章安装 SQL Server 所述相同的脱机安装步骤。Then use the same offline installation steps described in the article Install SQL Server.

在 SLES 上安装Install on SLES

通过下列步骤在 SUSE Linux Enterprise Server 上安装 mssql-server-agent****。Use the following steps to install the mssql-server-agent on SUSE Linux Enterprise Server.

安装 mssql-server-agent****Install mssql-server-agent

sudo zypper install mssql-server-agent
sudo systemctl restart mssql-server

如果已安装 mssql-server-agent,则可使用下列命令将其更新至最新版本****:If you already have mssql-server-agent installed, you can update to the latest version with the following commands:

sudo zypper refresh
sudo zypper update mssql-server-agent
sudo systemctl restart mssql-server

如果需要脱机安装,请在发行说明中找到 SQL Server 代理包下载。If you need an offline installation, locate the SQL Server Agent package download in the Release notes. 然后执行与文章安装 SQL Server 所述相同的脱机安装步骤。Then use the same offline installation steps described in the article Install SQL Server.

后续步骤Next steps

有关如何使用 SQL Server 代理创建、计划和运行作业的详细信息,请参阅在 Linux 上运行 SQL Server 代理作业For more information on how to use SQL Server Agent to create, schedule, and run jobs, see Run a SQL Server Agent job on Linux.