MySQL-----HA (keepalived article)

Source: Internet
Author: User
Tags chmod pkill

5.21 DB-01

5.22 DB-02

5.24 Virtual IP (cannot be the actual IP) + + Select VIP


Keepalived Installation and Configuration

Installing keepalived

On the 5.21:

wget 650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/ Zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>http:// Www.keepalived.org/software/keepalived-1.2.13.tar.gz

Tar-xvzf keepalived-1.2.13.tar.gz

CD keepalived-1.2.13
./configure--prefix=/usr/local/keepadlived--sysconf=/etc
Make
Make install


Configure keepalived

Vim/etc/keepalived/keepalived.conf


! Configuration File for Keepalived

2

3 Global_defs {

4 Notification_email {

5 [email protected]

6}

7 Notification_email_from [email protected]

8 Smtp_server 127.0.0.1

9 Smtp_connect_timeout 30

Ten router_id Mysql-ha

11}

12

Vrrp_instance Vi_1 {

State BACKUP ++++ #两台配置此处均是BACKUP

Interface eth0 +++++# native NIC

51 virtual_router_id

+++++ #优先级, another 90

1 Advert_int

Nopreempt +++++ #不抢占, high-priority configuration only, low configuration

Authentication {

Auth_type PASS

Auth_pass 1111

23}

virtual_ipaddress {

192.168.5.24 ++++++ #虚拟ip地址

26}

27}

28

Virtual_server 192.168.5.24 3306 {++++++ #虚拟ip下的服务端口

Delay_loop 3 +++++ #每隔3秒检查一次real_server状态

Lb_algo WRR +++++ #LVS算法

Lb_kind DR +++++ #LVS模式

Nat_mask 255.255.255.0

Persistence_timeout ++++ #会话保持时间

Protocol TCP

36

PNS Real_server 192.168.5.21 3306 {++++ #检查需要单节点的主机服务端口

3 Weight

notify_down/usr/local/mysql/bin/mysql.sh

Tcp_check {

Connect_timeout 3 ++++ Link time-out

Nb_get_retry 3 re-connect times

Delay_before_retry 3 re-connect interval time

Connect_port 3306 # #健康检查端口

45}

46}

47}


Script to execute after writing detection service down

vim/usr/local/mysql/bin/mysql.sh

#!/bin/sh

Pkill keepalived


# chmod a+x/usr/local/mysql/bin/mysql.sh

#/usr/local/keepalived/sbin/keepalived-d//Start keepalived Service

# PS-EF |grep keepalived//view keepalived process


Note: This script is used by the configuration file Notify_down option above, Keepalived uses the Notify_down option to check the service status of Real_server and fires this script when a Real_server service failure is found. Deleted its own process (Pkill keepalived), thus realizing automatic MySQL failover


Each keepalived provides VIP + real_server IP When real_server failure occurs, keepalived kills its own process, another keepalived get others shout VIP, take over, realize ha


Test:

Find a LAN pc,ping mysql VIP (5.24), this time can be ping through the

Stop the MySQL service and see if the keepalived health check will trigger the script we wrote to see if the keepalived process exists




Second 5.22 installation keepalived and configuration

# TAR-XVZF Keepalived-1.2.13.tar.gz

# CD keepalived-1.2.13

#./configure--prefix=/usr/local/keepalived--sysconf=/etc/&& make && make install


Configure keepalived

This configuration is the same as the above basic, there are three different places: Priority 90, no preemption settings (#nopreempt), real_server for native IP

Vim/etc/keepalived/keepalived.conf

! Configuration File for Keepalived


Global_defs {

Notification_email {

[Email protected]

}

Notification_email_from [email protected]

Smtp_server 127.0.0.1

Smtp_connect_timeout 30

router_id mysql-ha

}


Vrrp_instance Vi_1 {

State BACKUP

Interface Eth1 # #因为5.22 The NIC is eth1, so adjust the

VIRTUAL_ROUTER_ID 51

Priority # #优先级为90

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

virtual_ipaddress {

192.168.5.24 # #设置虚拟vip

}

}


Virtual_server 192.168.5.24 3306 {

Delay_loop 3

Lb_algo WRR

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP


Real_server 192.168.5.22 3306 {# #real_server为本机的ip地址

Weight 3

notify_down/usr/local/mysql/bin/mysql.sh

Tcp_check {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 3306

}

}

}


Script to be used after writing the detection service down

# vim/usr/local/mysql/bin/mysql.sh

#!/bin/sh

Pkill keepalived

#chmod a+x/usr/local/mysql/bin/mysql.sh


Start keepalived

#/usr/local/keepalived/sbin/keepalived-d

# ps-elf |grep keepalived


Test:

Stop the MySQL service to see if the keepalived Health Check program will trigger the script we wrote


Three- test

MySQL telnet test

Allow remote logins on two (5.21 and 5.22) separate licenses

Mysql>grant all privileges on * * to ' root ' @ '% ' identified by ' 123456 ';

Mysql>flush privileges;


Log on remotely using a client

Mysql-uroot-p123456-h192.168.5.24-p 3306

Mysql>

Mysql>


Can log in


Put two hosts on the service: MySQL all started keepalived also started

IP a view VIP on 5.22

1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN

Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00

inet 127.0.0.1/8 Scope host Lo

INET6:: 1/128 Scope Host

Valid_lft Forever Preferred_lft Forever

2:eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 52:54:00:2c:54:7b BRD FF:FF:FF:FF:FF:FF

inet 192.168.5.22/24 BRD 192.168.5.255 Scope Global eth1

((((((((((((((inet 192.168.5.24/32 scope Global eth1))) # #虚ip

Inet6 FE80::5054:FF:FE2C:547B/64 Scope link

Valid_lft Forever Preferred_lft Forever


Mysql>show Master status; # #也可以查看vip在哪台机器上


Stop 5.22 on the mysqld,keepalived will also be turned off, we ping 192.168.5.24 on 5.23 to see if we can ping through,

Normal is can pass, with mysql-uroot-p123456-h 192.168.5.24-p 3306, Normal is can log on, log on to 5.21. At this time VIP on 5.21, we restart 5.22 on the mysqld and Keepalived,ps-ef|grep keepalived stop 5.21 mysqld, then keepalived also stopped, VIP to 5.22, Log in with MySQL to view show master status;


Note: State backup two status is backup

High priority setting Nopreempt (no preemption)

VIP is not snatched from a low priority server when the high priority restores the running state



















MySQL-----HA (keepalived article)

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.