标签:get mysq character 51cto iad ext 权限 程序 log
介绍
MMM(Master-Master replication manager for MySQL)是一套支持双主故障切换和双主日常管理的脚本程序。MMM使用Perl语言开发,主要用来监控和管理MySQL Master-Master(双主)复制,可以说是mysql主主复制管理器。虽然叫做双主复制,但是业务上同一时刻只允许对一个主进行写入,另一台备选主上提供部分读服务,以加速在主主切换时刻备选主的预热,可以说MMM这套脚本程序一方面实现了故障切换的功能,另一方面其内部附加的工具脚本也可以实现多个slave的负载均衡。
优点
高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性。
Monitor节点是单点,可以结合Keepalived实现高可用。
实验要求
两台主服务器master
master1:192.168.177.128
master2:192.168.177.135
两台从服务器slave
slave1:192.168.177.132
slave2:192.168.177.133
监控服务器monitor
monitor:192.168.177.134
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# yum -y install epel-release
# yum clean all && yum makecache
# yum -y install mariadb-server mariadb
# systemctl stop firewalld.service
# setenforce 0
# systemctl start mariadb.service
# vim /etc/my.cnf //
删掉原来的[mysqld]9行,添加如下内容:
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
==注意==server_id要不同
# systemctl restart mariadb.service
# mysql>
# show master status; //记录日志文件名称和位置值,在两台主上查看
在m1上为m2授予从的权限,在m2上也要为m1授予从的权限
# grant replication slave on *.* to ‘replication‘@‘192.168.177.%‘ identified by ‘123456‘; //m1上
# grant replication slave on *.* to ‘replication‘@‘192.168.177.%‘ identified by ‘123456‘;//m2上
#change master to master_host=‘192.168.177.135‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;//m1上
# change master to master_host=‘192.168.177.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;//m2上
# start slave;
# show slave status\G;
# change master to master_host=‘192.168.177.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;
# start slave; //开启同步
# show slave status\G;
# yum -y install mysql-mmm*
安装结束后,对mmm进行配置
# cd /etc/mysql-mmm/
#vim mmm_common.conf //所有主机上都要配置,直接复制多份
<host default>
cluster_interface ens33
……
replication_user replication
replication_password 123456
agent_user mmm_agent
agent_password 123456
<host db1>
ip 192.168.177.128
mode master
peer db2
</host>
<host db2>
ip 192.168.177.135
mode master
peer db1
</host>
<host db3>
ip 192.168.177.132
mode slave
</host>
<host db4>
ip 192.168.177.133
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.177.200 #主服务器虚拟IP
mode exclusive
</role>
<role reader>
hosts db3, db4
ips 192.168.177.20,192.168.177.30 #从服务器虚拟IP
mode balanced
</role>
在主1上面复制:
# scp mmm_common.conf root@192.168.177.135:/etc/mysql-mmm/
# scp mmm_common.conf root@192.168.177.133:/etc/mysql-mmm/
# scp mmm_common.conf root@192.168.177.132:/etc/mysql-mmm/
# systemctl stop firewalld.service
# setenforce 0
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# yum -y install epel-release
# yum clean all && yum makecache
# yum -y install mysql-mmm*
# cd /etc/mysql-mmm
# vim mmm_mon.conf
<host default>
ping_ips 192.168.177.132,192.168.177.128,192.168.177.133,192.168.177.135 //四台地址
monitor_user mmm_monitor
monitor_password 123456
auto_set_online 10
</host>
在m1上:# scp mmm_common.conf root@192.168.177.134:/etc/mysql-mmm/
# mysql>
# grant super, replication client, process on *.* to ‘mmm_agent‘@‘192.168.177.%‘ identified by ‘123456‘;
# grant replication client on *.* to ‘mmm_monitor‘@‘192.168.177.%‘ identified by ‘123456‘;
# flush privileges;
# vim /etc/mysql-mmm/mmm_agent.conf
this db1 //根据规划进行逐一调整
this db2
this db3
this db4
# systemctl start mysql-mmm-agent.service
# systemctl enable mysql-mmm-agent.service #开机自启动
# systemctl start mysql-mmm-monitor.service
# mmm_control show
# mmm_control checks all
# mmm_control move_role writer db2 //指定db2绑定虚拟IP
停止m1 确认 虚拟地址 200 是否移动到 m2 上。注意:主不会抢占
# systemctl stop mariadb.service //m1上
# mmm_control show
db1(192.168.177.128) master/HARD_OFFLINE. Roles:
db2(192.168.177.135) master/ONLINE. Roles: writer(192.168.177.200)
标签:get mysq character 51cto iad ext 权限 程序 log
原文地址:http://blog.51cto.com/13620936/2148077