MySQLmmm群集
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQLmmm群集相关的知识,希望对你有一定的参考价值。
简介:MMM即Master-Master Replication Manager for mysql(mysql主主复制管理器)通过MMM方案能实现服务器的故障转移,从而实现mysql的高可用。
操作环境:五台Linux(CentOS7)虚拟机:两台主服务器,两台从服务器,一台监控服务器。
具体操作步骤:
五台虚拟机分配IP:同网段
因为要在线安装软件包,所以模式都设置为NAT模式;
首先配置阿里云源,安装epel源(所有机器都要装)
安装完源以后清空之前的,重新设置
安装mariadb
编辑配置文件
删除原有【mysqld】文件插入
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=var/lib/mysql/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这里不能一样其他相同)
关闭防火墙开启mariadb,直接mysql登录mariadb
在主1服务器上查看master状态(mysql_bin.000003 245 必须注意)
在两台主服务器上提权
开启slave
mmm群集脚本:
主服务器1 192.168.120.128 db1 vip:192.168.120.200
主服务器2 192.168.120.129 db2
从服务器1 192.168.120.130 db3 vip:192.168.120.210
从服务器2 192.168.120.131 db4 192.168.120.220
监控服务器 192.168.120.132
=======================================
四台同装 //下载阿里云源yum配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release -y //安装epel源
yum clean all && yum makecache //清空所有,重新设置数据缓存
yum install mariadb-server mariadb -y //安装mariadb
vim /etc/my.cnf
删除原有【mysqld】文件插入
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=var/lib/mysql/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
关闭防火墙
systemctl stop firewalld.service
setenforce 0
开启服务
systemctl start mariadb.service
可以登录mysql
授权(两台主上)
grant replication slave on . to ‘replication‘@‘192.168.120.%‘ identified by ‘123456‘;
change master to master_host=‘192.168.120.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000003‘,master_log_pos=245;
开启同步
start slave;
查看状态
show slave statusG;
从服务器上
change master to master_host=‘192.168.120.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000003‘,master_log_pos=245;
开启同步
start slave;
查看状态
show slave statusG;
=================安装mmm======================
四台同装
yum install mysql-mmm* -y
cd /etc/mysql-mmm/
vim mmm_common.conf
修改
(网卡名称改成ens33)
<host default>
4 cluster_interface ens33 (网卡名称改成ens33)
5 pid_path /run/mysql-mmm-agent.pid
6 bin_path /usr/libexec/mysql-mmm/
7 replication_user replication (名称)
8 replication_password 123456 (密码)
9 agent_user mmm_agent
10 agent_password 123456 (代理密码)
13 <host db1>
14 ip 192.168.120.128 主1IP
15 mode master
16 peer db2
17 </host>
18
19 <host db2>
20 ip 192.168.120.129 主2IP
21 mode master
22 peer db1
23 </host>
24
25 <host db3>
26 ip 192.168.120.130 从1IP
27 mode slave
28 </host>
29
30 <host db4>
31 ip 192.168.120.131 从2IP
32 mode slave
33 </host>
34
35 <role writer> 虚拟用户
36 hosts db1, db2
37 ips 192.168.120.200 200
38 mode exclusive
39 </role> 要同网段
40
41 <role reader>
42 hosts db3, db4
43 ips 192.168.120.210, 192.168.120.220 210,220用户
44 mode balanced
45 </role>
在主1上(远程复制功能)
scp mmm_common.conf [email protected]:/etc/mysql-mmm/
scp mmm_common.conf [email protected]:/etc/mysql-mmm/
scp mmm_common.conf [email protected]:/etc/mysql-mmm/
监控服务器安装好mmm后
cd /etc/mysql-mmm/
vim mmm_mon.conf
修改
8 ping_ips 192.168.120.128,192.168.120.129,192.168.120.130,192.168.120.131
9 auto_set_online 10 //10秒自动上线
21 monitor_password 123456
----------------------------在四台服务器上为mmm agent授权-----
//授权代理mmm_agent
grant super, replication client, process on . to ‘mmm_agent‘@‘192.168.120.%‘ identified by ‘123456‘;
//监控授权mmm_monitor
grant replication client on . to ‘mmm_monitor‘@‘192.168.120.%‘ identified by ‘123456‘;
flush privileges; //刷新
vim mmm_agent.conf
修改四台
this db1
this db2
this db3
this db4
----------------------------在所有数据库服务器上启动mysql-mmm-agent---------
四台
systemctl start mysql-mmm-agent.service 开启服务
systemctl enable mysql-mmm-agent.service 开机自启动
systemctl start mysql-mmm-monitor.service 监控上开启
mmm_control show 监控上查看四台服务器状态
显示
db1(192.168.120.128) master/ONLINE. Roles: writer(192.168.120.200)
db2(192.168.120.129) master/ONLINE. Roles:
db3(192.168.120.130) slave/ONLINE. Roles: reader(192.168.120.210)
db4(192.168.120.131) slave/ONLINE. Roles: reader(192.168.120.220)
切换
mmm_control move_role writer db2
mmm_control checks all //需要全部ok
-----------------------------------故障检测------------------------------------
systemctl stop mariadb.service //关闭主1mariadb
mmm_control show //监控那台查看(自动会切第二台)
在四台服务器上为监控机地址授权登录
grant all on . to ‘testdba‘@‘192.168.120.132‘ identified by ‘123456‘;
flush privileges; //刷新
-----------------在监控服务器上-------------------------
mysql -utestdba -p -h 192.168.120.200 //直接登录访问
以上是关于MySQLmmm群集的主要内容,如果未能解决你的问题,请参考以下文章