- 配置主主复制(m1和m2两台主服务器互相同步)
-
查看对方的日志文件名称和偏移值
mysql> show master status;
-
主服务器互相提升访问权限(m1、m2服务器分别执行)
# mysql-m1
grant replication slave on *.* to 'replication'@'172.168.100.%' identified by '123456';
# 使用账户为replication 密码为123456
change master to master_host='172.168.100.201',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
# 当在MariaDB-m1上执行时,master_host地址为MariaDB-m2地址
···
# mysql-m2
grant replication slave on *.* to 'replication'@'172.168.100.%' identified by '123456';
change master to master_host='172.168.100.200',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
# 当在MariaDB-m2上执行时,master_host地址为MariaDB-m1地址
-
开启同步,查看服务器的主从状态
start slave;
show slave status\G;
# Slave_IO_Running: Yes
# Slave_SQL_Running: Yes
-
配置m3、m4服务器作为从服务器
show master status;
# 查看m1服务器的日志文件以及偏移值(注意日志文件和偏移值的改变)
# m1和m2互相同步,在此只需执行m1即可
change master to master_host='172.168.100.200',master_user='replication',master_password='123456',master_log_file='mysql_bin.000004',master_log_pos=245;
# m3和m4上分别执行
-
分别查看m3和m4的主从状态
start slave;
show slave status\G;
# Slave_IO_Running: Yes
# Slave_SQL_Running: Yes
-
安装配置MMM架构
前面我们使用wget配置了ALI云源并简易安装 MariaDB 来代替 MySQL ,并搭建了主主同步,主从复制以便完成实验,现在我们来完成MMM架构
-
安装mysql-mmm,修改配置文件(五台主机配置相同)
# yum -y install mysql-mmm* //前面我们配置了epel源,直接yum安装
# vim /etc/mysql-mmm/mmm_common.conf //配置如下
active_master_role writer
<host default>
cluster_interface ens33
pid_path /run/mysql-mmm-agent.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replication
replication_password 123456
agent_user mmm_agent
agent_password 123456
</host>
<host db1>
ip 172.168.100.200
mode master
peer db2
</host>
<host db2>
ip 172.168.100.201
mode master
peer db1
</host>
<host db3>
ip 172.168.100.202
mode slave
</host>
<host db4>
ip 172.168.100.203
mode slave
</host>
<role writer>
hosts db1, db2
ips 172.168.100.100
mode exclusive
</role>
<role reader>
hosts db3, db4
ips 172.168.100.101, 172.168.100.102
mode balanced
</role>
-
快速为其他主机修改配置文件
scp mmm_common.conf root@192.168.100.200:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.100.201:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.100.202:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.100.203:/etc/mysql-mmm/
-
在主机上修改mmm_agent.conf文件的名称
# vim /etc/mysql-mmm/mmm_agent.conf
this db1 //按照规划分别修改为db1、db2、db3、db4
-
在所有主机上对mmm_agent、mmm_moniter进行授权
mysql> grant super, replication client, process on *.* to 'mmm_agent'@'192.168.100.%' identified by '123456';
mysql> grant replication client on *.* to 'mmm_monitor'@'192.168.100.%' identified by '123456';
# flush privileges; //重新加载权限表
-
配置监控主机(在mysql-monitor上配置)
# vim /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf
<monitor>
ip 127.0.0.1
pid_path /run/mysql-mmm-monitor.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
ping_ips 172.168.100.200,172.168.100.201,172.168.100.202,172.168.100.203
auto_set_online 10 #上线时间修改为10s
# The kill_host_bin does not exist by default, though the monitor will
# throw a warning about it missing. See the section 5.10 "Kill Host
# Functionality" in the PDF documentation.
#
# kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host
#
</monitor>
<host default>
monitor_user mmm_monitor
monitor_password 123456
</host>
debug 0
-
关闭防火墙及增强×××
systemctl disable firewalld.service
systemctl stop firewalld.service
setenforce 0
- 启动服务,查看各节点状态
systemctl start mysql-mmm-monitor.service
# ERROR: Can't connect to monitor daemon!,如若出现报错,可尝试重启服务解决
mmm_control check all
# 检查监控服务器对所有主机的监控是否完善
# 检查结果全部OK,则部署完成
至此,MySQL-MMM已经部署成功,进一步的话,我们可以结合Amoeba实现读写分离,Writer 的虚拟VIP可以写入数据库,而 Reader 可以用来读取数据。并通过Keepalived对 monitor 服务器进行双机热备。