第三方数据复制引擎--Tungsten-Replicator 主要特点:
1 支持高版本MySQL向低版本复制,5.1-->5.0
2 支持跨数据库系统的复制,MySQL->PgSQL ,MySQL->MongoDB
3 支持多主库向单台Slave的复制,Multi-Master-->Slave
4 G-Replicator提取数据的更新记录写到MySQL 队列表Queue;基于这个队列,可以为其他应用服务提供便利
现在最新版本为Tungsten Replicator2.0.6,较2.0.4,安装可以用cookbook方式,cookbook提供了许多写好的安装脚本等信息;
版本信息:http://code.google.com/p/tungsten-replicator/wiki/Release_Notes
Tungsten Replicator2.0.6的WIKI:http://code.google.com/p/tungsten-replicator/w/list
Tungsten Replicator2.0.4相关文档:https://s3.amazonaws.com/release ... /content/index.html
Tungsten Replicator下载地址:http://code.google.com/p/tungsten-replicator/downloads/list
Tungsten Replicator的基本支持
一、系统要求
ruby 1.8.5 or later (ruby --version)
Ruby openssl libraries ( echo "p 'OK'" | ruby -ropenssl )
Java 1.6 or later (java -version)
GNU tar (tar --version)
rsync 并启动
二、用户权限要求
1、新建用户tungsten,且属于mysql组,这样tugsten才有权限读取MYSQL binlog目录
useradd tungsten -g mysql
2、用户必须能对所有服务器有SSH权限,且无需要密码。可通过 ssh-agent来完成
三、网络要求
1、所有用户可以通过hostname
hostname --ip-address必须返回一个IP(如果用IP方式可以不用配置host)
2、程序应用对外开放接口
3306 (MySQL database)
2112 (Tungsten THL)
10000 (Tungsten RMI)
10001 (JMX management)
四、数据库要求
1、必须支持bin-log,且不同server有不同的server-id
设置MYSQL支持bin-log
修改配置文件my.cnf
点击(此处)折叠或打开
-
[mysqld]
-
# Master replication settings.
-
log-bin=mysql-bin
-
server-id=1
-
max_allowed_packet=48m
-
innodb_flush_lot_at_trx_commit=2
- sync_binlog=1
default-storage-engine 必须为innodb引擎
innodb_buffer_pool_size 512M为最低设置
max_allowed_packet最低设置为16M,建议48M。如果设置的较小,复制过程中将报错 "Packet for query is too large"
innodb_flush_lot_at_trx_commit=2 and sync_binlog=1 ,此设置是为防止BinLog崩溃,如未设置,install过程中会报warn
之后重新启动MYSQL
binlog-ignore-db = tungsten_tungsten
执行tungsten会往数据库里写数据,所所加上这句。不让这句写入binlog ;tungsten_服务名
2、数据库必须支持innodb
默认搜索引擎要设置为innodb
MYSQL5.1设置为,修改配置文件my.cnf
default-table-type=innodb
MYSQL5.5默认引擎为innodb,无需设置
3、必须有能所有SERVER都有权限的用户,可通过mysql -u USER -pPASSWORD -P PORT -h HOST 连接
创建Tungsten Replicator数据用户与数据库,
点击(此处)折叠或打开
-
mysql> grant all on *.* to root@'hostIP' identified by 'password' with grant option;
- mysql> grant all on *.* to tungsten@'hostIP' identified by 'password' with grant option;
Tungsten Replicator的安装(Tungsten Replicator 2.0.4 及2.0.6亦可)
一、下载Tungsten Replicator
点击(此处)折叠或打开
cd /usr/local/src/
wget http://tungsten-replicator.googlecode.com/files/tungsten-replicator-2.0.4.tar.gz
tar zxvf tungsten-replicator-2.0.4.tar.gz
mv tungsten-replicator-2.0.4 /usr/local/tungsten
chown -R tungsten /usr/local/tungsten
wget http://tungsten-replicator.googlecode.com/files/tungsten-replicator-2.0.4.tar.gz
tar zxvf tungsten-replicator-2.0.4.tar.gz
mv tungsten-replicator-2.0.4 /usr/local/tungsten
chown -R tungsten /usr/local/tungsten
可通过./tools/tungsten-installer --help-all 查看所有参数
datasource-user与password 要有权限均可以master与slave中执行MYSQL权限
service-name可以随意取名
home-directory为tungsten目录
start-and-report 为配置并启动,用这个参数执行后会自动启动replicator,并且conf中写入services等相关配置
点击(此处)折叠或打开
./tools/tungsten-installer --master-slave \
--master-host=masterhost \
--datasource-user=tungsten \
--datasource-password=badpwd \
--datasource-port=3306 \
--cluster-hosts=masterhost ,slavehost \
--service-name=tungsten \
--home-directory=/usr/local/tungsten \
--start-and-report
--master-host=masterhost \
--datasource-user=tungsten \
--datasource-password=badpwd \
--datasource-port=3306 \
--cluster-hosts=masterhost ,slavehost \
--service-name=tungsten \
--home-directory=/usr/local/tungsten \
--start-and-report
如果两个HOST的SSH端口不是默认的22,要加入参数--net-ssh-option=port=19000 \
执行中会输出 大概如下内容
点击(此处)折叠或打开
-
...
-
Processing services command...
-
NAME VALUE
-
---- -----
-
appliedLastSeqno: -1
-
appliedLatency : -1.0
-
role : slave
-
serviceName : tungsten
-
serviceType : local
-
started : true
-
state : ONLINE
- Finished services command...
执行完成后,会同时在master\slave两台上出现tungsten_tungsten数据库、同时有replicator进程,且打开10000端口;
查看tungsten_tungsten数据库
点击(此处)折叠或打开
mysql> show tables;
+-----------------------------+
| Tables_in_tungsten_tungsten |
+-----------------------------+
| consistency |
| heartbeat |
| trep_commit_seqno |
| trep_shard |
+-----------------------------+
4 rows in set (0.00 sec)
+-----------------------------+
| Tables_in_tungsten_tungsten |
+-----------------------------+
| consistency |
| heartbeat |
| trep_commit_seqno |
| trep_shard |
+-----------------------------+
4 rows in set (0.00 sec)
点击(此处)折叠或打开
-
mysql> select * from trep_commit_seqno\G;
-
*************************** 1. row ***************************
-
task_id: 0
-
seqno: 0
-
fragno: 0
-
last_frag: 1
-
source_id: 192.168.0.12
-
epoch_number: 0
-
eventid: mysql-bin.000039:0000000000000427;140
-
applied_latency: 0
-
update_timestamp: 2013-02-18 15:28:12
-
shard_id: tungsten_tungsten
-
extract_timestamp: 2013-02-18 15:28:12
- 1 row in set (0.00 sec)
Tungsten Replicator的备份与恢复功能
Tungsten Replicator提供了简单的备份与恢复的功能 ,使用了两个简单的plugins(mysqldump and xtrabackup)
配置文件中已经默认配置了BackUp相关功能,可做相应修改
配置文件位置为/usr/local/tungsten/tungsten-replicator/conf/,列出如下几个重要参数
点击(此处)折叠或打开
-
less tungsten-replicator/conf/static-tungsten.properties |grep backup
-
replicator.backup.default=mysqldump
-
...
-
replicator.backup.agent.mysqldump.mysqldumpOptions=--opt --all-databases --add-drop-database
-
replicator.storage.agent.fs.directory=/usr/local/tungsten/backups/tungsten
-
replicator.backup.agent.mysqldump.hotBackupEnabled=true
-
replicator.backup.agent.xtrabackup.hotBackupEnabled=true
- replicator.backup.agent.xtrabackup.options=user=${replicator.global.db.user}&password=${replicator.global.db.password}&host=${replicator.global.db.host}&port=${replicator.global.db.port}&directory=/tmp/innobackup&archive=/tmp/innobackup.tar&mysqldatadir=/var/lib/mysql/&mysql_service_command=/etc/init.d/mysql
注:备份与恢复 都要在offline的情况下执行,状态为“OFFLINE:NORMAL”,如不正常情况会出现“OFFLINE:ERROR”,则会恢复失败
查看Replicator当前状态
-
./tungsten-replicator/bin/trepctl status
-
...
-
state : ONLINE
-
-
./tungsten-replicator/bin/trepctl status
-
...
-
state : OFFLINE:NORMAL
- Finished status command...
-
# ./tungsten-replicator/bin/trepctl backup
- Backup completed successfully; URI=storage://file-system/store-0000000003.properties
-
# ./tungsten-replicator/bin/trepctl restore -uri storage://file-system/store-0000000003.properties
- Restore is pending; check log for status
-
# ls /usr/local/tungsten/backups/tungsten
-
storage.index store-0000000002-mysqldump-1871676336962858846.sql store-0000000003.properties
-
store-0000000001-mysqldump-341047084963524507.sql store-0000000002.properties
- store-0000000001.properties store-0000000003-mysqldump-4915067303150219872.sql
在正常Master/Slave模式下,如果有其中一台Slave坏掉,不影响正常的Tungsten-Replicator运行,但如果 Master失败,则要重新都offline,然后保证数据一致性;
正常要加Slave,要同时offline 数据一致后,重新online,但因为已经有一台Slave,则可以避免Master的OFFLINE;思路为用一台Slave做一台新Slave的供体,保证两台数据一致;
1、设置slave1 为offline状态 ,然后备份数据,然后再online,online后,会自动同步offline的过程中产生的master的数据
-
trepctl -host slave1 offline
-
trepctl -host slave1 backup
- trepctl -host slave1 online
-
trepstart
-
trepctl -host newslave restore
- trepctl -host newslave online
Tungstent 日志管理 :http://www.lishiming.net/thread-5309-1-1.html