丐版sqlserver AlwaysOn集群

这篇具有很好参考价值的文章主要介绍了丐版sqlserver AlwaysOn集群。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

点击查看代码
丐版sqlserver集群

之前试过docker的,k8s的,然后发现,还是最朴素的是最简单的,希望有大佬能够汉化,他妈的,那些英文看得人要发癫啊。



前置准备,参照丐版pxc集群:
https://www.cnblogs.com/zwnfdswww/p/18112077
如果不关防火墙:
打开对应的端口即可:
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent

sudo firewall-cmd --reload


sudo hostnamectl set-hostname m191
sudo hostnamectl set-hostname m192
sudo hostnamectl set-hostname m193

bash
vim /etc/hosts

10.1.161.29 m191
10.1.161.31 m192
10.1.161.32 m193


sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo
sudo yum install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup

设置密码:
Citygis@1613

systemctl status mssql-server

yum install mssql-server-agent

/opt/mssql/bin/mssql-conf set sqlagent.enabled true
systemctl restart mssql-server.service



sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel

sudo yum install -y mssql-tools unixODBC-devel

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

source ~/.bashrc

sqlcmd -S 10.1.161.32 -U SA -P 'Citygis@1613'

CREATE DATABASE TestDB

SELECT Name from sys.Databases

GO
USE TestDB
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)

INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);

GO
SELECT * FROM Inventory WHERE quantity > 152;

GO
QUIT
需要几台服务器,重复安装即可
测试:
navicat连一下
10.1.161.29,1433
SA Citygis@1613

如果没有驱动,去navicat目录下安装sqlncli_x64即可
sql(all)
将 SA 帐户禁用:
ALTER LOGIN SA DISABLE;

CREATE LOGIN Citygis@1613 WITH PASSWORD = 'Citygis@1613';
ALTER SERVER ROLE sysadmin ADD MEMBER Citygis@1613;

重要:新用户登录
ALTER LOGIN SA DISABLE;



 
Bash(all):

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

sudo systemctl restart mssql-server

Bash(all)
yum install -y mssql-server-ha 
yum info mssql-server-ha

 
Sql(all):

ALTER EVENT SESSION  AlwaysOn_health ON SERVER WITH (STARTUP_STATE=ON);

GO

Sql(all):

CREATE LOGIN dbm_login WITH PASSWORD = '1111.aaa';

CREATE USER dbm_user FOR LOGIN dbm_login;

第一个是登录用户,第二个是执行用户


Sql(主):

CREATE MASTER KEY ENCRYPTION BY PASSWORD = '1111.aaa';

CREATE CERTIFICATE dbm_certificate WITH SUBJECT = 'dbm';

BACKUP CERTIFICATE dbm_certificate

   TO FILE = '/var/opt/mssql/data/dbm_certificate.cer'

   WITH PRIVATE KEY (

           FILE = '/var/opt/mssql/data/dbm_certificate.pvk',

           ENCRYPTION BY PASSWORD = '1111.aaa'

       );

ls /var/opt/mssql/data
看下文件有没有生成
Bash(主):

cd /var/opt/mssql/data/

scp dbm_certificate.* 10.1.161.31:/var/opt/mssql/data/

scp dbm_certificate.* 10.1.161.32:/var/opt/mssql/data/
       
Bash(从);

cd /var/opt/mssql/data/

chown mssql.mssql dbm_certificate.*


Sql(从):

CREATE MASTER KEY ENCRYPTION BY PASSWORD = '1111.aaa';

CREATE CERTIFICATE dbm_certificate

    AUTHORIZATION dbm_user

    FROM FILE = '/var/opt/mssql/data/dbm_certificate.cer'

    WITH PRIVATE KEY (

    FILE = '/var/opt/mssql/data/dbm_certificate.pvk',

    DECRYPTION BY PASSWORD = '1111.aaa'

            );
            
            
Sql(all);

CREATE ENDPOINT [Hadr_endpoint]

    AS TCP (LISTENER_PORT = 5022)

    FOR DATABASE_MIRRORING (

        ROLE = ALL,

        AUTHENTICATION = CERTIFICATE dbm_certificate,

        ENCRYPTION = REQUIRED ALGORITHM AES

        );

ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED;

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [dbm_login];


sudo firewall-cmd --zone=public --add-port=5022/tcp --permanent

sudo firewall-cmd --reload


Sql(all);

select @@SERVERNAME;



Sql(主):

CREATE AVAILABILITY GROUP [ag1]
WITH (DB_FAILOVER = ON, CLUSTER_TYPE = EXTERNAL)
FOR REPLICA ON
    N'm191'
    WITH (
        ENDPOINT_URL = N'tcp://m191:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = EXTERNAL,
        SEEDING_MODE = AUTOMATIC,
        SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL)
    ),
    N'm192'
    WITH (
        ENDPOINT_URL = N'tcp://m192:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = EXTERNAL,
        SEEDING_MODE = AUTOMATIC,
        SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL)
    ),
    N'm193'
    WITH (
        ENDPOINT_URL = N'tcp://m193:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = EXTERNAL,
        SEEDING_MODE = AUTOMATIC,
        SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL)
    );

ALTER AVAILABILITY GROUP [ag1] GRANT CREATE ANY DATABASE;




Sql(从):

 

ALTER AVAILABILITY GROUP [ag1] JOIN WITH (CLUSTER_TYPE = EXTERNAL);        

ALTER AVAILABILITY GROUP [ag1] GRANT CREATE ANY DATABASE


(如果报错,可能是hosts文件里面主机名对应ip错了)

测试一下:

Sql(主):

CREATE DATABASE [db1];

ALTER DATABASE [db1] SET RECOVERY FULL;

BACKUP DATABASE [db1]

   TO DISK = N'/var/opt/mssql/data/db1.bak';

ALTER AVAILABILITY GROUP [AG1] ADD DATABASE [db1];


从节点查一下。

集群完成。

DROP AVAILABILITY GROUP group_name

可选:

Bash(all)
sudo yum install subscription-manager

用户名和密码去redhat官网申请
vi /etc/rhsm/rhsm.conf

Set to 1 to disable certificate validation:
insecure = 1

sudo subscription-manager register





sudo subscription-manager list --available

sudo subscription-manager attach --pool=<PoolID>

其中,“PoolId”是上一步中高可用性订阅的池 ID 。
subscription-manager repos --list

选一个高可用相关的软件仓库
sudo subscription-manager repos --enable=rhel-ha-for-rhel-7-server-rpms
(备用:sudo subscription-manager repos --enable=rhel-atomic-7-cdk-3.3-rpms)
如果系统自带了有,可以不执行上面的命令


Bash(all):

yum install pacemaker pcs resource-agents corosync fence-agents-all -y

Bash(all):

passwd hacluster  (这里密码一定要设置成一样的,我这设置的是123456.com)

Bash(all):

sudo systemctl enable pcsd

sudo systemctl start pcsd

sudo systemctl enable pacemaker


firewall-cmd --add-service=high-availability --zone=public --permanent

firewall-cmd --zone=public --add-port=2224/tcp --permanent

firewall-cmd --zone=public --add-port=3121/tcp –permanent

firewall-cmd --zone=public --add-port=5405/udp --permanent 

firewall-cmd --reload



Bash(all):

sudo pcs cluster destroy

sudo systemctl enable pacemaker



Bash(主):

sudo pcs cluster auth m191 m192 m193 -u hacluster -p 123456.com

sudo pcs cluster setup --name AG1 m191 m192 m193 


chown -R hacluster.haclient /var/log/cluster

pcs cluster start --all
pcs cluster enable –all

pcs cluster status

ps aux | grep pacemaker


corosync-cfgtool -s

corosync-cmapctl | grep members

pcs status corosync


crm_verify -L -V


(all):
pcs property set stonith-enabled=false


pcs property set no-quorum-policy=ignore

Bash(all):

sudo pcs property set stonith-enabled=false

Bash(all):

yum install mssql-server-ha –y

sudo systemctl restart mssql-server

Sql(all):

USE [master]

GO

CREATE LOGIN [pacemakerLogin] with PASSWORD= N'1111.aaa';

 

ALTER SERVER ROLE [sysadmin] ADD MEMBER [pacemakerLogin]


Bash(all):

sudo echo 'pacemakerLogin' >> ~/pacemaker-passwd

sudo echo '1111.aaa' >> ~/pacemaker-passwd

sudo mv ~/pacemaker-passwd /var/opt/mssql/secrets/passwd

sudo chown root:root /var/opt/mssql/secrets/passwd

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



Bash(主)

重要,ip记得改

sudo pcs resource create ag_cluster ocf:mssql:ag ag_name=AG1 meta failure-timeout=60s master notify=true

 

sudo pcs resource create virtualip ocf:heartbeat:IPaddr2 ip=10.1.161.70

执行完之后查看是否绑定成功
sudo pcs resource show
看下虚拟ip在哪里,去相应的主机
ip  addr show

Bash(主)

sudo pcs constraint colocation add virtualip ag_cluster-master INFINITY with-rsc-role=Master

 

sudo pcs constraint order promote ag_cluster-master then start virtualip

sudo pcs status

测试:
navicat连一下

10.1.161.70,1433
Citygis@1613 Citygis@1613
Sql(VIP):

Sql(VIP):

-- group info

SELECT

    g.name as ag_name,

    rgs.primary_replica,

    rgs.primary_recovery_health_desc as recovery_health,

    rgs.synchronization_health_desc as sync_health

From sys.dm_hadr_availability_group_states as rgs

JOIN sys.availability_groups AS g

                      ON rgs.group_id = g.group_id

 

--replicas info

SELECT

         g.name as ag_name,

         r.replica_server_name,

         rs.is_local,

         rs.role_desc as role,

         rs.operational_state_desc as op_state,

         rs.connected_state_desc as connect_state,

         rs.synchronization_health_desc as sync_state,

         rs.last_connect_error_number,

         rs.last_connect_error_description

From sys.dm_hadr_availability_replica_states AS  rs

JOIN sys.availability_replicas AS r

         ON rs.replica_id = r.replica_id

JOIN sys.availability_groups AS g

         ON g.group_id = r.group_id

 

 

--DB level

SElECT

     g.name as ag_name,

     r.replica_server_name,

     DB_NAME(drs.database_id) as [database_name],

     drs.is_local,

     drs.is_primary_replica,

     synchronization_state_desc as sync_state,

     synchronization_health_desc as sync_health,

     database_state_desc as db_state

FROM sys.dm_hadr_database_replica_states AS drs

     JOIN sys.availability_replicas AS r

     ON r.replica_id = drs.replica_id

     JOIN sys.availability_groups AS g

     ON g.group_id = drs.group_id

ORDER BY g.name, drs.is_primary_replica DESC;

GO


SQL Server Always On的同步原理:

所有的事务会被提交到主副本,辅助副本去读取物理日志来同步,新建的数据库需要加入到ag里面

Pacemaker的监控原理:

会用被动心跳来检查,如果发现节点有问题,会通过三角轮转进行迁移,然后还能对节点进行监控


引用:
[1] https://www.cnblogs.com/guarderming/p/12082936.html

文章来源地址https://www.toymoban.com/news/detail-848909.html

到了这里,关于丐版sqlserver AlwaysOn集群的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • js 点击图片实现查看大图

    点击图片放大缩小(遮罩)

    2024年02月05日
    浏览(53)
  • js实现点击查看全部/收起功能

    在上一篇文章实现用js截取文本后,我的另一个需求也迎刃而解了。需求就是一段长文本需要溢出隐藏,然后点击全部时显示全部文本,点击收起又回到溢出隐藏的状态。实现的效果如下图: 实现的思路时点击全部时使用这条数据的原文本,点击收起时使用截取后的文本。而

    2024年02月10日
    浏览(61)
  • MCU方案选型和进口替代,点击查看~

    MCU(微控制单元)俗称单片机,可被认为是CPU的缩减版本,把CPU的频率与规格进行缩减处理,并将RAM、ROM、时钟、A/D转换、定时/计数器、UART 、DMA等电路单元,甚至包括USB接口、LCD驱动电路都整合在一块芯片之中,形成芯片级的计算机,为各种应用场合提供组合控制。   MC

    2024年02月20日
    浏览(33)
  • React Native 点击图片变大,查看图片

    Index.js: 参考链接: https://www.npmjs.com/package/react-native-image-zoom-viewer https://chat.xutongbao.top/

    2024年02月14日
    浏览(34)
  • Android 点击图片,放大查看,实现缩放拖动等功能

    实现方法:点击图片时,把图片url传到另一个activity中实现放大拖动, 图片点击事件触发: Intent intent = new Intent(); intent.setClass(mContext, PictureActivity.class); intent.putExtra(“url”,R.drawable.ic_logo); mContext.startActivity(intent); 然后创建一个activity的内容如下: public class PictureActivity extend

    2024年02月11日
    浏览(51)
  • WebMagic - 创意前端项目集合(点击链接可在电脑上查看效果)

    欢迎来到 WebMagic 仓库!这里汇集了一系列令人惊叹的前端项目,涵盖了HTML5、CSS3和JS等多项技术。无论你是前端开发者、设计师,还是对创意互动内容感兴趣的人,这个仓库都将为你带来无尽的惊喜。 每个项目都经过精心设计和编码,具有清晰的文档,让你轻松上手。请随意

    2024年02月12日
    浏览(37)
  • SQL Server 2022 AlwaysOn新特性之包含可用性组介绍

    由于技术能力有限,文章仅能进行简要分析和说明,如有不对的地方,请指正,谢谢🙂。 SQL Server的容灾功能一直弱于Oracle和MySQL,无法自动同步元数据(用户、登录名、权限、SQL 代理作业、链接服务器),导致在对镜像库或者AlwaysOn执行切换之前,都要手动同步master、msdb里

    2023年04月27日
    浏览(93)
  • CSS处理文字段落尾行行末缩进,点击查看更多展开效果

    需求:  如图:第三行文末需要展示省略号,并且有查看更多按钮,切换显示隐藏。 常规css处理方法: 控制文字行数: // 多行显示 .text_morerow {     overflow: hidden;     display: -webkit-box;     -webkit-line-clamp: 2; // 控制显示行数     -webkit-box-orient: vertical;     word-break: break-all; 

    2024年02月06日
    浏览(49)
  • uni-app+uView实现点击查看大图片的效果

    参数说明

    2024年02月10日
    浏览(47)
  • vue 图片点击放大查看大图(element-ui与vant)

    未放大效果: 点击放大后的效果: html: js: html: js:

    2024年02月08日
    浏览(52)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包