Mysql-mmm and keepalived high availability MySQL underlying architecture

Source: Internet
Author: User
Tags db2 install perl

First, the structure diagram

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/88/94/wKioL1f8hR7TQBtMAAJkY1jLHuc617.jpg "title=" Mmm.jpg "alt=" Wkiol1f8hr7tqbtmaajky1jlhuc617.jpg "/>

Second, the configuration steps

Required Software

    • Mysql-5.6.20

    • mysql-mmm-agent-2.2.1

    • mysql-mmm-2.2.1

    • mysql-mmm-monitor-2.2.1

    • keepalived-1.2.13

Installation steps

1. Four machines to install MySQL database (can be installed directly yum or compiled installation)

2. Setting the master-slave relationship


function

IP

Server Name

server ID

monitor

192.168.1.234

-

-

monitor

192.168.1.241


master

192.168.1.242

DB1

1

master

192.168.1.240

db2

2

slave

192.168.1.237

db3

3

Slave

192.168.1.238

Db4

4


A total of three users are required to use MYSQL-MMM:

Replication, mmm_agent, and Mmm_monitor (users on the Management server to monitor the cluster status, so you can restrict logins from the Management Server only). Use the following three commands to create a new three user and assign the appropriate permissions:

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 '; Grant Replication Slave on * * to [e-mail protected] ' 192.168.1.% ' identified by ' replication ';

View the status of two MySQL master respectively:

Show Master Status\g

Then use the following statement

Change Master to master_host= ' 192.168.1.242 ', master_user= ' replication ', master_password= ' replication ', Master_log_ File= ' mysql-bin.000005 ', master_log_pos=1857;

To switch from the library to the main library of the synchronization state, when the two main libraries set up each other, set two from the library, you can choose one of the two main libraries as their own synchronization of the main library. After all is set up, use the command start slave; command to open from the library state, before synchronizing, pay attention to the firewall settings. Then use the command show slave status\g on four MySQL servers to see if the synchronization was successful, Slave_io_running:yes, Slave_sql_running:yes, if these two parameters show Yes, Indicates that the settings were successfully synchronized from the library.

3. Installing Mysql-mmm

Install separately on the Management Server (192.168.1.234 and 192.168.1.241)

Yum-y Install mysql-mmm-monitor* and yum-y install perl-time-hires*

Install separately on four MySQL servers

Yum-y Install mysql-mmm-agent*

4. Set Mysql-mmm

a).

Vi/etc/mysql-mmm/mmm_common.conf

The configuration file is as follows, 6 server this file to the same, you can do a copy, direct replication OK

################################################# #active_master_role       writer  

b). Set the Mmm_agent configuration file (set on 4 MySQL servers),

Vi/etc/mysql-mmm/mmm_agent.conf

Configuration file as follows, mainly modify this dbx, according to the content of mmm_common.conf to specify exactly db.

##################################################### #include mmm_common.conf # the ' this ' variable refers  Server. Proper operation requires# That's ' This ' server (db1 by default), as-well as all other servers, with the# Proper IP Addresse s set in Mmm_common.conf.this db1 #########################################################################

c). Set the configuration file for two monitor,

Vi/etc/mysql-mmm/mmm_mon.conf

The configuration file is as follows,

############################################################### #include  mmm_common.conf <monitor >    ip                   192.168.1.234   #这个ip设置monitor自己服务器的ip     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.242, 192.168.1.240, 192.168.1.237, 192.168.1.238     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> 

d). Start Mmm_agent and Mmm_monitor, respectively,

(Start client)

/etc/init.d/mysql-mmm-agent start

(Start the server monitor side)

/etc/init.d/mysql-mmm-monitor start



e). See if Mysql-mmm is working, use commands on the monitor side,

Mmm_control show DB1 (192.168.1.242) master/online. Roles:reader (192.168.1.244) DB2 (192.168.1.240) master/online. Roles:reader (192.168.1.246), writer (192.168.1.243) db3 (192.168.1.237) slave/online. Roles:reader (192.168.1.245) DB4 (192.168.1.238) slave/online. Roles:reader (192.168.1.247)

If this indicates normal.

5. Installation Settings keepalived

Install keepalived on 192.168.1.234 and 192.168.1.241, respectively, using Yum to install directly

Set the configuration file separately, configured as follows

Vi/etc/keepalived/keepalived.conf

The 192.168.1.234 configuration file is:

###############################################################! configuration file for  keepalived global_defs {#   notification_email {#     [ email protected]#     [email protected]#     [ email protected]#   }#   notification_email_from [email protected ]#   smtp_server 192.168.200.1#   smtp_connect_timeout 30    router_id LVS_DEVEL} vrrp_script chk_down {   #script   "netstat - apn | grep mmm_mond;if [[ $? -eq 1 ]];then exit 1;else  exit 0;fi  "  script " Netstat -apn | grep mmm_mond "         interval 2        weight  -30        fall 3        rise 1}  vrrp_instance vi_1 {    state backup    interface  eth0    virtual_router_id 52#    nopreempt     priority 100    advert_int 1    authentication {         auth_type PASS         auth_pass 1111    }    virtual_ipaddress {         192.168.1.249/24 dev eth0 label eth0:1     }    track_interface {         eth0    }    track_script {         chk_down    }    debug    notify_master  "/etc/keepalived/mmm_ Restart.sh "    notify_backup "/etc/keepalived/mmm_stop.sh "#     notify_fault  "/etc/keepalived/mmm_stop.sh"  } ################################################## ##############

The 192.168.1.241 configuration file is:

##################################################################  ! configuration file  for keepalived global_defs {#   notification_email {#      [email protected]#     [email protected]#      [email protected]#   }#   notification_email_from [ Email protected]#   smtp_server 192.168.200.1#   smtp_connect_timeout  30   router_id LVS_DEVEL} vrrp_script chk_down {   #script   "netstat -apn | grep mmm_mond;if [[ $? -eq 1 ]];then  exit 1;else exit 0;fi  "  script " netstat -apn | grep  Mmm_mond "        interval 2         weight -10&nBsp;       fall 3        rise  1} vrrp_instance VI_1 {    state BACKUP     interface eth0    virtual_router_id 52#    nopreempt     priority 85    advert_int 1     authentication {        auth_type pass         auth_pass 1111    }    virtual_ Ipaddress {        192.168.1.249/24 dev eth0 label  eth0:1    }    track_interface {         eth0    }    track_script {         chk_down    }    debug    notify_master  "/etc/ Keepalived/mmm_restart.sh "    notify_backup "/etc/keepalived/mmm_stop.sh "#     notify_fault  "/etc/keepalived/mmm_stop.sh"  } ################################ ############################

/etc/keepalived/mmm_restart.sh content is:

#!/bin/bash Service Mysql-mmm-monitor Start

############################################################

/etc/keepalived/mmm_stop.sh content is:

#!/bin/bash Service Mysql-mmm-monitor Stop

Start keepalived, respectively, with the command

/etc/init.d/keepalived start

To this end of all configurations.

Iii. Key Notes

    1. Mysql-mmm uses the concept of virtual IP, so install mmm_common.conf configuration, MySQL provides external write virtual IP of 192.168.1.243, provide external read virtual IP is 192.168.1.244, 192.168.1.245 , 192.168.1.246, 192.168.1.247, please make reasonable use of the procedure section.

    2. The advantage of this architecture is that the main library has two, any one of the main library down, and another master library can be docked in a timely manner, so that MySQL data write to form redundant high availability, and when a main library hangs, the MMM architecture will also be in time to modify the synchronization of the main library from the library IP, will automatically modify the synchronization IP from the library to the corresponding IP of the normal working main library in a timely manner. This way, master-slave synchronization will not problem, maintain the correctness of the master-slave data, and the use of virtual IP concept, to provide read and write separation function.

    3. One drawback of this architecture is that there is only one monitor side, which is a single point, with the latter considering redundancy, so add the keepalived so that when a monitor end is hung up, using Keepalived's high availability and failover features, The monitor on the other standby machine can be successfully launched to achieve the redundancy effect.


This article is from the "Zheng Xiaoming Technology Blog" blog, make sure to keep this source http://zhengmingjing.blog.51cto.com/1587142/1860643

Mysql-mmm and keepalived high availability MySQL underlying architecture

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.