重要参考:http://wenku.baidu.com/link?url=dTLpH5iqasckqvVXB1FsTPMR39o4GuInI9R3NW-D4O4FlAKzeHnFd9_vIGG8HsR7CmJinpQaroqjHJNE5QBxrNy0FxCNMxYxgCug7vGIif_
由淘宝核心系统研发—数据库组开发的MySQL-Transfer,用于解决MySQL主从同步延迟的问题,从MySQL单线程到多线程的工作模式。可以观看@丁奇的相关资料:
MySQL多线程同步-Transfer使用说明
MySQL异步复制延迟解决的架构设计与运维架构—在线播放—优酷网
系统结构 :
传统的主从结构是 [Master] à [Slave], Master和slave主从关系;
使用transfer以后,[Master] à [Transfer] .--> [Slave], Master和Transfer主从关系,Transfer和Slave是Client-Server关系。
服务器环境:
主库:192.168.15.216 (3306端口)
从库:192.168.15.217 (3306端口)
Transfer: 192.168.15.217 (3307端口)
MySQL版本:mysql-5.5.18-linux2.6-x86_64.tar.gz
存储引擎:Innodb
Database: rocdata
MySQL-Transfer:Transfer.2.1-based-PS-5.5.18
注:
Tranfsfer相同的表使用同一个线程更新,若只有一个表,性能与原生版本相同。要体现效果,一般16个表或以上,考虑到线上大库都有分表,这个条件比较容易满足。
一、192.168.15.216主库配置
首先确认主库上使用row格式的binlog,配置/etc/my.cnf:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld1]
port = 3306
socket = /tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/mysqldata/
bind-address=192.168.15.216
skip-external-locking
skip-name-resolve
user=mysql
max_allowed_packet = 256M
query_cache_size=256M
max_connections=2000
max_connect_errors=10000
key_buffer_size=6000M
read_buffer_size=32M
read_rnd_buffer_size = 32M
myisam_sort_buffer_size=512M
tmp_table_size=1024M
old-passwords
interactive_timeout=60
wait_timeout=60
connect_timeout=60
table_cache=8192
thread_cache_size=512
sort_buffer_size=128M
back_log = 500
thread_concurrency=48
expire_logs_days=10
log-bin=mysql-bin
#binlog_format=STATEMENT
binlog_format=ROW
#binlog_format="MIXED
# master
server-id = 1
binlog-do-db = rocdata
binlog-ignore-db = mysql
启动MySQL,并查看Pos状态。
二、192.168.15.217从库配置。
MySQL端口3306和3307 ,建议MySQL TDIR目录区分开来。我的MySQL和Transfer目录:
/usr/local/mysql/
/usr/local/mysql-transfer
Transfer.2.1-based-PS-5.5.18替换T安装目录/usr/local/mysql-transfer/bin/下的mysqld。
1、配置3306端口,同步Master数据,这里不需要写主从同步信息,和单台MySQL配置一样。
/usr/local/mysql目录部署一个MySQL版本5.5.18(真实库),配置/etc/my.cnf:
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/mysqldata/data3306
bind-address=192.168.15.217
skip-external-locking
skip-name-resolve
user=mysql
max_allowed_packet = 256M
query_cache_size=256M
max_connections=2000
max_connect_errors=10000
key_buffer_size=6000M
read_buffer_size=32M
read_rnd_buffer_size = 32M
myisam_sort_buffer_size=512M
tmp_table_size=1024M
old-passwords
interactive_timeout=60
wait_timeout=60
connect_timeout=60
table_cache=8192
thread_cache_size=512
sort_buffer_size=128M
back_log = 500
thread_concurrency=48
expire_logs_days=10
启动MySQL 3306端口,并导入数据,前提需要记录的Pos点,保证Transfer同步正常。和传统的主从拷贝数据一样。
此时3306端口的运行状态。
2、配置3307 Transfer服务
a) /usr/local/mysql-transfer/目录部署一个MySQL (T),版本5.5.18
b) 用附件中的mysqld替换T安装目录/usr/local/mysql-transfer/bin/下的mysqld
c) 在/usr/local/mysql-transfer/log 目录下执行下执行 for((i=0; i<=16; i++)); do mkdir $i;done
d) 配置/etc/my3307.cnf,做以下修改:
[mysqld]
port = 3307
socket = /tmp/mysql3307.sock
basedir=/usr/local/mysql
datadir=/mysqldata/data3307
bind-address=192.168.15.217
skip-external-locking
skip-name-resolve
user=mysql
max_allowed_packet = 1G
query_cache_size=256M
max_connections=2000
max_connect_errors=10000
key_buffer_size=6000M
read_buffer_size=32M
read_rnd_buffer_size = 32M
myisam_sort_buffer_size=512M
tmp_table_size=1024M
old-passwords
interactive_timeout=60
wait_timeout=60
connect_timeout=60
table_cache=8192
thread_cache_size=512
sort_buffer_size=128M
back_log = 500
thread_concurrency=48
expire_logs_days=10
#tranfer
transfer_slave_thread = 16
remote_slave_hostname = 192.168.15.217
remote_slave_username = transfer
remote_slave_password = transferpw
remote_slave_port = 3306
relay-log =/usr/local/mysql/log/mysqld-relay-bin
relay-log-index =/usr/local/mysql/log/mysqld-relay-bin.index
master-info-file =/usr/local/mysql/log/master.info
relay-log-info-file =/usr/local/mysql/log/relay-log.info
log_slave_updates = 0
slave_skip_errors=1062,1032
#slave 192.168.15.217
server-id = 3
replicate_do_db = rocdata
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
[说明]配置给Transfer的这个uname必须有Slave的super权限
e) Transfer需要导入同步的数据库结构,不需要数据
f) Slave的 max_allowed_packet设置为1G (建议)
g) 启动Transfer并设置为Master的从库
具体步骤:
在3306端口上赋予Transfer 有Slave的super权限:
mysql> grant all privileges on *.* to 'transfer'@'192.168.15.217' identified by 'transferpw';
在主库192.168.15.216赋予Transfer 有 replicate privileges权限:
mysql> grant replication slave, reload, super on *.* to 'repluser216'@'192.168.15.217' identified by 'replpasswd216';
启动Transfer并设置为Master的从库:
mysql> CHANGE MASTER to MASTER_HOST='192.168.15.216', MASTER_PORT=3306, MASTER_USER='repluser216', MASTER_PASSWORD='replpasswd216', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=82104;
三、测试
1、在192.168.15.216主库rocdate上创建表test,并写入数据:
mysql> create table test ( id int(4));
mysql> insert into test values(1);
mysql> insert into test values(2);
2、查看192.18.15.216 MySQL(T)和MySQL真实库状态:
说明:关于 MySQL-Transfer 的性能还未做测试,后期有时间会补上……有错误的地方,希望CU的大侠可以指正,谢谢
(责任编辑:IT) |