标签:mysql主主复制 erro writer 离线 aliyun 程序 repos ref vim
MySQL-MMM高可用MMM(Master-Master replication manager for MySQL,MySQL主主复制管理器)是是一套支持双主故障切换和双主日常管理的脚本程序。MMM使用Perl语言开发,主要用来监控和管理MySQL Master-Master(双主)复制,虽然叫做双主复制,但是业务上同一时刻只允许对一个主进行写入,另一台备选主上提供部分读服务,以加速在主主切换时备选主的预热,可以说MMM这套脚本程序一方面实现了故障切换的功能,另一方面其内部附加的工具脚本也可以实现多个Slave的read负载均衡。
主机 | 操作系统 | IP地址 | 主要软件 |
---|---|---|---|
mysql-m1主服务器 | CentOS 7 | 192.168.27.128 | MySQL-MMM |
mysql-m2主服务器 | CentOS 7 | 192.168.27.139 | MySQL-MMM |
mysql-m3从服务器 | CentOS 7 | 192.168.27.147 | MySQL-MMM |
mysql-m4从服务器 | CentOS 7 | 192.168.27.142 | MySQL-MMM |
mysql-monitor | CentOS 7 | 192.168.27.143 | MySQL-MMM |
systemctl stop firewalld.service
setenforce 0
vim /etc/my.cnf
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/data/mysql_error.log #错误日志
general_log=ON #开启通用日志
general_log_file=/usr/local/mysql/data/mysql_general.log
log_bin=mysql-bin #二进制日志
slow_query_log=ON #慢日志
slow_query_log_file=mysql_slow_query.log
long_query_time=1
binlog-ignore-db=mysql,information_schema #不生成二进制日志文件
log_slave_updates=true #同步
sync_binlog=1 #同步二进制日志
auto_increment_increment=2 #字段一次递增多少
auto_increment_offset=1 #自增字段起始值
server-id = 1 #四台服务器的server-id不可相同
systemctl start mysqld.service
netstat -natp | grep 3306
mysql -u root -p
show master status;
grant replication slave on . to ‘replication‘@‘192.168.27.%‘ identified by ‘123456‘; #m1和m2都要授权
change master to master_host=‘192.168.27.139‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=154; #m1同步m2
change master to master_host=‘192.168.27.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=154; #m2同步m1
start slave; #开启同步
show slave status\G; #查看slave状态
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
mysql -u root -p
change master to master_host=‘192.168.27.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=154; #分别让m3和m4同步m1
start slave;
show slave status\G; #查看slave状态
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
-CentOS默认没有安装mysql-mmm软件包,推荐使用epel源,五台主机都要安装epel源和MMM。
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_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.27.128
mode master
peer db2
</host>
<host db2>
ip 192.168.27.139
mode master
peer db1
</host>
<host db3>
ip 192.168.27.147
mode slave
</host>
<host db4>
ip 192.168.27.142
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.27.111 #虚拟IP
mode exclusive
</role>
<role reader>
hosts db3, db4
ips 192.168.27.101, 192.168.27.102 #虚拟IP
mode balanced
</role>
mysql -u root -p
grant super, replication client, process on . to ‘mmm_agent‘@‘192.168.27.%‘ identified by ‘123456‘;
grant replication client on . to ‘mmm_monitor‘@‘192.168.27.%‘ identified by ‘123456‘;
flush privileges; #刷新权限
vi /etc/mysql-mmm/mmm_agent.conf
includemmm_common.conf
this db1 #分别修改为db1、db2、db3、db4
systemctl start mysql-mmm-agent.service
systemctl enable mysql-mmm-agent.service
vim /etc/mysql-mmm/mmm_mon.conf
----省略内容----
ping_ips 192.168.27.128,192.168.27.139,192.168.27.147,192.168.27.142 #数据库服务器地址
auto_set_online 10
----省略内容----
<host default>
monitor_user mmm_monitor
monitor_password 123456
</host>
----省略内容----
systemctl start mysql-mmm-monitor.service //启动mysql-mmm-monitor
mmm_control show //查看各节点的情况
db1(192.168.27.128) master/ONLINE. Roles: writer(192.168.27.111)
db2(192.168.27.139) master/ONLINE. Roles:
db3(192.168.27.147) slave/ONLINE. Roles: reader(192.168.27.101)
db4(192.168.27.142) slave/ONLINE. Roles: reader(192.168.27.102)
mmm_control show //查看各节点的情况
db1(192.168.27.128) master/HARD.OFFLINE.Roles:
db2(192.168.27.139) master/ONLINE. Roles: writer(192.168.27.111)
db3(192.168.27.147) slave/ONLINE. Roles: reader(192.168.27.101)
db4(192.168.27.142) slave/ONLINE. Roles: reader(192.168.27.102)
mmm_control show //查看各节点的情况
db1(192.168.27.128) master/ONLINE. Roles:
db2(192.168.27.139) master/ONLINE. Roles: writer(192.168.27.111)
db3(192.168.27.147) slave/ONLINE. Roles: reader(192.168.27.101)
db4(192.168.27.142) slave/ONLINE. Roles: reader(192.168.27.102)
mmm_control show //查看各节点的情况
db1(192.168.27.128) master/ONLINE. Roles:
db2(192.168.27.139) master/ONLINE. Roles: writer(192.168.27.111)
db3(192.168.27.147) slave/HARD.OFFLINE. Roles:
db4(192.168.27.142) slave/ONLINE. Roles: reader(192.168.27.102)reader(192.168.27.101)
mmm_control show //查看各节点的情况
db1(192.168.27.128) master/ONLINE. Roles:
db2(192.168.27.139) master/ONLINE. Roles: writer(192.168.27.111)
db3(192.168.27.147) slave/ONLINE. Roles: reader(192.168.27.101)
db4(192.168.27.142) slave/ONLINE. Roles: reader(192.168.27.102)
标签:mysql主主复制 erro writer 离线 aliyun 程序 repos ref vim
原文地址:http://blog.51cto.com/13659182/2145200