ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

SQL Server High Availability Groups in Linux CentOS 7

2022-06-16 17:04:55  阅读:182  来源: 互联网

标签:opt TBSLinuxNode2 CentOS TBSLinuxNode1 Server Cert cer SQL mssql


Configure pipeline

  • Installing SQL Server High Availability Package
  • Installing and Enabling SQL Server Agent if its not installed and enabled already
  • Enable SQL server High Availability on each Node
  • Creating AG Group EndPoint and Certificates
  • Copy Certificates of each node into all other Nodes
  • Change ownership and group association to mysql(User)
  • Restore each Certificate with authenticated user ( create user if you don't have already one)
  • Grant AG Group using SSMS
  • Create SQL Server Login and Permission for Pacemaker
  • Create Availability Group resource in pacemaker
  • Create IP for Listener in PackeMaker
  • Create Listener using same IP
  • Test Failover

# Install SQL Server High Availability Package

sudo yum install mssql-server-ha

# Enable AlwaysOn Avaiability Groups and resetart SQL Server on both nodes

sudo /opt/mssql/bin/mssql-conf set hadr.hadrenabled  1
sudo systemctl restart mssql-server

# Open SSMS and create Certificate for each node

# Node Name : TBSLinuxNode1

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Pass@123';

GO

CREATE CERTIFICATE TBSLinuxNode1_Cert
WITH SUBJECT = 'TBSLinuxNode1 AG Certificate';

GO

BACKUP CERTIFICATE TBSLinuxNode1_Cert
TO FILE = '/var/opt/mssql/data/TBSLinuxNode1_Cert.cer';

GO

CREATE ENDPOINT TBSSQLAG
STATE = STARTED
AS TCP (
    LISTENER_PORT = 5022,
    LISTENER_IP = ALL)
FOR DATABASE_MIRRORING (
    AUTHENTICATION = CERTIFICATE TBSLinuxNode1_Cert,
    ROLE = ALL);

GO

#Now samething on Node2 (TBSLinuxNode2)


CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Pass@123';

GO

CREATE CERTIFICATE TBSLinuxNode2_Cert
WITH SUBJECT = 'TBSLinuxNode2 AG Certificate';

GO

BACKUP CERTIFICATE TBSLinuxNode2_Cert
TO FILE = '/var/opt/mssql/data/TBSLinuxNode2_Cert.cer';

GO

CREATE ENDPOINT TBSSQLAG
STATE = STARTED
AS TCP (
    LISTENER_PORT = 5022,
    LISTENER_IP = ALL)
FOR DATABASE_MIRRORING (
    AUTHENTICATION = CERTIFICATE TBSLinuxNode2_Cert,
    ROLE = ALL);

GO

# Copy Certificate of one node to other using SCP 
# on Node1

scp -r root@TBSLinuxNode1:/var/opt/mssql/data/TBSLinuxNode1_Cert.cer 

root@TBSLinuxNode2:/var/opt/mssql/data/TBSLinuxNode1_Cert.cer

# On Node 2

scp -r root@TBSLinuxNode2:/var/opt/mssql/data/TBSLinuxNode2_Cert.cer 

root@TBSLinuxNode1:/var/opt/mssql/data/TBSLinuxNode2_Cert.cer

# Change Ownership of certificate to mssql on each node(In my case I have only two nodes)

sudo chown mssql:mssql TBSLinuxNode2_Cert.cer
sudo chown mssql:mssql TBSLinuxNode1_Cert.cer

# Create instance Level SQL User (TBSAGUser in my case on each node) using SSMS
Open SSMS and create User
# Restore certificate of Other Nodes into the present node using SSMS below: Login to TBSLinuxNode1

CREATE CERTIFICATE TBSLinuxNode2_Cert
AUTHORIZATION TBSAGUser
FROM FILE = '/var/opt/mssql/data/TBSLinuxNode2_Cert.cer';

# Grant permission to connec to the endpoint of TBSLinuxNode1

GRANT CONNECT ON ENDPOINT::TBSSQLAG TO TBSAGUser;

# Let's do the same thing by connecting to TBSLinuxNode2 and restore TBSLinuxNode1.cert

CREATE CERTIFICATE TBSLinuxNode1_Cert
AUTHORIZATION TBSAGUser
FROM FILE = '/var/opt/mssql/data/TBSLinuxNode1_Cert.cer';

# Grant permission to connec to the endpoint of TBSLinuxNode2

GRANT CONNECT ON ENDPOINT::TBSSQLAG TO TBSAGUser;

# Create Availability Group using SSMS with Cluster type External

# Create a new login or use the same login to give Pacemaker permission and provide view server permission, I will give 

#sysadmin to this user just for this demo

# On all Nodes Edit vi /var/opt/mssql/secrets/passwd using emacs and update with user and password that you created for 

Pacemaker and save it

TBSAGUser
Pass@123
# Hold down the CTRL key and then press X, then C, to exit and save the file
# setup right permission

sudo chmod 400 /var/opt/mssql/secrets/passwd

# Create the AG resource in the Pacemaker cluster

sudo pcs resource create TBSLinuxRG ocf:mssql:ag ag_name=TBSLinuxAG meta failure-timeout=30s --master meta notify=true

# Create IP resource for Listener 
sudo pcs resource create LinuxSQLProdList ocf:heartbeat:IPaddr2 ip=192.168.1.104 cidr_netmask=24

# Create an ordering constraint to ensure that the AG resource is up and running before the IP address. While the colocation 

#constraint implies an ordering constraint, this enforces it

sudo pcs constraint order promote TBSLinuxRG-master then start LinuxSQLProdList

# Let's Test Failover

标签:opt,TBSLinuxNode2,CentOS,TBSLinuxNode1,Server,Cert,cer,SQL,mssql
来源: https://www.cnblogs.com/aboa/p/16382592.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有