【alwaysOn】sql server2016 无域控搭建alwayson 【转】

https://www.cnblogs.com/double-K/p/5994166.html

SQL SERVER 2016 AlwaysOn 无域集群+负载均衡搭建与简测

 

  之前和很多群友聊天发现对2016的无域和负载均衡满心期待,毕竟可以简单搭建而且可以不适用第三方负载均衡器,SQL自己可以负载了。windows2016已经可以下载使用了,那么这回终于可以揭开令人憧憬向往的AlwaysOn2016 负载均衡集群的神秘面纱了。

  本篇主要描述个人集群搭建中遇到的坑和一些注意事项,以及2016无域负载均衡的简单体验测试。

搭建体验

基础环境

  想要不使用域环境来搭建AlwaysON 必须使用windows 2016 和sql server2016

  本篇我使用3台虚拟机(主要是为了测试负载均衡,否则2台就可以),为了搭建的纯洁性,我3台机器都是独立安装,没有使用虚机复制。

  

主机名 IP地址
sql16node1 192.168.3.113
sql16node2 192.168.3.114
sql16node3 192.168.3.115
sqlcluster2016(windows集群) 192.168.3.120
L_KK_AWO2016(AlwaysOn监听) 192.168.3.121
16操作系统介质
ed2k://|file|cn_windows_server_2016_x64_dvd_9327743.iso|6020876288|58F585A340248EF7603A48F832F08B6D|/
SQL16介质
ed2k://|file|cn_sql_server_2016_enterprise_x64_dvd_8699450.iso|2452795392|D8AFD8D6245F518F53F720C48E2819C0|/

 

 

遇到的问题

  整体的系统,故障转移集群,AlwaysOn搭建都和2012和2014没有太大差别,所以这里只介绍几个搭建时的特殊注意点。

  1.因为没有域所以需要在”计算机属性“添加计算机的DNS后缀。

  

 

 

  2.需要做域名解析(域名解析运行——>drivers,每个节点都需要配置)

  

 

 

  3.图形化创建会出现问题,导出脚本查看发现脚本不全

  下面是创建AWO的脚本(前提是各个节点已经还原的备份文件)

  注: 以下脚本可以通过SSMS工具切换到SQLCMD模式运行

  

 

复制代码
--- YOU MUST EXECUTE THE FOLLOWING SCRIPT IN SQLCMD MODE.
:Connect sql16node1

IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
    ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END


GO

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [NT Service\MSSQLSERVER]

GO

:Connect sql16node1

IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='AlwaysOn_health')
BEGIN
  ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON);
END
IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name='AlwaysOn_health')
BEGIN
  ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END

GO

:Connect sql16node2

IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
    ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END


GO

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [NT Service\MSSQLSERVER]

GO

:Connect sql16node2

IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='AlwaysOn_health')
BEGIN
  ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON);
END
IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name='AlwaysOn_health')
BEGIN
  ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END

GO

:Connect sql16node3

IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
    ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END


GO

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [NT Service\MSSQLSERVER]

GO

:Connect sql16node3

IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='AlwaysOn_health')
BEGIN
  ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON);
END
IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name='AlwaysOn_health')
BEGIN
  ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END

GO

:Connect sql16node1

USE [master]

GO

CREATE AVAILABILITY GROUP [KK_AG_2016]
WITH (AUTOMATED_BACKUP_PREFERENCE = SECONDARY,
DB_FAILOVER = OFF,
DTC_SUPPORT = NONE)
FOR DATABASE [AWO_2016]
REPLICA ON N'SQL16NODE1' WITH (ENDPOINT_URL = N'TCP://SQL16NODE1:5022', FAILOVER_MODE = AUTOMATIC, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT, BACKUP_PRIORITY = 50, SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)),
    N'SQL16NODE2' WITH (ENDPOINT_URL = N'TCP://SQL16NODE2:5022', FAILOVER_MODE = AUTOMATIC, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT, BACKUP_PRIORITY = 50, SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)),
    N'SQL16NODE3' WITH (ENDPOINT_URL = N'TCP://SQL16NODE3:5022', FAILOVER_MODE = AUTOMATIC, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT, BACKUP_PRIORITY = 50, SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL));

GO

------------这部分代码是图形化工具中缺失的步骤
:Connect sql16node2 ALTER AVAILABILITY GROUP [KK_AG_2016] JOIN; GO ALTER DATABASE [AWO_2016] SET HADR AVAILABILITY GROUP = [KK_AG_2016]; GO :Connect sql16node3 ALTER AVAILABILITY GROUP [KK_AG_2016] JOIN; GO ALTER DATABASE [AWO_2016] SET HADR AVAILABILITY GROUP = [KK_AG_2016]; GO


复制代码

 

创建监听

复制代码
:Connect sql16node1

USE [master]

GO

ALTER AVAILABILITY GROUP [KK_AG_2016]
ADD LISTENER N'L_KK_AWO2016' (
WITH IP
((N'192.168.3.121', N'255.255.255.0')
)
, PORT=8000);

GO
复制代码

 

测试

高可用测试

  简单的看起来与之前没有什么差别,依然依赖故障转移群集,仲裁的的方式与2012R2基本相同,可以使用仲裁磁盘、仲裁文件夹或动态节点投票(偶数个节点依然会动态分配投票权),值得关注的是在windows2016的集群中添加了云仲裁,这个云端配置先不说,真是对于之前配置的跨机房的集群的福音。

 

负载均衡测试

配置负载均衡(此处只是简单的做了一下主节点的负载)

复制代码
alter availability group kk_ag_2016
modify replica on 'sql16node1'
with
(
primary_role
(
read_only_routing_list = (('sql16node2','sql16node3'),'sql16node1')
)
)



alter availability group kk_ag_2016
modify replica on N'sql16node1'
with
(
    secondary_role (read_only_routing_url = N'tcp://sql16node1.kk.com:1433')
)
go
alter availability group kk_ag_2016
modify replica on N'sql16node2'
with
(
    secondary_role (read_only_routing_url = N'tcp://sql16node2.kk.com:1433')
)
go
alter availability group kk_ag_2016
modify replica on N'sql16node3'
with
(
    secondary_role (read_only_routing_url = N'tcp://sql16node3.kk.com:1433')
)
go
复制代码

 

  测试的例子比较简单,也没使用什么压力工具就直接用SSMS管理工具。

  使用监听名称连接或监听IP加端口

  

  另外必须在连接参数中指定ApplicationIntent=ReadOnly

  

 

  开了5个窗口执行语句:

  

 

  使用profiler抓取结果

  

 

  

 

  只是看看能不能负载均衡,咋一看微软还真没骗人。但是要了解这只是只读副本的负载,而不是写入也可以负载!

  另外要注意AlwaysOn的数据同步是有时间延迟的(就算是同步模式)!这点可以参见我另一篇的测试:AlwaysOn 同步时间的测试

 

--------------博客地址------------------------------------------------------------------------------

原文地址: http://www.cnblogs.com/double-K/

posted @ 2020-04-25 16:26  郭大侠1  阅读(1272)  评论(0编辑  收藏  举报