合 使用OGG for MSSQL微服务快速双向同步RDS数据库(双主)
类似文章
OGG有传统的经典架构,也有最新的微服务,2个都可以远程捕获和应用数据,对数据库服务器是0侵入,而传统的经典架构是纯命令行模式,最新的微服务架构是图形化界面操作,几乎所有操作都可以在界面进行。
相关文章可以参考:
使用OGG for MySQL微服务快速双向同步RDS数据库:https://www.dbaup.com/shiyongoggweifuwukuaisushuangxiangtongburdsshujuku.html
OGG用于跨云RDS for MySQL之间配置双主实时同步–OGG远程捕获和投递:https://www.dbaup.com/oggyongyukuayunrdszhijianpeizhishuangzhushishitongbuyuanchengbuhuohetoudi.html
otter用于跨云RDS for mysql之间配置双主实时同步:https://www.dbaup.com/otteryongyukuayunrdszhijianpeizhishuangzhushishitongbu.html
OGG用于PG数据库之间双主实时同步(RDS for PG亦可)–OGG远程捕获和投递:https://www.dbaup.com/oggyongyupgshujukuzhijianshuangzhushishitongburds-for-pgyikeoggyuanchengbuhuohetoudi.html
使用OGG for PG微服务快速双向同步RDS数据库(双主):https://www.dbaup.com/shiyongogg-for-pgweifuwukuaisushuangxiangtongburdsshujukushuangzhu.html
使用阿里的开源工具otter,这个方案经过验证是可行的。阿里数据同步工具Otter和Canal简介请参考:https://www.dbaup.com/alishujutongbugongjuotterhecanaljianjie.html
使用OGG for Oracle微服务双向同步Oracle数据库搭建双主架构(含DDL):https://www.dbaup.com/shiyongogg-for-oracleweifuwushuangxiangtongbuoracleshujukuhanddl.html
使用OGG for mysql微服务搭建双主架构(含DDL):https://www.dbaup.com/shiyongogg-for-mysqlweifuwudajianshuangzhujiagouhanddl.html
使用OGG for SQL Server微服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | -- 创建专用网络 docker network create --subnet=172.72.9.0/24 mssql-network -- MSSQL A docker rm -f mssql2019a docker run -d --name mssql2019a -h mssql2019a \ -p 33200:1433 --net=mssql-network --ip 172.72.9.200 \ -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=lhr@xxt123" -e TZ=Asia/Shanghai \ --privileged=true -u root \ mcr.microsoft.com/mssql/server:2019-latest -- MSSQL B docker rm -f mssql2019b docker run -d --name mssql2019b -h mssql2019b \ -p 33201:1433 --net=mssql-network --ip 172.72.9.201 \ -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=lhr@xxt123" -e TZ=Asia/Shanghai \ --privileged=true -u root \ mcr.microsoft.com/mssql/server:2019-latest -- 使用ogg微服务,这里的端口需要一致 docker rm -f lhrogg214mamssql docker run -d --name lhrogg214mamssql -h lhrogg214mamssql \ --net=mssql-network --ip 172.72.9.205 \ -p 9392:3389 -p 9000-9005:9000-9005 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true lhrbest/ogg214mamssql:v1.0 \ /usr/sbin/init -- 启用代理 docker exec -it mssql2019a /opt/mssql/bin/mssql-conf set sqlagent.enabled true docker exec -it mssql2019b /opt/mssql/bin/mssql-conf set sqlagent.enabled true docker restart mssql2019a mssql2019b -- 2个SQL Server库需要配置 sqlcmd -S 192.168.66.35,33200 -U sa -P lhr@xxt123 sqlcmd -S 192.168.66.35,33201 -U sa -P lhr@xxt123 -- 修改密码 USE [master] GO ALTER LOGIN [sa] WITH CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF GO USE [master] GO ALTER LOGIN [sa] WITH PASSWORD=N'lhr' GO -- 创建同步数据库 create database lhrdb; go -- 创建用户 use lhrdb; create login ogg with password = 'lhr' ,DEFAULT_DATABASE=lhrdb, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; create user ogg for login ogg with default_schema=ogg; exec sp_addsrvrolemember @loginame = N'ogg', @rolename = N'sysadmin'; ALTER ROLE db_owner ADD MEMBER ogg; create schema ogg; go -- 启用cdc use lhrdb; EXECUTE sys.sp_cdc_enable_db; create table testogg(id int primary key , name varchar(100)); SELECT name, recovery_model, recovery_model_desc,is_cdc_enabled FROM sys.databases WHERE name in ('lhrdb') ; SELECT name,is_tracked_by_cdc FROM lhrdb.sys.tables WHERE is_tracked_by_cdc = 1; go -- OGGMA cat > /ogg214c/ogg_ma/odbc.ini <<"EOF" [mssql2019a] Driver = ODBC Driver 17 for SQL Server Server = 172.72.9.200,1433 Database = lhrdb User = ogg Password = lhr [mssql2019b] Driver = ODBC Driver 17 for SQL Server Server = 172.72.9.201,1433 Database = lhrdb User = ogg Password = lhr EOF odbcinst -i -s -f /ogg214c/ogg_ma/odbc.ini -- 添加TRANDATA su - oracle adminclient CONNECT http://127.0.0.1:9000 deployment deploy214 as oggadmin password lhr dblogin useridalias MSSQLA DOMAIN OGGMA list tables dbo.* ADD TRANDATA ogg.* ADD TRANDATA dbo.* INFO TRANDATA dbo.* -- 源端配置JOB EXECUTE sys.sp_cdc_drop_job 'cleanup'; cd /ogg214c/ogg_deploy/etc/conf/ogg/ ./ogg_cdc_cleanup_setup.sh createJob ogg lhr lhrdb "172.72.9.200,1433" ogg |
访问:http://192.168.66.35:9000 ,用户名:oggadmin,密码:lhr
创建身份证明
或直接访问:http://192.168.66.35:9001/
创建检查点表
由于我们要配置双主,所以,这里的2个SQL Server都需要配置检查点表,否则只在目标端配置检查点表即可。
配置SQLA到SQLB的实时同步
创建extract进程
参数:
1 2 3 4 5 6 | EXTRACT exta SOURCEDB mssql2019a USERIDALIAS MSSQLA, DOMAIN OGGMA IGNOREREPLICATES TRANLOGOPTIONS FILTERTABLE ogg.ckpt EXTTRAIL ./dirdat/e1 TABLE dbo.*; |
创建replicate进程
参数:
1 2 3 | REPLICAT repa TARGETDB mssql2019b USERIDALIAS MSSQLB, DOMAIN OGGMA MAP dbo.*, TARGET dbo.*; |
测试同步
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | -- 源端 insert into testogg values(1,'a'); select * from testogg; [root@docker35 ~]# sqlcmd -S 172.72.9.200 -U ogg -P lhr -d lhrdb 1> select * from testogg; 2> GO id name ----------- ---------------------------------------------------------------------------------------------------- 1 a (1 rows affected) 1> [root@docker35 ~]# sqlcmd -S 172.72.9.201 -U ogg -P lhr -d lhrdb 1> select * from testogg; 2> GO id name ----------- ---------------------------------------------------------------------------------------------------- 1 a (1 rows affected) |