1. 程式人生 > >sqlserver distribution分發alwayson搭建

sqlserver distribution分發alwayson搭建

ima security log ack sdi ilo public tin mode

SqlServer的復制訂閱組建中,分發服務器是一個關鍵的隱患點,現在將分發distribution變成alwayson高可用模式。

發布:TEST125

distribution1 : TEST177

distribution2 : TEST178

訂閱:TEST129

TEST177/178 建立分發,過程略。

添加發布服務器,過程略。

TEST125配置分發TEST177並建立發布test -- (過程)--TEST177 job TEST125-test-1 --logreader

TEST129推送訂閱 --(過程)--TEST177 job TEST125-test-Repl_test-TEST129-3

暫停agent - job

TEST177 distribution屬性完整並完備,copybak至TEST178,restore with nocovery 。

由於無法通過界面建議distribution的alwayson,所以只能依賴於腳本。

中間建立ENDPOINT和開啟EVENT SESSION過程略。

CREATE AVAILABILITY GROUP [dis_awo]
WITH (AUTOMATED_BACKUP_PREFERENCE = SECONDARY,
DB_FAILOVER = OFF,
DTC_SUPPORT = NONE)
FOR DATABASE [distribution
] REPLICA ON NTEST177 WITH (ENDPOINT_URL = NTCP://TEST177.Test.com:5022, FAILOVER_MODE = AUTOMATIC, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT, BACKUP_PRIORITY = 50, SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)), NTEST178 WITH (ENDPOINT_URL = NTCP://TEST178.Test.com:5022, FAILOVER_MODE = AUTOMATIC, AVAILABILITY_MODE =
SYNCHRONOUS_COMMIT, BACKUP_PRIORITY = 50, SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL));

TEST178上聯結可用組,監聽器: dis_ip ,distribution alwayson完成。

TEST177上agentjob TEST125-test-1 生成腳本,在TEST178上執行。

修改點:

@command=N-Publisher [TEST125] -PublisherDB [test] -Distributor [dis_ip] -DistributorSecurityMode 1  -Continuous, 

TEST177上agentjob TEST125-test-Repl_test-TEST129-3 生成腳本,在TEST178上執行。

修改點:

@server=NTEST178, 
@command=N-Subscriber [TEST129] -SubscriberDB [test] -Publisher [TEST125] -Distributor [dis_ip] -DistributorSecurityMode 1 -Publication [Repl_test] -PublisherDB [test]    -Continuous, 

TEST177/178建立主輔啟動job。

declare @role_desc varchar(50)
select @role_desc=a.role_desc from sys.dm_hadr_availability_replica_states a
join sys.dm_hadr_availability_replica_cluster_states b on a.replica_id=b.replica_id
where b.replica_server_name=@@SERVERNAME
if @role_desc=PRIMARY
begin 
exec sp_start_job @job_name=TEST125-test-1
exec sp_start_job @job_name=TEST125-test-Repl_test-TEST129-3
end 
else 
begin 
exec sp_stop_job @job_name=TEST125-test-1
exec sp_stop_job @job_name=TEST125-test-Repl_test-TEST129-3
end

過程完成。

此方法,對自己沒有信心就不要使用,之後復制監控器界面將不再可用,只能通過腳本進行監控復制訂閱。

PS:

在整個搭建測試的過程中,本著哪裏不通改哪裏,最後測試成功,以上是簡化的方法。

過程中其他用到的腳本:

exec sp_helpdistpublisher NTEST125

sp_changedistpublisher @publisher = TEST125
     ,  @property =  active 
    ,  @value = true 

select datasource, srvid from master..sysservers where upper(srvname) = upper(NTEST125)

select datasource, srvid from master..sysservers where upper(srvname) = upper(NTEST129)

select * from MSdistribution_agents

sqlserver distribution分發alwayson搭建