MySQL-mmm-two nodes(master)架构
In two node master-master setup, MMM uses five IPs: single permanent IP for each node
that is never changed, 2 reader IPs (read-only) and 1 writer IP (updates). Last three IPs
are migrating between the nodes depending on node availability.
Normally (no replication failures, no replication delay etc) active master has 2 IPs (reader
and writer), standby master - 1 IP (reader). In case of a failure, both - writer and reader
roles migrate to the working node.
测试环境部署
主机 ip 说明
monitor 192.168.1.109 mmm monitor服务器
master 192.168.1.106 数据库服务器(master)
slave1 192.168.1.107 数据库服务器(同样也为master)
vip部署
ip role 说明
192.168.1.220 writer 应用连接此ip执行写操作
192.168.1.221 reader 应用连接此ip执行读操作
192.168.1.222 reader 应用连接此ip执行读操作
具体安装配置过程:
1.安装MySQL-mmm与master-master复制(略)
2.数据库节点创建mmm_monitor与mmm_agent用户
- GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.1.%'
- IDENTIFIED BY 'RepMonitor';
- GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.1.%'
- IDENTIFIED BY 'RepAgent';
3.所有节点(包括monitor节点)配置/etc/mysql-mmm/mmm_common.conf
所有节点均相同
- active_master_role writer
- <host default>
- cluster_interface eth0
- pid_path /var/run/mysql-mmm/mmm_agentd.pid
- bin_path /usr/libexec/mysql-mmm/
- replication_user repl
- replication_password repl
- agent_user mmm_agent
- agent_password RepAgent
- </host>
- <host master>
- ip 192.168.1.106
- mode master
- peer slave1
- </host>
- <host slave1>
- ip 192.168.1.107
- mode master
- peer master
- </host>
- <role writer>
- hosts master, slave1
- ips 192.168.1.220
- mode exclusive
- </role>
- <role reader>
- hosts master, slave1
- ips 192.168.1.221, 192.168.1.222
- mode balanced
- </role>
4.数据库节点配置/etc/mysql-mmm/mmm_agent.conf - include mmm_common.conf
- # The 'this' variable refers to this server. Proper operation requires
- # that 'this' server (db1 by default), as well as all other servers, have the
- # proper IP addresses set in mmm_common.conf.
- # 修改为主机名
- this master
5.monitor节点配置/etc/mysql-mmm/mmm_mon.conf - include mmm_common.conf
- <monitor>
- ip 127.0.0.1
- pid_path /var/run/mysql-mmm/mmm_mond.pid
- bin_path /usr/libexec/mysql-mmm
- status_path /var/lib/mysql-mmm/mmm_mond.status
- ping_ips 192.168.1.1, 192.168.1.106, 192.168.1.107
- auto_set_online 60
- # 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 RepMonitor
- </host>
- debug 0
6.MySQL-mmm测试 - [iyunv@monitor mysql-mmm]# mmm_control show
- master(192.168.1.106) master/ONLINE. Roles: reader(192.168.1.222), writer(192.168.1.220)
- slave1(192.168.1.107) master/ONLINE. Roles: reader(192.168.1.221)
- --关闭master主机上的mysql服务,角色成功切换
- [iyunv@monitor mysql-mmm]# mmm_control show
- master(192.168.1.106) master/HARD_OFFLINE. Roles:
- slave1(192.168.1.107) master/ONLINE. Roles: reader(192.168.1.221), reader(192.168.1.222), writer(192.168.1.220)
- --启动master主机上的mysql服务,角色成功切换
- [iyunv@monitor mysql-mmm]# mmm_control show
- master(192.168.1.106) master/ONLINE. Roles: reader(192.168.1.221)
- slave1(192.168.1.107) master/ONLINE. Roles: reader(192.168.1.222), writer(192.168.1.220)
7.常用命令 - [iyunv@monitor mysql-mmm]# mmm_control show
- [iyunv@monitor mysql-mmm]# mmm_control set_online slave1
- [iyunv@monitor mysql-mmm]# mmm_control set_offline slave1
|