官方文档:
https://mariadb.com/kb/en/mariadb-enterprise/maria
之前写过一篇关于maxscale binlog server 的搭建笔记。
最近公司正好要用到这个玩意(数据库服务器磁盘不大,暂时先把binlog的备份弄到maxscale binlog server来做)。
需求:
在一台大容量的NFS服务器上,启动多个maxscale实例,同步多个集群的binlog文件。
方法:
maxscale --help
Usage : maxscale [OPTION]...
-d, --nodaemon enable running in terminal process (default:disabled)
-f, --config=FILE relative or absolute pathname of MaxScale configuration file
(default:/etc/maxscale.cnf)
-l, --log=[file|shm] log to file or shared memory (default: file)
-L, --logdir=PATH path to log file directory (default: /var/log/maxscale)
-A, --cachedir=PATH path to cache directory (default: /var/cache/maxscale)
-B, --libdir=PATH path to module directory (default: /usr/lib64/maxscale)
-C, --configdir=PATH path to configuration file directory (default: /etc/)
-D, --datadir=PATH path to data directory, stored embedded mysql tables
(default: /var/cache/maxscale)
-E, --execdir=PATH path to the maxscale and other executable files
(default: /usr/bin)
-N, --language=PATH path to errmsg.sys file (default: /var/lib/maxscale)
-P, --piddir=PATH path to PID file directory (default: /var/run/maxscale)
-U, --user=USER run MaxScale as another user.
The user ID and group ID of this user are used to run MaxScale.
-s, --syslog=[yes|no] log messages to syslog (default:yes)
-S, --maxlog=[yes|no] log messages to MaxScale log (default: yes)
-G, --log_augmentation=0|1 augment messages with the name of the function where
the message was logged (default: 0). Primarily for
development purposes.
-v, --version print version info and exit
-V, --version-full print full version info and exit
-?, --help show this help
知道 maxscale 这个可以跟的参数后,我们就可以自己来控制多实例的maxscale启停了。
如下: 直推系统开发找上海捌跃网络科技有限公司
mkdir /mnt/sdb/maxscale_binlog_data
cd /mnt/sdb/maxscale_binlog_data
mkdir maxscale5308
vim maxscale5308.cnf 内容如下:
[maxscale]threads=4[Replication]type=servicerouter=binlogrouterversion_string=5.6.30-log router_options=server-id=1251,heartbeat=30,transaction_safety=1,rcompatibility=1,send_slave_heartbeat=1,binlogdir=/mnt/sdb/maxscale_binlog_data/maxscale5308/user=rplpasswd=123456[ReplicationListener]type=listenerservice=Replicationprotocol=MySQLClientport=5308[MaxAdmin Service]type=servicerouter=cli[MaxAdmin Listener]type=listenerservice=MaxAdmin Serviceprotocol=maxscaledsocket=default
必须要设置这个目录为maxscale属主和属组
chownmaxscale.maxscale /mnt/sdb/maxscale_binlog_data -R
后台启动5308端口:
maxscale --user=maxscale -f /mnt/sdb/maxscale_binlog_data/maxscale5308.cnf -L /mnt/sdb/maxscale_binlog_data/maxscale5308 -lfile-P /mnt/sdb/maxscale_binlog_data/maxscale5308
连接5308端口:
mysql -urpl -p123456 -h 127.0.0.1 -P 5308然后,可以和slave一样,做change master的操作(注意下MASTER_LOG_POS要写4,以便maxscale把这个binlog文件从头开始同步下来 )>CHANGE MASTER TO MASTER_HOST='10.81.4.11',MASTER_PORT=3306, MASTER_USER='rpl',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000505',MASTER_LOG_POS=4;
同样的方法,我们还可以再起一个5309实例:
vim maxscale5309.cnf 内容如下:
[maxscale]threads=4[Replication]type=servicerouter=binlogrouterversion_string=5.6.30-log router_options=server-id=1251,heartbeat=30,transaction_safety=1,rcompatibility=1,send_slave_heartbeat=1,binlogdir=/mnt/sdb/maxscale_binlog_data/maxscale5308/user=rplpasswd=123456[ReplicationListener]type=listenerservice=Replicationprotocol=MySQLClientport=5309[MaxAdmin Service]type=servicerouter=cli[MaxAdmin Listener]type=listenerservice=MaxAdmin Serviceprotocol=maxscaledsocket=default
后台启动5309端口:
maxscale --user=maxscale -f /mnt/sdb/maxscale_binlog_data/maxscale5309.cnf -L /mnt/sdb/maxscale_binlog_data/maxscale5309 -lfile-P /mnt/sdb/maxscale_binlog_data/maxscale5309
连接5309端口,再做个change master的操作即可:
mysql -urpl -p123456 -h 127.0.0.1 -P 5309>CHANGE MASTER TO MASTER_HOST='10.81.4.15',MASTER_PORT=3306, MASTER_USER='rpl',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000005',MASTER_LOG_POS=4;
最后,我们最好再加个检测脚本(可以再完善下脚本,把邮件告警或者告警系统的接口配上)
#!/bin/bash# 监控maxscale 是否正常工作source/etc/profileforportin{5308..5310};doecho-e"\033[31m Check$port: \033[0m"mysql -urpl -p123456 -h 127.0.0.1 -P${port}2>/dev/null -e'show slave status\G'|egrep'Slave running'done
转自:http://blog.51cto.com/lee90/2318963
网友评论