MySQL dual-machine hot-standby with keepalived in CENTOS6 (1/2)

Source: Internet
Author: User

This article describes how to cooperate with the former to achieve keepalived dual-machine hot standby


System environment: CentOS 6.3 x64

MySQL version: mysql-5.6.10

Keepalived version: keepalived-1.2.7


mysql-vip:192.168.7.253

mysql-master1:192.168.7.201

mysql-master2:192.168.7.249


First, close iptables and SELinux.

# Service Iptables Stop

# Setenforce 0

# Vi/etc/sysconfig/selinux

---------------

Selinux=disabled

---------------

Note: If you need to open iptables on the line, you need to add a rule to make the keepalived VRRP pass.

# iptables-a Input-p vrrp-j ACCEPT


1. keepalived installation and configuration on the mysql-master1:192.168.7.201 server


Compile the installation, the actual kernel version of the machine is subject to

# wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz

# tar ZXVF keepalived-1.2.7.tar.gz

# CD keepalived-1.2.7

#./configure--prefix=/usr/local/keepalived--with-kernel-dir=/usr/src/kernels/2.6.32-

279.el6.x86_64

# Make && make install


Set up keepalived boot script

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

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

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

# Chkconfig keepalived on


Create a new profile, and the default keepalived boot will go to the/etc/keepalived directory to look for the configuration file

# mkdir/etc/keepalived

# vi/etc/keepalived/keepalived.conf

------------------

Global_defs {

Notification_email {

Lzyangel@126.com

}

#当主, the backup device changes, by mail notification

Notification_email_from lzyangel@126.com

Smtp_server stmp.126.com

Smtp_connect_timeout 30

router_id mysql-ha

}

Vrrp_instance vi_1{

# defined as main device in initialization state

State BACKUP

# Attention Card Interface

Interface eth0

VIRTUAL_ROUTER_ID 51

# priority, the other one to 90

Priority 100

Advert_int 1

# do not proactively preempt resources

Nopreempt

Authentication {

# authentication method, can be pass or AH two kinds of authentication methods

Auth_type Pass

# Authentication Password

Auth_pass 1111

}

virtual_ipaddress {

# virtual IP address, increased deletion as state changes

192.168.7.253

}

}

Virtual_server 192.168.7.253 3306 {

# check Real_server status every 2 seconds

Delay_loop 2

# LVS algorithm

Lb_algo WRR

# LVS Mode

Lb_kind DR

# Session Hold Time

Persistence_timeout 60

Protocol TCP

Real_server 192.168.7.201 3306 {

# weight

Weight 3

# Script executed after service down detected

notify_down/etc/rc.d/keepalived.sh

Tcp_check {

# Connection Timeout

Connect_timeout 10

# Number of links

Nb_get_retry 3

# re-connect interval time

Delay_before_retry 3

# Health Check Port

Connect_port 3306

}

}

}

----------------------

Script to be executed after the test service down is written

# vi/etc/rc.d/keepalived.sh

-------------

#!/bin/sh

/etc/init.d/keepalived stop

-------------

# chmod +x/etc/rc.d/keepalived.sh

Note: This script is used by the configuration file Notify_down option above, keepalived use the Notify_down option to check

Real_server Service status.

This script is triggered when a Real_server service failure is found.

As we can see, the script is just one command:

The keepalived process is forced to kill by Pkill Keepalived, thus realizing the automatic transfer of MySQL fault.

In addition, we do not have to worry about two MySQL will also provide data update operations, because each MySQL on the keepalived configuration only

There are native MySQL Ip+vip, not two MySQL ip+vip.

Home 1 2 last page

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.