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狀態爲運行

打開 同步管理, 點擊啓用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章