阅读量:329
在Ubuntu上配置SQL Server的复制功能涉及多个步骤,包括安装必要的软件包、配置SQL Server代理、创建数据库和表、以及设置复制。以下是详细的配置步骤:
安装SQL Server和必要的工具导入公共存储库GPG密钥:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
注册SQL Server Ubuntu存储库:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list)"
安装SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
运行mssql-conf setup按照提示设置SA密码并选择版本。配置SQL Server代理
为了进行日常数据备份等任务,需要开启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;
-- Specify the distributor name. Use 'hostname' command on in terminal to find the hostname
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