KeepAlived (III): keepalived + haproxy, and keepalivedvrrp

Source: Internet
Author: User
Tags haproxy

KeepAlived (III): keepalived + haproxy, and keepalivedvrrp

Configuration items when keepalived uses scripts for health check. For example, keepalived + haproxy achieves high availability of haproxy.

Keepalived is divided into vrrp instance heartbeat check and backend service health check. To configure a backend service, the backend service can only be LVS. However, vrrp can exist independently with lvs. For example, keepalive can work with services such as haproxy and mysql to achieve high availability.

The following is fromman keepalivedRelated configuration options for heartbeat check and health check by script.

VRRP script (s) # define a vrrp script. When a script is executed in a vrrp group or vrrp instance, it must be referenced here # Note, all vrrp instances monitor the script exit code vrrp_script <SCRIPT_NAME> {script <STRING> | <QUOTED-STRING> # the command to be executed or the script Path interval <INTEGER> # script call time interval, the default 1-second timeout <INTEGER> # script execution wait time-out period. If the timeout period is exceeded, the script execution fails. weight <INTEGER:-254 .. 254> # adjust the priority value of a vrrp instance based on the weight value. The default value is 0 rise <INTEGER> # How many successful attempts are required, vrrp performs role status switching fall <INTEGER> # number of failures, and vrrp performs role status switching. user USERNAME [GROUPNAME] # script Execution identity. The group is by default the same as username init_fail # assume that the script is in the failed State during initialization} VRRP synchronization group (s) # indicates Master/Slave/error respectively (for example, the monitored eth0 is broken). # When you want to pass parameters for the script, enclose the entire script and parameter yy_master/path/to_master.sh [username [groupname] notify_backup/path/to_backup.sh [username [groupname] notify_fault "/path/fault with quotation marks. sh VG_1 "[username [groupname] # Running y indicates the script that will be called as long as the status switch is complete. The script is called after the preceding three scripts are executed, # keepalived will automatically pass four parameters, so do not manually PASS Parameters for the script. #$1 = "GROUP" | "INSTANCE" #$2 = vrrp GROUP name or vrrp INSTANCE name #$3 = switching target status (MASTER/BACKUP/FAULT) #$4 = priority value notify/path/notify. sh [username [groupname] VRRP instance (s) part # monitoring interface. When an interface is down, switch to the fault status track_interface {eth0 eth1 eth2 weight <-254 .. 254> ...} # monitoring Script: Execute the script track_script defined by vrrp_script {<SCRIPT_NAME> weight <-254 .. 254 >}# yy_master/backup/fault/stop respectively indicate master switch, slave, Error (for example, monitored eth0 is broken), script executed when vrrp is stopped # When parameters are to be passed to the script, enclose the entire script and parameter policy_master with quotation marks <STRING >|< QUOTED-STRING> [username [groupname] policy_backup <STRING >|< QUOTED-STRING> [username [groupname] policy_fault <STRING> | <QUOTED-STRING> [username [groupname] yy_stop <STRING> | <QUOTED-STRING> [username [groupname] # executed when stopping vrrp # required y indicates that scripts called during status Switching, in addition, this script is called after the preceding three scripts are executed <STRING> | <QUOTED -STRING> [username [groupname] Virtual server (s) part # script quorum_up <STRING> | <QUOTED-STRING> quorum_down <STRING> | <QUOTED-STRING> real_server <IPADDR> <PORT> {# script yy_up <STRING >|< QUOTED-STRING> policy_down <STRING >|< QUOTED-STRING> # MISC Health Check type, this type uses a custom Script to check the backend health status MISC_CHECK {# Which Script is executed to determine whether the backend is healthy misc_path <STRING >|< QUOTED-STRING> # Script execution timeout misc_t Imeout <INT> # specify a random delay time to prevent all backend servers from being checked at the same time. If it is set to 0, this function is disabled. # This function is enabled by default. The default maximum interval is the value of delay_loop. Warmup <INT> # If this option is specified, the weight is dynamically adjusted based on the exit status code of the Health Check script # The exit status code is: #0, indicating that the check is successful, do not modify any weight #1: Check failed #2-255: Check successful, but the weight is reduced by 2. For example, if the status code is 255, set the weight to 253) misc_dynamic # specify the identity for running the backend health check script. If no group is specified, username user USERNAME [GROUPNAME] will be used by default}

For example, in keepalived + haproxy.

vrrp_script check_haproxy {        script"/etc/keepalived/chk_haproxy.sh"        interval 2        weight 2    }global_defs {        router_id haproxy1    }vrrp_instanceVI_1 {        state MASTER        interface eth0        virtual_router_id 150        priority 50        advert_int 1        authentication {            auth_type PASS            auth_pass 1111        }virtual_ipaddress{        192.168.1.201    }track_script {        check_haproxy    }}

The script/etc/keepalived/chk_haproxy.sh of check_haproxy is as follows:

#!/bin/bashif killall -0 haproxy &>/dev/null;then    serivce haproxy restart    sleep 1    if killall -0 haproxy &>/dev/null;then        service keepalived stop    fifi

 

Back to Linux series article outline: http://www.cnblogs.com/f-ck-need-u/p/7048359.html
Back to website architecture series article outline: http://www.cnblogs.com/f-ck-need-u/p/7576137.html
Back to database series article outline: http://www.cnblogs.com/f-ck-need-u/p/7586194.html
Reprinted please indicate the source: http://www.cnblogs.com/f-ck-need-u/p/8566233.html

Note: If you think this article is not bad, please click the recommendation in the lower right corner. Your support can stimulate the author's enthusiasm for writing. Thank you very much!

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.