分类: Mysql/postgreSQL
2013-12-07 13:25:54
系统结构 :
传统的主从结构是 [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真实库状态:
蓝天上的青鸟2013-12-23 12:23:28
pyzwj:是我下载的transfer 有问题嘛,我已经把mysqld的权限改成755了呀,请楼主指点 谢谢
建议选择其中一种方式尝试
1、指定mysql的pid
在 my.cnf 中增加了 在server下面
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
添加下面一行
datadir = /var/lib/mysql/
和
[safe_mysqld]
err-log = /var/log/mysqld.log
pid-file = /var/lib/mysql/mysql.pid
重新启动 mysql
2、修改改selinux的配置文件
[root@localhost selinux]# vi config
SELINUX=disabled
SELINUXTYPE=targeted
然后重启计算机
pyzwj2013-12-20 09:30:46
pyzwj:楼主,我有个问题:
配置slave和transfer时,
Transfer.2.1-based-PS-5.5.18替换T安装目录/usr/local/mysql-transfer/bin/下的mysqld。
但是替换之后,mysqld无法启动,报错如下:
Starting MySQL.The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).[FAILED]
错误日志中的信息:
131219 17:14:46 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
/usr/local/mysql/bin/mysqld: /usr/local/mysql/bin/mysqld: cannot execute binary file
131219
是我下载的transfer 有问题嘛,我已经把mysqld的权限改成755了呀,请楼主指点 谢谢
回复 | 举报pyzwj2013-12-20 09:26:56
楼主,我有个问题:
配置slave和transfer时,
Transfer.2.1-based-PS-5.5.18替换T安装目录/usr/local/mysql-transfer/bin/下的mysqld。
但是替换之后,mysqld无法启动,报错如下:
Starting MySQL.The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).[FAILED]
错误日志中的信息:
131219 17:14:46 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
/usr/local/mysql/bin/mysqld: /usr/local/mysql/bin/mysqld: cannot execute binary file
131219