温馨提示×

Ubuntu上SQL Server的复制功能如何配置

小樊
83
2025-02-16 02:32:31
栏目: 云计算
亿速云云数据库,读写分离,安全稳定,弹性扩容,低至0.3元/天!! 点击查看>>

在Ubuntu上配置SQL Server的复制功能涉及多个步骤,包括安装必要的软件包、配置SQL Server代理、创建数据库和表、以及设置复制。以下是详细的配置步骤:

安装SQL Server和必要的工具

  1. 导入公共存储库GPG密钥:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
  1. 注册SQL Server Ubuntu存储库:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list)"
  1. 安装SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
  1. 运行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发行版的不同而有所差异。建议参考官方文档以获取最准确的配置指南。

亿速云「云数据库 MySQL」免部署即开即用,比自行安装部署数据库高出1倍以上的性能,双节点冗余防止单节点故障,数据自动定期备份随时恢复。点击查看>>

推荐阅读:如何在Ubuntu上配置SQL Server

0