debug 0
....
[root@monitor ~]#
3)修改客户端配置文件
master1配置
[root@master1 ~]# vi /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this master1
master2配置
[root@master2 ~]# vi /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this master2
slave1配置
[root@slave1 ~]# vi /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this slave1
slave2配置
[root@slave2 ~]# vi /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this slave2
==========================================================
3 mysql-MMM架构使用
启动MMM集群架构
设置集群中服务器为online状态
mysql-MMM架构部署完成后需要启动,数据库端启动mmm-agent进程,管理端启动mmm-monitor进程,启动完成后设置所有数据库主机状态为online。
步骤一:启动MMM集群架构
1)启动mmm-agent进程
master1操作:
[root@master1 ~]# /etc/init.d/mysql-mmm-agent start
master2操作:
[root@master2 ~]# /etc/init.d/mysql-mmm-agent start
slave1操作:
[root@slave1 ~]# /etc/init.d/mysql-mmm-agent start
slave2操作:
[root@slave2 ~]# /etc/init.d/mysql-mmm-agent start
2)启动mmm-monitor进程
monitor主机操作:
[root@monitor ~]# /etc/init.d/mysql-mmm-monitor start
步骤二:设置集群中服务器为online状态
控制命令只能在管理端monitor服务器上执行。
查看当前集群中各服务器状态:
[root@monitor ~]# mmm_control show
master1(192.168.4.10)master/AWAITING_RECOVERY. Roles:
master2(192.168.4.11)master/AWAITING_RECOVERY. Roles:
slave1(192.168.4.12)slave/AWAITING_RECOVERY. Roles:
slave2(192.168.4.13)slave/AWAITING_RECOVERY. Roles:
设置4台数据库主机状态为online:
[root@monitor ~]# mmm_control set_online master1
OK: State of 'master1' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor ~]# mmm_control set_online master2
OK: State of 'master2' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor ~]# mmm_control set_online slave1
OK: State of 'slave1' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor ~]# mmm_control set_online slave2
OK: State of 'slave2' changed to ONLINE. Now you can wait some time and check its new roles!
再次查看当前集群中各服务器状态:
[root@monitor ~]# mmm_control show
master1(192.168.4.10)master/ONLINE. Roles:writer(192.168.4.200)
master2(192.168.4.11)master/ONLINE. Roles:
slave1(192.168.4.12)slave/ONLINE. Roles:reader(192.168.4.201)
slave2(192.168.4.13)slave/ONLINE. Roles:reader(192.168.4.202)
步骤三:测试mysql-MMM架构
2)mysql-MMM虚拟IP访问测试
[root@client ~]# mysql -h192.168.4.200-uroot -ppwd123 -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#
[root@client ~]# mysql -h192.168.4.201-uroot -ppwd123 -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#
[root@client ~]# mysql -h192.168.4.202-uroot -ppwd123 -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#
3)主数据库宕机测试
[root@master1 ~]# service mysql stop //停止master1上服务
Shutting down mysql....[确定]
[root@monitor ~]# mmm_control show //查看集群内服务器状态
通过输出信息可以看到虚拟IP从master1切换到master2:
master1(192.168.4.10)master/HARD_OFFLINE. Roles:
master2(192.168.4.11)master/ONLINE. Roles:writer(192.168.4.200)
slave1(192.168.4.12)slave/ONLINE. Roles:reader(192.168.4.201)
slave2(192.168.4.13)slave/ONLINE. Roles:reader(192.168.4.202)
[root@client ~]# mysql -h192.168.4.200-uroot -ppwd123 -e "show databases" //访问虚拟IP测试
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#
MySQL-MMM集群架构就完成了。
过程中遇到的问题:
我在第一次 mmm_control show 查看集群服务器状态的时候,发现除了master1的状态为AWAITING_RECOVERY, 其他三台为HARD_OFFLINE。
这是因为我最开始创建的monitor用户没有被同步过去,在主库master1 重新创建就好。
查看MYSQL数据库中所有用户 ,
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
还有一个问题,我的环境是虚拟机克隆的,配置主从的时候遇到UUID冲突的问题,
停止数据库 把数据库所在目录下的auto.cnf 备份一份之后,删除。 重启就好了。
主库master1 一定要记得开启 log-slave-updates