在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
配置订阅服务器
在另一个SQL Server实例,即订阅服务器上,创建用于接收这些项目的数据库。然后,配置订阅服务器以接收发布:
USE [Sales]; GO EXEC sp_addsubscription @publication = 'MyPublication', @subscriber = 'subscriber_name', @destination_db = 'Sales', @subscription_type = 'push'; GO
完成上述步骤后,SQL Server的复制功能已在Ubuntu上配置完成。
请注意,以上步骤是基于SQL Server 2022和Ubuntu 20.04的配置示例,具体步骤可能因SQL Server版本和Ubuntu发行版的不同而有所差异。建议参考官方文档以获取最准确的配置指南。