MYSQL + MHA + keepalive + VIP installation configuration (3) ----- keepalived installation _ MySQL

Source: Internet
Author: User
MYSQL + MHA + keepalive + VIP installation configuration (3) ----- keepalived installation configuration 1. Overview

Keepalived description: Keepalived is used to detect the status of a web server. if a web server crashes or a job fails, Keepalived will detect it, and remove the faulty web server from the system. when the web server works normally, Keepalived automatically adds the web server to the server group. all these tasks are completed automatically without manual interference, all you need to do is repair the faulty web server.

II. environment

vip:192.168.1.203/204mysql-master:192.168.1.231mysql-slave:192.168.1.232

3. install keepalived

The installation steps are the same for mysql-master and mysql-slave machines:

1,: http://www.keepalived.org/software/keepalived-1.2.12.tar.gz

shell>wget http://www.keepalived.org/software/keepalived-1.2.12.tar.gz

2. installation environment

yum -y install openssl-devel

Otherwise, the following error will be reported:

configure: error:!!! OpenSSL is not properly installed on your system. !!!!!! Can not include OpenSSL headers files.

3. Installation

shell>tar -zxvfkeepalived-1.2.12.tar.gzshell>cd keepalived-1.2.12shell>./configure --prefix=/opt/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/shell>make shell>make install

Note:

-- Prefix: Installation Path

-- With-kernel-dir: this is an important parameter. this parameter does not indicate that we want to include Keepalived in the kernel, but the header file in the kernel source code, that is, the include directory.

2.6.32-431. el6.x86 _ 64 can be passed through

Shell> uname-r command to view

4. configuration

# cp /opt/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/# cp /opt/keepalived/etc/sysconfig/keepalived /etc/sysconfig/# mkdir /etc/keepalived# cp /opt/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/# cp /opt/keepalived/sbin/keepalived /usr/sbin/

5. start/stop

shell>service keepalived startshell>service keepalived stopshell>service keepalived restart

4. keepalived configuration

1. mysql-master: 192.168.1.231 configuration

shell>vim /etc/keepalived/keepalived.conf

The configuration is as follows:

Global_defs {router_id mysql-master # Modify to your host name icationication_email {mengtao10@163.com # receive mail, there can be multiple, one line} # When the master, backup device changes, by email notification icationication_email_from lzyangel@126.com # send mail server smtp_server stmp.163.com # send mail timeout time smtp_connect_timeout 30 }##################### the first part # ################# vrrp_instance VI_1 {state BACKUP # both are changed to BACKUPinterface eth0 # bound Nic virtual_router_id 60 # default 51 master/slave change to 60 priority 100 # priority, on mysql-slave, change LVS to 80advert_int 1 nopreempt # Do not preemptible resources, that is, it will not take the master back to authentication {# authentication method after it is active, it can be PASS or AH authentication method auth_type PASS # authentication password auth_pass 1111} virtual_ipaddress {192.168.1.203192.168.1.204 # this can add multiple VIPs }}########### ########################## virtual_server 192.168.1.203 3306 {delay_loop 6lb_algo wrrlb_kind DRnat_mask limit 255.0persistence _ timeout 50 protocol TCPreal_server 192.168.1.231 3306 {weight 1notify_down/root/mysql_down.shTCP_CHECK {connect_timeout 10nb_get_retry 3connect_port 3306 }}}

2. mysql-master: 192.168.1.20.configuration

shell>vim /etc/keepalived/keepalived.conf

The configuration is as follows:

Global_defs {router_id mysql-master # Modify to your host name icationication_email {mengtao10@163.com # receive mail, there can be multiple, one line} # When the master, backup device changes, by email notification icationication_email_from lzyangel@126.com # send mail server smtp_server stmp.163.com # send mail timeout time smtp_connect_timeout 30 }##################### the first part # ################# vrrp_instance VI_1 {state BACKUP # both are changed to BACKUPinterface eth0 # bound Nic virtual_router_id 60 # default 51 master/slave change to 60 priority 80 # priority, on mysql-master, change LVS to 100advert_int 1 authentication {# authentication method, it can be PASS or AH authentication method auth_type PASS # authentication password auth_pass 1111} virtual_ipaddress {192.168.1.203192.168.1.204 # this can add multiple VIPs }}########### ########################## virtual_server 192.168.1.203 3306 {delay_loop 6lb_algo wrrlb_kind DRnat_mask limit 255.0persistence _ timeout 50 protocol TCPreal_server 192.168.1.20.3306 {weight 1notify_down/root/mysql_down.shTCP_CHECK {connect_timeout 10nb_get_retry 3connect_port 3306 }}}

3. configure myslq_down.sh on both servers !!!

Note that the notify_down/root/mysql_down.sh option is the script to be executed when keepalived cannot detect mysql. from the preceding configuration file, the real server only has the local host. Then, if keeaplived is started, the client only accesses mysql on the local machine. Note the nopreempt option. you can configure it on a machine with a higher priority without preemptible resources.
Check the content of this script:

# Vim/root/mysql_down.sh #! /Bin/bashpkill keepalived # chmod + x/root/mysql_down.sh # grant executable permissions

The script contains a command: pkill keepalived. The main function is that if the mysql of the local machine fails, the keepalived of the local machine will be killed at the same time, so that the other one will take over from him, the virtual IP address will also be taken over by another server. if the keepalived virtual IP address is not killed by another server, the mysql access will not be switched over.

Note: you must first start MYSQL and then start keepalived. otherwise, keepalived will run the mysql_down.sh script after startup, which is equivalent to suicide.

4. check the binding status of the IP address after mysql-master (231) is started, as follows:

shell> ip a1: lo: 
 
   mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host  valid_lft forever preferred_lft forever2: eth0: 
  
    mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 08:00:27:cc:92:22 brd ff:ff:ff:ff:ff:ffinet 192.168.1.232/24 brd 192.168.1.255 scope global eth0inet 192.168.1.203/32 scope global eth0inet 192.168.1.204/32 scope global eth0inet6 fe80::a00:27ff:fecc:9222/64 scope link  valid_lft forever preferred_lft forever
  
 

V. test

1. MYSQL and Keepalived are started on machines 231 and 232 at the same time.

Use the client (or program) of the Windows cmd command line to connect to VIP: 192.168.1.203 or 204, as shown below:

C:/Users/Duncan>mysql -h192.168.1.203 -usunney -psunneyWelcome to the MySQL monitor.Commands end with ; or /g.Your MySQL connection id is 1440Server version: 5.5.37-log MySQL Community Server (GPL)Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql|| performance_schema || sunney || test |+--------------------+5 rows in set (0.04 sec)mysql>

Note: the stored database is mysql-master (192.168.1.231) because it is the master database. Configure priority 100 with a high priority.

2. shut down mysql and Keepalived at the same time on the MYSQL-slave (232) machine. at this time, the above is the same. Because he didn't go through this library.

3. mysql-master (231) simultaneously disables MYSQL and Keepalived. mysql-slave (232) simultaneously starts MYSQL and Keepalived

Switching is fast. it may take about 2 to 3 seconds!

Use the client (or program) of the Windows cmd command line to connect to VIP: 192.168.1.203 or 204, as shown below:

C:/Users/Duncan>mysql -h192.168.1.203 -usunney -psunneyWelcome to the MySQL monitor.Commands end with ; or /g.Your MySQL connection id is 1440Server version: 5.5.37-log MySQL Community Server (GPL)Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql|| performance_schema || sunney || test |+--------------------+5 rows in set (0.04 sec)mysql>

Successful!

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.