MySQL primary master replication +keepalived for high availability

Source: Internet
Author: User

MySQL's simplest high-availability

2 pc machines

MySQL master-master replication enables data synchronization

KeepAlive realize dual machine hot standby, ensure the normal operation of service

1 , Environment

Master1 10.0.0.201

Master2 10.0.0.202

2,Master1Operation Authorization

Mysql>grant replication Slave on * * to ' admin ' @ ' 10.0.0.202 ' identified by ' 123456 ';// Authorization

Mysql>show Master Status\g;

3,Master2Operation Authorization

Mysql->grant replication Slave on * * to ' admin ' @ ' 10.0.0.201 ' identified by ' 123456 ';// Authorization

Mysql->show Master Status\g;

4, Master1-201Action on

Change Master to

Master_host= ' 10.0.0.202 ',

Master_user= ' admin ',

Master_password= ' 123456 ',

Master_log_file= ' mysql-bin.000006 ',

master_log_pos=-242;

Mysql->start slave;

Mysql->show slave status\g;

5, Master2-202Action on

Change Master to

Master_host= ' 10.0.0.201 ',

Master_user= ' admin ',

Master_password= ' 123456 ',

Master_log_file= ' mysql-bin.000002 ',

master_log_pos=242;

Mysql->start slave;

Mysql->show slave status\g;

6, Master201and the202Simultaneous installationkeepalived(You can also useYuminstallation, I experimented with theYum)

# TAR-XVF Keepalived-1.1.20.tar.gz

# CD keepalived-1.1.20

#./configure--prefix=/usr/local/keepalived

# Make && make install

# cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/

# cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/

# mkdir/etc/keepalived

# cp/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/

# cp/usr/local/keepalived/sbin/keepalived/usr/sbin/

7.keepalived configuration file

! Configuration File for Keepalived

Global_defs {

Notification_email {

}

Notification_email_from [email protected]

}

Vrrp_instance Vi_1 {

State backup///2 all written as backup otherwise noprempt useless, the Lord's up will seize the main

interface eth0///VIP external interface Location

VIRTUAL_ROUTER_ID//// identification number, main unified

priority, high at the beginning of the primary

Advert_int 2

Nopreempt/// not preemption mode, set on high priority

authentication{// certification

Auth_type PASS

Auth_pass 1111

}

virtual_ipaddress {/// virtual IP

192.168.1.137/24 Dev eth0

}

}

at first I want to write scripts in the keepalive configuration file to monitor the mysqld service, and then always have a problem, I am outside to write script detection, the script is as follows:

#!/bin/bash

#Totle: Check MySQL

#Description: Check MySQL status

#Author: Chenmin

#date: 2015-09-22

Check_mysql_health () {

mysql-h*****-u*****-p****-E "Showslave status\g" >/dev/null 2>&1// write as per MySQL authorization

}/// detection of MySQL availability

Check_keepalived_health () {/// detect keepalived service is turned on

Health= '/etc/init.d/keepalived status|grep-c pid '///0 is not turned on,1 is normal

[$health = 0]&&/etc/init.d/keepalived start// open keepalived if not turned on

}

Main () {

Check_mysql_health&&check_keepalived_health/// guaranteed when MySQL is available keepalived must be available

check_mysql_health| | check_mysql_health| | check_mysql_health| | /etc/init.d/keepalived stop

}/ /If 3 MySQL available detection fails, shut down the keepalived service and let backup occupy the VIP

While True/// dead Loop,2 seconds to perform a test

Do

Main

Sleep 2

Done

[Email protected] mysqlcheck]# nohup bash/etc/keepalived/mysqlcheck/check_mysql.sh &

Background Execution Detection

there may be many deficiencies, long connections will be broken, VIP up time may have to 2 seconds more, so I'm going to use the following mysql-mmm to achieve the primary master cross-cutting.


This article is from the "innovation sharing gallop inside and out" blog, please be sure to keep this source http://10554846.blog.51cto.com/10544846/1697185

MySQL primary master replication +keepalived for high availability

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.