首页 > 数据库 >丐版sqlserver AlwaysOn集群

丐版sqlserver AlwaysOn集群

时间:2024-04-12 13:00:15浏览次数:28  
标签:AlwaysOn opt dbm -- pcs sudo sqlserver 丐版 mssql

丐版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”是上一步中高可用性订阅的池 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

标签:AlwaysOn,opt,dbm,--,pcs,sudo,sqlserver,丐版,mssql
From: https://www.cnblogs.com/zwnfdswww/p/18125126

相关文章

  • 模拟SQLserver死锁现象(解析)
    SQLServer死锁是指两个或多个事务相互等待对方持有的资源而无法继续执行的情况。当两个或多个事务都持有一些资源并且试图获取其他事务持有的资源时,可能会发生死锁。这种情况下,每个事务都在等待另一个事务释放其所需的资源,导致所有涉及的事务都无法继续执行,形成了死锁。死锁通常......
  • SQLSERVER 2019数据库(可疑) 数据修复案例
    2019数据库,在正常使用过程中,服务器突然断电,重新启动服务器后,数据库变为(可疑)。【数据恢复故障分析】由于数据库在正常读写操作过,服务器突然断电,导致数据库无法把所有缓冲中的数据写入到数据库文件中,所以会使数据内部索引及数据区损坏。【数据恢复过......
  • 模拟SQLserver死锁现象
    SQLServer死锁是指两个或多个事务相互等待对方持有的资源而无法继续执行的情况。当两个或多个事务都持有一些资源并且试图获取其他事务持有的资源时,可能会发生死锁。这种情况下,每个事务都在等待另一个事务释放其所需的资源,导致所有涉及的事务都无法继续执行,形成了死锁。死锁通常......
  • 丐版pxc集群
    同步systemctlstopfirewalld&&systemctldisablefirewalldsystemctlstopNetworkManager&&systemctldisableNetworkManagersetenforce0sed-is/SELINUX=enforcing/SELINUX=disabled//etc/selinux/configswapoff-ased-ri's/.swap./......
  • C# SQLSERVER 自动备份
    publicclassBakDBHelper{///<summary>///创建数据库备份///</summary>publicstringCreateBackup(stringdbname,stringbackname){stringres="";//要备份的位置......
  • sqlserver数据库端口号怎么修改
    sqlserver数据库端口号修改方法:确定当前端口号(select@@serverport;)通过sqlserver配置管理对象(smo)修改通过sqlserver配置管理器修改通过注册表编辑器修改通过命令行修改(scconfigmssqlserver port=1433)SQLServer数据库端口号修改方法1.确定当前端口号<......
  • SqlServer中的MAX函数的两种用法
    原文链接:https://blog.csdn.net/yixiaobing/article/details/136549794在 SQL Server中,MAX 函数是一个聚合函数,用于从指定的列中检索最大值。它会遍历列中的所有值(忽略NULL值),如果列中的所有值都是NULL,MAX 函数将返回NULL。并返回其中的最大值。MAX 函数对于快速确定一......
  • 约跑小程序源码(asp.net+vue+element++uniapp+sqlserver)
    开发语言:c#框架:后端asp.netmvcpc管理页面:vue+element数据库:sqlserver开发软件:eclipse/myeclipse/idea浏览器:谷歌浏览器小程序框架:uniapp小程序开发软件:HBuilderX一、前言介绍   约跑小程序是一个小程序。用户跑步可以用宜刻小程序进行记录打卡,也可以选择和其他......
  • SqlServer事务语法及使用方法
    原文链接:https://blog.csdn.net/xiaouncle/article/details/52891563事务是关于原子性的。原子性的概念是指可以把一些事情当做一个不可分割的单元来看待。从数据库的角度看,它是指应全部执行或全部不执行的一条或多条语句的最小组合。可以使用一些T-SQL语句在事务中“标记”这些......
  • MSSQLServer dbo没有智能提示/红色报错波浪线
    使用SQLServer的时候碰到了一个问题,就是已经在[24_3_25]中创建了temp1表,但是左侧对象资源管理器窗口中没显示,而且没有输入提示,还有红色报错波浪线。如图所示解决方法:资源管理器没显示选中“表”选择刷新对于报错波浪线和没提示的问题看看是否是因为开启智能提示点击......