USE master GO CREATE LOGIN dbm_login WITH PASSWORD ='bb123456??'; CREATEUSER dbm_user FOR LOGIN dbm_login; GO CREATE MASTER KEY ENCRYPTION BY PASSWORD ='bb123456??'; go CREATE CERTIFICATE dbm_certificate WITH SUBJECT ='dbm'; BACKUP CERTIFICATE dbm_certificate TO FILE ='/tmp/dbm_certificate.cer' WITH PRIVATE KEY ( FILE ='/tmp/dbm_certificate.pvk', ENCRYPTION BY PASSWORD ='bb123456??' ); GO
CREATE LOGIN dbm_login WITH PASSWORD ='bb123456??'; CREATEUSER dbm_user FOR LOGIN dbm_login; GO CREATE MASTER KEY ENCRYPTION BY PASSWORD ='bb123456??'; GO CREATE CERTIFICATE dbm_certificate AUTHORIZATION dbm_user FROM FILE ='/tmp/dbm_certificate.cer' WITH PRIVATE KEY ( FILE ='/tmp/dbm_certificate.pvk', DECRYPTION BY PASSWORD ='bb123456??' ); GO
监听和重启
最后在所有节点执行以下命令
1 2 3 4 5 6 7 8 9
CREATE ENDPOINT [Hadr_endpoint] AS TCP (LISTENER_IP = (0.0.0.0), LISTENER_PORT =5022) FOR DATA_MIRRORING ( ROLE =ALL, AUTHENTICATION = CERTIFICATE dbm_certificate, ENCRYPTION = REQUIRED ALGORITHM AES ); ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED; GRANTCONNECTON ENDPOINT::[Hadr_endpoint] TO [dbm_login];
启用开机自启动ALWAYON,在所有节点执行以下命令
1 2
ALTER EVENT SESSION AlwaysOn_health ON SERVER WITH (STARTUP_STATE=ON); GO
ALTER AVAILABILITY GROUP [ag1] FORCE_FAILOVER_ALLOW_DATA_LOSS
测试
在主库上创建一个数据库,并加入到可用组AG中。
1 2 3 4 5 6 7 8
CREATE DATABASE agtestdb; GO ALTER DATABASE agtestdb SET RECOVERY FULL; GO BACKUP DATABASE agtestdb TO DISK = '/var/opt/mssql/data/agtestdb.bak'; GO ALTER AVAILABILITY GROUP [ag1] ADD DATABASE [agtestdb]; GO