otter項目開源地址:https://github.com/alibaba/otter
canal項目開源地址:https://github.com/alibaba/canal
我們的用這個系統的背景:主要是做異地容災,可是我們需要的現網的數據需要同步到容災區。
|
工作原理:
原理描述:
1.基於Canal開源產品,獲取數據庫增量日志數據。 什么是Canal, 請點擊
2.典型管理系統架構,manager(web管理)+node(工作節點)
a. manager運行時推送同步配置到node節點
b. node節點將同步狀態反饋到manager上
3.基於zookeeper,解決分布式狀態調度的,允許多node節點之間協同工作.
|
組件解釋:
canal:
什么是canal? otter之前開源的一個子項目,開源鏈接地址:http://github.com/alibaba/canal
定位:基於數據庫增量日式解析,提供增量數據訂閱&消費,目前主要支持了mysql
工作原理:
原理相對簡單:類似MYSQL原有的主從復制機制。
1.canal模擬mysql slave 的交互協議,偽裝自己為mysql slave,想mysql master發送dump協議
2.mysql master收到dump請求,開始推送binary log給slave(也就是canal)
3.canal解釋binary log 對象(原始為byte流)
相關文檔:
See the wiki page for : wiki文檔
|
環境配置:
canal、otter依賴jdk環境、node依賴 aria2啟動:
apt-get update && apt-get install default-jdk aria2 -y
|
組件安裝配置:
配置數據庫的字符集編碼:
查看字符編碼:
show variables like 'character%'; [mysqld]
canal:
a. canal原理基於mysql binlog技術;需要binlog的支持,而且log的format格式為ROW:
[mysqld]
log-bin=mysql-bin #添加這一行就ok
binlog-format=ROW #選擇row模式
server_id=1 #配置mysql replaction需要定義,不能和canal的slaveId重復
b. 授權slave同步:
CREATE USER canal IDENTIFIED BY 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
或者:GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
FLUSH PRIVILEGES;
解壓直接使用。
配置文件:
vi conf/example/instance.properties
#################################################
## mysql serverId
canal.instance.mysql.slaveId = 1234
# position info,需要改成自己的數據庫信息
canal.instance.master.address = 127.0.0.1:3306 #指定master 的ip:port
canal.instance.master.journal.name = #配置binlog的file 可以不用配置(默認是以當前啟動)
canal.instance.master.position = #配置binlog的postion 可以不用配置(默認是以當前啟動)
canal.instance.master.timestamp =
#canal.instance.standby.address =
#canal.instance.standby.journal.name =
#canal.instance.standby.position =
#canal.instance.standby.timestamp =
# username/password,需要改成自己的數據庫信息
canal.instance.dbUsername = canal #配置為授權的賬號
canal.instance.dbPassword = canal #配置授權的密碼
canal.instance.defaultDatabaseName = #可以指定數據庫
canal.instance.connectionCharset = UTF-8 #配置編碼格式
# table regex
canal.instance.filter.regex = .*\\..*
#################################################
啟動、停止:
bin/startup.sh bin/stop.sh
zookeeper:
安裝配置:
配置所有的zk主機的hosts文件
192.168.56.1 zk
192.168.56.2 re
192.168.56.3 yt
zk配置文件:
vim conf/zoo.cfg
#################################################
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zk_cluster/zookeeper-3.4.6_node1/data #目錄需要創建
#dataLogDir
# the port at which the clients will connect
clientPort=2181 #每一個節點的port也不一樣
server.1=zk:2887:3892 #不管是前面的port還是后面的port。每一個節點都不一樣
server.2=zk:2888:3893
server.3=zk:2889:3894
server.4=re:3386:3388:observer #遠端的zkobserver角色
server.5=re:3387:3389:observer #遠端的zkobserver角色
server.6=yt:2892:3895:observer #遠端的zkobserver角色
# the maximum number of client connections.
# increase this if you need to handle more clients
observer配置:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
peerType=observer #指定此節點為observer類型
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zk_cluster/zookeeper-3.4.6_node4/data
#dataLogDir
# the port at which the clients will connect
clientPort=2184
server.1=zk:2887:3892
server.2=zk:2888:3893
server.3=zk:2889:3894
server.4=re:2890:3890:observer
server.5=re:2891:3891:observer
server.6=yt:2892:3895:observer
# the maximum number of client connections.
# increase this if you need to handle more clients
啟動、停止:
zookeeper-3.4.6_node4/bin/zkServer.sh start zookeeper-3.4.6_node4/bin/zkServer.sh stop
注意:每一個節點都有一個唯一的myid,這個需要在data目錄下創建一個myid文件並將本地節點對應的server.x x的id寫入myid中。data目錄需要建立哦
列如: 第一個節點:
server.1=zk:2887:3892 只需要在myid文件中輸入 1即可
一條命令查看zk的:
echo stat |nc 192.168.158.140 2181
otter:
manager:
manager是web管理界面,需要mysql數據庫的支持,在manager上部署mysql、授權。還需要原始的數據、載入原始數據;網上下載即可:
wget https://raw.github.com/alibaba/otter/master/manager/deployer/src/main/resources/sql/otter-manager-schema.sql
配置文件:
vim conf/otter.properties
## otter manager domain name #修改為正確訪問ip,生成URL使用
otter.domainName = 192.168.56.4 #配置訪問的域名或者ip
## otter manager http port
otter.port = 8080 #配置web訪問的port
## 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.01:3306/ottermanager #配置manager鏈接數據庫
otter.database.driver.username = otter #配置連接數據庫的用戶名
otter.database.driver.password = otter #配置連接數據庫的密碼
## otter communication port
otter.communication.manager.port = 1099 #配置node鏈接的port
## otter communication pool size otter.communication.pool.size = 10
## default zookeeper address,修改為正確的地址,手動選擇一個地域就近的zookeeper集群列表
otter.zookeeper.cluster.default = 192.168.56.1:2181,192.168.56.1 :2182,192.168.56.1:2183,192.168.56.2:3384,192.168.56.2:3385,192.168.56.3:2186
#配置一個就近的zk群集地址 寫離manager最近的一個也可以 例如:192.168.56.1:2181
## default zookeeper sesstion timeout = 90s
otter.zookeeper.sessionTimeout = 90000
## otter arbitrate connect manager config
otter.manager.address = ${otter.domainName}:${otter.communication.manager.port
啟動、停止:
bin/startup.sh bin/stop.sh
訪問url:
http://192.168.168.4:8080
默認賬號密碼:admin/admin
node:
vim conf/otter.properties
# otter node root dir
otter.nodeHome = ${user.dir}/../
## otter node dir
otter.htdocs.dir = ${otter.nodeHome}/htdocs
otter.download.dir = ${otter.nodeHome}/download
otter.extend.dir= ${otter.nodeHome}/extend
## default zookeeper sesstion timeout = 60s
otter.zookeeper.sessionTimeout = 60000
## otter communication pool size
otter.communication.pool.size = 10
## otter arbitrate & node connect manager config
otter.manager.address = 192.168.56.4:1099 # 指定manager的ip:port
啟動、停止:注:node啟動需要先配置nid,下面解釋。
bin/startup.sh bin/stop.sh
注意:這里提到一個nid,這是node唯一的標識 我們如何得到這個nid的標識號呢?這個在manager上面添加的node產生的,下面會提到。
這個nid文件需要在node的conf目錄;也是只是添加標識號即可。nid位於conf目錄下。
|