点击查看代码
丐版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

快速部署sqlserver AlwaysOn集群的更多相关文章

  1. 用Docker swarm快速部署Nebula Graph集群

    用Docker swarm快速部署Nebula Graph集群 一.前言 本文介绍如何使用 Docker Swarm 来部署 Nebula Graph 集群. 二.nebula集群搭建 2.1 环境准 ...

  2. docker swarm快速部署redis分布式集群

    环境准备 四台虚拟机 192.168.2.38(管理节点) 192.168.2.81(工作节点) 192.168.2.100(工作节点) 192.168.2.102(工作节点) 时间同步 每台机器都执 ...

  3. Harbor快速部署到Kubernetes集群及登录问题解决

    Harbor(https://goharbor.io)是一个功能强大的容器镜像管理和服务系统,用于提供专有容器镜像服务.随着云原生架构的广泛使用,原来由VMWare开发的Harbor也加入了云原生基金 ...

  4. 快速部署一个Kubernetes集群

    官方提供的三种部署方式 minikube Minikube是一个工具,可以在本地快速运行一个单点的Kubernetes,仅用于尝试Kubernetes或日常开发的用户使用. 部署地址:https:// ...

  5. 第3章:快速部署一个Kubernetes集群

    kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具. 这个工具能通过两条指令完成一个kubernetes集群的部署: # 创建一个 Master 节点$ kubeadm in ...

  6. 基于 Sealos 的镜像构建能力,快速部署自定义 k8s 集群

    Sealos 是一个快速构建高可用 k8s 集群的命令行工具,该工具部署时会在第一个 k8s master 节点部署 registry 服务(sealos.hub),该域名通过 hosts 解析到第一 ...

  7. 使用docker快速部署一个consul集群

    作为一个开发者,有时候需要一个集群环境,之前的做法要么就是使用多个虚拟机,要么就是采用不同的端口来模拟,但是虚拟机比较占内存,而且启动慢,采用不同的端口来模拟,管理起来比较麻烦一些,程序隔离性差一些. ...

  8. Docker简单部署Ceph测试集群

    通过docker可以快速部署小规模Ceph集群的流程,可用于开发测试. 以下的安装流程是通过linux shell来执行的;假设你只有一台机器,装了linux(如Ubuntu)系统和docker环境, ...

  9. 使用Docker构建持续集成与自动部署的Docker集群

    为什么使用Docker " 从我个人使用的角度讲的话  部署来的更方便 只要构建过一次环境 推送到镜像仓库 迁移起来也是分分钟的事情 虚拟化让集群的管理和控制部署都更方便 hub.docke ...

  10. [转载] 把Nutch爬虫部署到Hadoop集群上

    http://f.dataguru.cn/thread-240156-1-1.html 软件版本:Nutch 1.7, Hadoop 1.2.1, CentOS 6.5, JDK 1.7 前面的3篇文 ...

随机推荐

  1. 暑假Java自学进度总结05

    一.今日所学: 1.if的第一个表达式: if(关系表达式){ 语句: } 执行流程: 1>首先执行关系表达式的值 2>如果关系表达式的值为true则执行语句,否则不执行 3>继续执 ...

  2. Jenkins部署架构概述

    1.Jenkins是什么 Jenkins是一个开源的.提供友好操作界面的持续集成(CI)工具,起源于Hudson,主要用于持续.自动的构建/测试软件项目.监控外部任务的运行. Jenkins用Java ...

  3. Sy.ExpressionBuilder 动态查询新体验

    省流模式,看下对比 //常规查询 var query = users .WhereIf(m => m.UserName.Contains(input.UserName), !string.IsN ...

  4. Camera | 8.让rk3568支持前后置摄像头

    一.目标 本文主要目标是,支持前置摄像头0v5648.后置摄像头ov13850,以及移植过程遇到的一些小问题的解决. 1. 摄像头连接图 参考上图,摄像头详细信息如下: 2个摄像头均连接在I2C通道4 ...

  5. 前后端分离使用mp遇到问题

    <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-s ...

  6. 【测试平台开发】——04Flask后端api开发实战(一)

    一.测试平台开发模式 要开发一套平台有两种开发模式,一个[大而全],一个[小而简]. 说道[大而全]想到目前大型项目都使用的语言[JAVA],[小而简]想到的是[Python]语言. 重武器(大而全) ...

  7. .NET 摄像头采集

    本文主要介绍摄像头(相机)如何采集数据,用于类似摄像头本地显示软件,以及流媒体数据传输场景如传屏.视讯会议等. 摄像头采集有多种方案,如AForge.NET.WPFMediaKit.OpenCvSha ...

  8. 【漏洞分析】OSN 代币攻击事件:一笔资金伪造多个分红大户

    背景 OSN 是一种 fee on transfer 代币,会根据用户分红账户的余额对用户发放分红.攻击者利用漏洞增发分红账户的余额,随后触发分红机制完成获利. OSN:https://bscscan ...

  9. 『面试题』WEB前端面试专题-Promise相关

    题目一 const promise = new Promise((resolve, reject) => { console.log(1); resolve(); console.log(2); ...

  10. 中国信通院高质量数字化转型产品及服务全景图发布,合合信息多项AI产品入选

    随着5G.人工智能.大数据等新一代技术的发展,企业在商业竞争中正面临更多不确定性.中国信通院高度关注企业数字化转型中遇到的痛点,发起"铸基计划-高质量数字化转型行动",链接企业数字 ...