在Ubuntu上配置SQL Server的复制功能涉及多个步骤,包括安装必要的软件包、配置SQL Server代理、创建数据库和表、以及设置复制。以下是详细的配置步骤:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list)" sudo apt-get update sudo apt-get install -y mssql-server 运行mssql-conf setup按照提示设置SA密码并选择版本。
配置SQL Server代理:
sudo /opt/mssql/bin/mssql-conf set sqlagent.enabled true sudo systemctl restart mssql-server 在发布服务器上,创建示例数据库和表,将其作为发布项目:
CREATE DATABASE Sales; GO USE [Sales]; GO CREATE TABLE Customer ( [CustomerID] INT NOT NULL, [SalesAmount] DECIMAL NOT NULL ); GO INSERT INTO Customer (CustomerID, SalesAmount) VALUES (1, 100), (2, 200), (3, 300); GO 在此示例中,发布服务器也是分发服务器。在发布服务器上运行以下命令,也为分发配置实例:
DECLARE @distributor AS SYSNAME; DECLARE @distributorlogin AS SYSNAME; DECLARE @distributorpassword AS SYSNAME; -- Specify the distributor name. Use 'hostname' command on in terminal to find the hostname SET @distributor 'distributor instance name'; -- in this example, it will be the name of the publisher -- Specify the distribution database. USE master; EXEC sp_adddistributor @distributor @distributor -- this should be the hostname -- Log into distributor and create Distribution Database. In this example, our publisher and distributor is on the same host EXEC sp_adddistributiondb @database 'distribution', @log_file_size 2, @deletebatchsize_xact 5000, @deletebatchsize_cmd 2000, @security_mode 0, @login @distributorlogin, @password @distributorpassword; GO 在发布服务器上运行以下T-SQL命令:
DECLARE @publisher AS SYSNAME; DECLARE @distributorlogin AS SYSNAME; DECLARE @distributorpassword AS SYSNAME; SET @publisher 'instance name'; -- Specify the distributor login. SET @distributorlogin 'distributor login'; -- Specify the distributor password. SET @distributorpassword 'distributor password'; -- Log into publisher and create publication. USE [distribution]; GO EXEC sp_addpublication @publication = 'MyPublication', @description = 'My publication description', @update_mode = 'concurrent', @status = 'active'; GO 请注意,具体的步骤可能会因SQL Server版本和配置的不同而有所差异。建议参考Microsoft官方文档以获取最新和详细的指导。