MySQL HA by using Mysql-mmm

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用户
  
  
  
  
  1. GRANT REPLICATION CLIENT   ON *.* TO 'mmm_monitor'@'192.168.1.%'   
  2. IDENTIFIED BY 'RepMonitor'
  3. GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.1.%'   
  4. IDENTIFIED BY 'RepAgent'
3.所有节点(包括monitor节点)配置/etc/mysql-mmm/mmm_common.conf
所有节点均相同
  
  
  
  
  1. active_master_role      writer 
  2.  
  3. <host default
  4.     cluster_interface       eth0 
  5.     pid_path                /var/run/mysql-mmm/mmm_agentd.pid 
  6.     bin_path                /usr/libexec/mysql-mmm/ 
  7.     replication_user        repl 
  8.     replication_password    repl 
  9.     agent_user              mmm_agent 
  10.     agent_password          RepAgent 
  11. </host> 
  12.  
  13. <host master> 
  14.     ip      192.168.1.106 
  15.     mode    master 
  16.     peer    slave1 
  17. </host> 
  18.  
  19. <host slave1> 
  20.     ip      192.168.1.107 
  21.     mode    master 
  22.     peer    master 
  23. </host> 
  24.  
  25. <role writer> 
  26.     hosts   master, slave1 
  27.     ips     192.168.1.220 
  28.     mode    exclusive 
  29. </role> 
  30.  
  31. <role reader> 
  32.     hosts   master, slave1 
  33.     ips     192.168.1.221, 192.168.1.222 
  34.     mode    balanced 
  35. </role> 

4.数据库节点配置/etc/mysql-mmm/mmm_agent.conf

  
  
  
  
  1. include mmm_common.conf 
  2.  
  3. # The 'this' variable refers to this server.  Proper operation requires 
  4. # that 'this' server (db1 by default), as well as all other servers, have the 
  5. # proper IP addresses set in mmm_common.conf. 
  6. # 修改为主机名
  7. this master 

5.monitor节点配置/etc/mysql-mmm/mmm_mon.conf

  
  
  
  
  1. include mmm_common.conf 
  2.  
  3. <monitor> 
  4.     ip                  127.0.0.1 
  5.     pid_path            /var/run/mysql-mmm/mmm_mond.pid 
  6.     bin_path            /usr/libexec/mysql-mmm 
  7.     status_path         /var/lib/mysql-mmm/mmm_mond.status 
  8.     ping_ips            192.168.1.1, 192.168.1.106, 192.168.1.107 
  9.     auto_set_online     60 
  10.  
  11.     # The kill_host_bin does not exist by default, though the monitor will 
  12.     # throw a warning about it missing.  See the section 5.10 "Kill Host 
  13.     # Functionality" in the PDF documentation. 
  14.     # 
  15.     # kill_host_bin     /usr/libexec/mysql-mmm/monitor/kill_host 
  16.     # 
  17. </monitor> 
  18.  
  19. <host default
  20.     monitor_user        mmm_monitor 
  21.     monitor_password    RepMonitor 
  22. </host> 
  23.  
  24. debug 0 

6.MySQL-mmm测试

  
  
  
  
  1. [root@monitor mysql-mmm]# mmm_control show 
  2.   master(192.168.1.106) master/ONLINE. Roles: reader(192.168.1.222), writer(192.168.1.220) 
  3.   slave1(192.168.1.107) master/ONLINE. Roles: reader(192.168.1.221) 
  4.  
  5. --关闭master主机上的mysql服务,角色成功切换 
  6. [root@monitor mysql-mmm]# mmm_control show 
  7.   master(192.168.1.106) master/HARD_OFFLINE. Roles:  
  8.   slave1(192.168.1.107) master/ONLINE. Roles: reader(192.168.1.221), reader(192.168.1.222), writer(192.168.1.220) 
  9.  
  10. --启动master主机上的mysql服务,角色成功切换 
  11. [root@monitor mysql-mmm]# mmm_control show 
  12.   master(192.168.1.106) master/ONLINE. Roles: reader(192.168.1.221) 
  13.   slave1(192.168.1.107) master/ONLINE. Roles: reader(192.168.1.222), writer(192.168.1.220) 

7.常用命令

  
  
  
  
  1. [root@monitor mysql-mmm]# mmm_control show 
  2. [root@monitor mysql-mmm]# mmm_control set_online slave1 
  3. [root@monitor mysql-mmm]# mmm_control set_offline slave1 

 

你可能感兴趣的:(mysql,mysql-mmm)