1、修改实例下所有节点的数据同步模式,在master数据库下运行
--查找所有异步提交的辅助节点,修改为同步提交模式 -- SYNCHRONOUS_COMMIT 同步提交模式 -- ASYNCHRONOUS_COMMIT 异步提交模式 select 'ALTER AVAILABILITY GROUP ['+a.name+'] MODIFY REPLICA ON N'''+c.replica_server_name+''' WITH (AVAILABILITY_MODE = SYNCHRONOUS_COMMIT) GO' from sys.availability_groups a --join sys.dm_hadr_instance_node_map b on a.resource_id=b.ag_resource_id join sys.availability_replicas c on a.group_id=c.group_id where availability_mode = 0 --0异步提交 ,1 同步提交模式
2、执行集群转移脚本,在目标节点执行
--执行集群转移的脚本 select ' ALTER AVAILABILITY GROUP ['+a.name+'] FAILOVER;' from sys.availability_groups a --执行集群强制转移(会丢数据) select ' ALTER AVAILABILITY GROUP ['+a.name+'] FORCE_FAILOVER_ALLOW_DATA_LOSS;' from sys.availability_groups a
3、查看队列情况
SELECT ar.replica_server_name AS [副本名称] ,
ar.availability_mode_desc as [同步模式], DB_NAME(dbr.database_id) AS [数据库名称] , dbr.database_state_desc AS [数据库状态], dbr.synchronization_state_desc AS [同步状态], dbr.synchronization_health_desc AS [同步健康状态], ISNULL(CASE dbr.redo_rate WHEN 0 THEN -1 ELSE CAST(dbr.redo_queue_size AS FLOAT) / dbr.redo_rate END, -1) AS [Redo延迟(秒)] , ISNULL(CASE dbr.log_send_rate WHEN 0 THEN -1 ELSE CAST(dbr.log_send_queue_size AS FLOAT) / dbr.log_send_rate END, -1) AS [Log传送延迟(秒)] , dbr.redo_queue_size AS [Redo等待队列(KB)] , dbr.redo_rate AS [Redo速率(KB/S)] , dbr.log_send_queue_size AS [Log传送等待队列(KB)] , dbr.log_send_rate AS [Log传送速率(KB\S)] FROM [master].sys.availability_replicas AS AR INNER JOIN [master].sys.dm_hadr_database_replica_states AS dbr ON ar.replica_id = dbr.replica_id WHERE dbr.redo_queue_size IS NOT NULL
4、修改一台服务器可用性组中的某个节点为同步提交模式或者异步提交模式
-- SYNCHRONOUS_COMMIT 同步提交模式 -- ASYNCHRONOUS_COMMIT 异步提交模式 USE [master] GO ALTER AVAILABILITY GROUP [TreasureWDDB140226] MODIFY REPLICA ON N'WINDBGYS2091' WITH (AVAILABILITY_MODE = SYNCHRONOUS_COMMIT) GO
5、从系统中查看和调整WSFC投票权(注意是区分大小写的)
查看集群WSFC投票权
cluster node /prop |find "NodeWeight"
修改某个WSFC投票权(1拥有投票权 0 没有投票权)
cluster node XXXXXX /prop NodeWeight = 0
这个设置在win2008r2的cluster services 服务里面是没有的,需要单独打补丁才有这个设置选项具体参考
https://support.microsoft.com/zh-cn/kb/2494036
6、加入节点遇到 “计算机已经加入集群”
有时候一些wsfc节点在加入集群的时候遇到错误,请确保该机器不再集群中,如果这机器以前加入过某个集群
后来退出来的,可能有些注册表信息项目没有删除干净容易遇到这样的问题。(我还遇到过一个新装的机器报这个错误)
解决方法:
在该机器命令行运行 cluster node /force
7、alwayon加入新的机器和db
--在源机器上创建端点 xxxx是机器名 ---主库执行 结果全选主库执行 select 'ALTER AVAILABILITY GROUP ['+a.name+'] ADD REPLICA ON N''XXXX'' WITH (ENDPOINT_URL = N''TCP://XXXX.gycomm.cn:5022'', FAILOVER_MODE = MANUAL, AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT, BACKUP_PRIORITY = 50, SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL));' from sys.availability_groups a --如果目标机器第一次加入到集群中需要创建端点和授予端点用户权限 ---辅库执行 --确保gycomm\sqluser登录和权限 CREATE ENDPOINT [Hadr_endpoint] AS TCP (LISTENER_PORT = 5022) FOR DATA_MIRRORING (ROLE = ALL, ENCRYPTION = REQUIRED ALGORITHM AES) GO 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 [gycomm\sqlUser] GO 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 --目标机器加入到组 主库执行,结果全选在辅库执行 select 'ALTER AVAILABILITY GROUP ['+a.name+'] JOIN' from sys.availability_groups a --目标机器db加入到组 主库执行,结果全选在辅库执行 select 'ALTER database ['+b.database_name+'] set hadr AVAILABILITY GROUP =' + a.name from sys.availability_groups a inner join sys.availability_databases_cluster b on a.group_id = b.group_id