SQLSERVER2016 无域控AlwaysOn 实施步骤
SQLSERVER2016 无域控AlwaysOn 实施步骤
步骤:
一、安装3个windows server 2016系统
1)在3台机器建立具有administrators权限的相同账号密码,本例子直接使用administrator;
2)分别修改计算机名称为 sqldb1,sqldb2,sqldb3;
3)配置dns,如testag.com;
4)在3台服务器上做好hosts映射,如:
192.168.40.128 sqldb1
192.168.40.128 sqldb1.testag.com
192.168.40.129 sqldb2
192.168.40.129 sqldb2.testag.com
192.168.40.130 sqldb3
192.168.40.130 sqldb3.testag.com
192.168.40.100 testcluster
192.168.40.100 testcluster.testag.com
192.168.40.200 sqllistner
192.168.40.200 sqllistner.testag.com
二、配置故障转移群集
1)在3台机器上分别安装故障转移群集;
2)建立故障转移群集 testcluster.testag.com;
三、每台机器单独安装SQLSERVER 2016
1)在3台机器上分别安装SQLSERVER2016,独立安装,非群集安装;
2)给3台服务器的SQLSERVER配置相同的启动账号;
3)配置证书;
四、配置Alwayson
1)在另外2台辅助副本机器上恢复要加入alwayson的数据库;
2)用SSMS的GUI创建alwayson;注:我使用的SSMS按本会丢失两个关键语句,导致创建失败,https://www.cnblogs.com/double-K/p/5994166.html 该博有说明,这两个语句是:
------------这部分代码是图形化工具中缺失的步骤
:Connect sqldb2
ALTER AVAILABILITY GROUP [sqldbag] JOIN;
Go
ALTER DATABASE [testdb2] SET HADR AVAILABILITY GROUP = [sqldbag];
GO
:Connect sqldb3
ALTER AVAILABILITY GROUP [sqldbag] JOIN;
GO
ALTER DATABASE [testdb2] SET HADR AVAILABILITY GROUP = [sqldbag];
GO
3)创建侦听器 sqllistner,做好hosts映射;
4)创建只读路由,让alwayson支持读写分离;
ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb1' WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY)); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb1' WITH (SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'tcp://sqldb1.testag.com:1433')); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb2' WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY)); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb2' WITH (SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'tcp://sqldb2.testag.com:1433')); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb3' WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY)); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb3' WITH (SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'tcp://sqldb3.testag.com:1433')); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb1' WITH (PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=('sqldb2','sqldb3','sqldb1'))); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb2' WITH (PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=('sqldb3','sqldb1','sqldb2'))); ALTER AVAILABILITY GROUP sqldbag MODIFY REPLICA ON N'sqldb3' WITH (PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=('sqldb2','sqldb1','sqldb3')));
ssms要让只读路由生效,必须具备两点:
1)连接到制定数据库,而不是默认;
2)增加连接参数 ApplicationIntent=ReadOnly
参考文档:
https://www.cnblogs.com/double-K/p/5994166.html
http://www.cnblogs.com/lyhabc/p/6498712.html
----------------------------------
注意问题和事项:
1)所有sqlserver服务器创建相同密码的administrators权限的windows账号,用作sqlserver的启动账号,避免权限问题;
2)本人使用的ssms2016版本创建alwayson丢失语句,导致创建alwayson失败;
3)无域控,需要对所有资源做hosts映射,包含
sqldb1, sqldb2, sqldb3, sqldb1.testag.com, sqldb2.testag.com, sqldb3.testag.com,
群集服务器 testcluster.testag.com,
侦听器 sqllistner, sqllistner.testag.com
4)忘记创建只读路由,通过侦听器无法连接到只读副本;
5)当alwayson的辅助副本中的 可读辅助副本 设置为 仅读意向 时,ssms无法打开数据库,需要配置 ApplicationIntent=ReadOnly 连接参数才可打开