mysql數據庫同步系統otter部署實踐(中國與歐洲同步)


otter的介紹就不說了, 自己去看官網https://github.com/alibaba/otter/wiki

本系統中, 中國的服務器部署在阿里雲上, 歐洲服務器部署在亞馬遜上, 由於阿里雲的網絡不支持外網回環訪問(即在本機上向本機的外網地址發送數據), 所以需要將node與manager部署在不同的主機上。如果只是在虛擬機中調試, 很多服務都可以放在一台主機中。

1. 阿里雲服務器

1. mysql服務, 外網ip 120.x.x.1,  內網ip 10.x.x.1

2. manager服務, 本系統與mysql安裝在同一台服務器上

3. node服務, 外網ip 120.x.x.2,   內網ip 10.x.x.2

4. zookeeper服務, 外網ip 120.x.x.3,  內網ip 10.x.x.3

2. 亞馬遜服務器

1. mysql服務, 外網ip 59.x.x.1, 內網ip 172.x.x.1

2. node服務,外網ip 59.x.x.2, 內網ip 172.x.x.2

3. zookeeper服務, 外網ip 59.x.x.2, 內網ip 172.x.x.3

3. 下載otter和zookeeper

已經編譯好的壓縮包

https://github.com/alibaba/otter/releases

下載manager系統表

https://raw.github.com/alibaba/otter/master/manager/deployer/src/main/resources/sql/otter-manager-schema.sql

下載ddl同步策略表

https://github.com/alibaba/otter/tree/master/node/deployer/src/main/resources/sql/otter-system-ddl-mysql.sql

下載zookeeper

http://www.apache.org/dyn/closer.cgi/zookeeper/

4. 配置阿里雲mysql

修改兩台服務器的mysql配置, /etc/mysql/my.cnf (5.7版本的mysql的配置文件應該是/etc/mysql/mysql.conf.d/mysqld.cnf)

注意: server-id需要和manager上配置的node的id一致

[mysqld]

character-set-server=utf8
collation-server=utf8_general_ci   #設置mysql的字符集

#bind-address = 127.0.0.1       這一行要注釋掉

server-id                  = 1   
log_bin                    = /data/lib/mysql/mysql-bin.log
expire_logs_days      = 5
max_binlog_size       = 200M
binlog_do_db           = xxx
binlog_format          = ROW

重啟mysql

5. 配置亞馬遜上的mysql

只是server-id不一樣

[mysqld]

character-set-server=utf8
collation-server=utf8_general_ci   #設置mysql的字符集

#bind-address = 127.0.0.1       這一行要注釋掉

server-id                  = 2  
log_bin                    = /data/lib/mysql/mysql-bin.log
expire_logs_days      = 5
max_binlog_size       = 200M
binlog_do_db           = xxx
binlog_format          = ROW

重啟mysql

6. 導入系統表和otter用戶

注意修改密碼

mysql>source otter-manager-schema.sql mysql>source otter-system-ddl-mysql.sql mysql>CREATE USER canal IDENTIFIED BY 'canal; mysql>GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%'; mysql>GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%'; mysql>FLUSH PRIVILEGES;

 

7. 安裝aria2和zookeeper

 

在需要運行node服務器上安裝aria2, 它是一個下載工具, otter使用它下載了什么文件, 我也不知道

apt-get install aria2

在分別在阿里雲和亞馬遜的兩台服務器上安裝zookeeper和運行zookeeper, 這個過程很簡單

cd zookeeper-3.4.9/conf/ cp zoo_sample.cfg zoo.cfg cd ../bin/ ./zkServer.sh start

8. 配置manager

cd manager/conf/ vim otter.properties

## otter manager domain name
otter.domainName = 120.x.x.1   #修改為當前服務器的公網地址 
## otter manager http port
otter.port = 8080
## jetty web config xml
otter.jetty = jetty.xml

## otter manager database config
otter.database.driver.class.name = com.mysql.jdbc.Driver
otter.database.driver.url = jdbc:mysql://127.0.0.1:3306/otter  #由於mysql和manager在同一個服務器
otter.database.driver.username = canal
otter.database.driver.password = canal    #需要修改為實際的密碼

## otter communication port
otter.communication.manager.port = 1099

## otter communication pool size
otter.communication.pool.size = 10

## default zookeeper address
otter.zookeeper.cluster.default = 120.x.x.3:2181 #修改為阿里雲上安裝的zookeeper
## default zookeeper sesstion timeout = 60s

...

9. 啟動manager

cd manager/bin ./startup.sh

在瀏覽器中打開manager主頁

http://120.x.x.1:8080/

右擊右上角的登錄按鈕, 用戶名為admin, 密碼也為admin (點擊系統管理->權限管理, 然后修改密碼)

9.1添加zookeeper管理

點擊機器管理->zookeeper管理,

9.2 添加Node管理

點擊 機器管理->Node管理

注意: 添加順序不能改變, manager會為node分配一個id, mysql的server-id要與node id一致

機器名稱 : aliyun_node

機器ip:      10.x.x.2

機器端口 :   2088

外部ip:        120.x.x.2

啟用外部IP:  是

zookeeper集群: aliyun_zookeeper

保存

再添加一次

機器名稱 : aws_node

機器ip:      172.x.x.2

機器端口 :   2088

外部ip:        59.x.x.2

啟用外部IP:  是

zookeeper集群: aliyun_zookeeper

保存

9.3 添加數據源

配置管理 -> 數據源配置

9.4 添加數據表

schema name: xxx

table name: test

數據源:   aliyun_mysql

保存

schema name: xxx

table name: test

數據源:   aws_mysql

保存

9.5 添加canal配置

canal名稱: aliyun_canal

zookeeper集群: aliyun_zookeeper

數據庫地址: 120.x.x.1:3306;

數據庫賬號:  canal

數據庫密碼:  canal

保存

canal名稱: aws_canal

zookeeper集群: aws_zookeeper

數據庫地址: 59.x.x.1:3306;

數據庫賬號:  canal

數據庫密碼:  canal

保存

9.6添加channel

同步管理 -> 添加

9.7添加pipeline

同步管理 -> aliyun<>aws -> 添加

pipeline名字: aliyun->aws

select機器:    aliyun_node

load機器:      aws_node

主站點:         是

canal名字:    aliyun_canal

高級設置:      勾

支持ddl同步:  是

保存

pipeline名字: aws->aliyun

select機器:    aws_node

load機器:      aliyun_node

主站點:         否

canal名字:    aliyun_canal

高級設置:      勾

支持ddl同步:  否

保存

10. 配置/啟動node

1. 配置aliyun上的node

cd node/conf/

echo 1 > nid

vim otter.properties

...

## otter arbitrate & node connect manager config
otter.manager.address = 120.x.x.1:1099      #填manager的外網地址

1. 配置aws上的node

cd node/conf/

echo 2 > nid

vim otter.properties

...

## otter arbitrate & node connect manager config
otter.manager.address = 120.x.x.1:1099    #填manager的外網地址

然后執行startup.sh

注意: 這個腳本默認配置了很大的內容, 如果內存不夠, 可以修改這個文件

11. 啟動

打開 機器管理 -> Node管理, 顯示兩個node狀態為運行

打開 同步管理, 點擊啟用

 

https://my.oschina.net/u/2343729/blog/826050


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM