Keepalived Configuration and Usage

Keepalived provides health checks for RealServers and failover between LoadBalance hosts.keepalived to in , a service , can implement in node or node , and can in ipvshas node node , node node Master/Backup.

 

VRRP (easily understood if you know TCP/IP):

(VRRP) is , can a to VRRP . IP Address VRRP , data to these IP Address. not can , process provide , IP Addresscan . use VRRP is has can in each configuration or . VRRP in IP .

 

VRRP:

	VRRPeach node is has   , is from 0-255 , can : 	 to has  status , node 100 node 99, ,  is node all  node all is backupstatus , via  method master, if node no will master	: 	if between nodes master, , we  manage already keepalivedsupport , if status   can via method manage , manage can view status ,  

 

keepalivedpart

  1. vrrp implement
  2. virtual_server: vrrp
  3. vrrp_script:method perform

 

keepalived

keepalived

 

KeepAlived Installation:

[root@Nginx-one ~]# tar zxf keepalived-1.2.13.tar.gz [root@Nginx-one ~]# cd keepalived-1.2.13[root@Nginx-one keepalived-1.2.13]# yum install kernel-devel openssl-devel libnl-devel[root@Nginx-one keepalived-1.2.13]# ./configure --prefix=/ --mandir=/usr/local/share/man/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/[root@Nginx-one keepalived-1.2.13]# make && make installKeepalived configuration------------------------Keepalived version       : 1.2.13			##version#Compiler                 : gcc				##tool ##Compiler flags           : -g -O2			####Extra Lib                : -lssl -lcrypto -lcrypt 	####Use IPVS Framework       : Yes				##LVS, not use LVScan disable-lvs##IPVS sync daemon support : Yes				##IPVS, is  IPVS FRAMEWORK###IPVS use libnl           : Yes				##is use libnl##fwmark socket support    : Yes				####Use VRRP Framework       : Yes				##VRRP, keepalived vrrpd##Use VRRP VMAC            : Yes				##VRRP Virtual mac##SNMP support             : NoSHA1 support             : NoUse Debug flags          : No[root@Nginx-one keepalived-1.2.13]# make && make install

 

KeepAlived all configuration all in a configuration file setting , support configuration can the following :

	1, configuration  (global configure) 	2, VRRPDconfiguration 	3, LVSconfiguration 	, configuration is for keepalived configuration , not is use LVS, VRRPDis keepalived , LVSconfiguration in  to use keepalivedconfiguration  and manage LVSuse , if use keepalivedHA, LVSnot need configuration . 	configuration file all is  (block)  , each all in {}, # and !. 

 

(global definition)

global_defs {   notification_email {		##keepalivedin  () need Email for , ##     itchenyi@gmail.com   }   notification_email_from itchenyi@gmail.com   smtp_server 127.0.0.1		##SMTPserver ##   smtp_connect_timeout 30		####   router_id Nginx-one			##, ##}

 

VRRPDconfiguration (VRRP (syncchroization group) and VRRP (VRRP instance) )

not use SYNC Group , if has 2, a , a , each a VRRP, VRRPconfiguration , Issues , VRRPDis , not Master and Backup , from Issues, Sync Groupcan all Sync Group, , Group a Issuesall .

vrrp_instance VI_1 { ####state MASTER ##status , , can Master , Master##interface eth1 ##via ##virtual_router_id 10 ## ID, not 255, can IPuse ##priority 100 ##, process  ,  and  ##advert_int 1 ##, 1s##authentication { ####auth_type PASS ##method , PASS##auth_pass ipython ####}virtual_ipaddress { ##Address##1.1.1.100}}### configuration  ###

 

configuration Backup configuration :

[root@nginx-two keepalived-1.2.13]# cat /software/keepalived/etc/keepalived/keepalived.conf ! Configuration File for keepalivedglobal_defs {   notification_email {     itchenyi@gmail.com   }   notification_email_from itchenyi@gmail.com   smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id nginx-two}vrrp_instance VI_1 {    state BACKUP    interface eth1    virtual_router_id 20    priority 50    advert_int 1    authentication {        auth_type PASS        auth_pass ipython    }    virtual_ipaddress {        1.1.1.100    }}###configuration : ####	nopreempt setting not , this configuration  can setting in stateBACKUP node , and this  	preempt_delay , 5	debug debug	notify_master to Master Script##start##[root@Nginx-one keepalived-1.2.13]# service keepalived startStarting keepalived:                                       [  OK  ]###file ###[root@Nginx-one keepalived-1.2.13]# tail -f /var/log/messages Aug  3 00:02:12 Nginx-one Keepalived[8177]: Starting Keepalived v1.2.13 (08/03,2014)Aug  3 00:02:12 Nginx-one Keepalived[8178]: Starting Healthcheck child process, pid=8180Aug  3 00:02:12 Nginx-one Keepalived[8178]: Starting VRRP child process, pid=8181#### IPAddress####Aug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Netlink reflector reports IP 1.1.1.10 addedAug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Netlink reflector reports IP fe80::20c:29ff:fecb:90a2 addedAug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Registering Kernel netlink reflectorAug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Registering Kernel netlink command channelAug  3 00:02:13 Nginx-one Keepalived_healthcheckers[8180]: Netlink reflector reports IP 1.1.1.10 addedAug  3 00:02:13 Nginx-one Keepalived_healthcheckers[8180]: Netlink reflector reports IP fe80::20c:29ff:fecb:90a2 addedAug  3 00:02:13 Nginx-one Keepalived_healthcheckers[8180]: Registering Kernel netlink reflectorAug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Registering gratuitous ARP shared channelAug  3 00:02:13 Nginx-one Keepalived_healthcheckers[8180]: Registering Kernel netlink command channelAug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Opening file '/etc/keepalived/keepalived.conf'.Aug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Configuration is using : 62834 BytesAug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: Using LinkWatch kernel netlink reflector...Aug  3 00:02:13 Nginx-one Keepalived_vrrp[8181]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]###configuration file ####Aug  3 00:02:13 Nginx-one Keepalived_healthcheckers[8180]: Opening file '/etc/keepalived/keepalived.conf'.Aug  3 00:02:13 Nginx-one Keepalived_healthcheckers[8180]: Configuration is using : 7377 BytesAug  3 00:02:13 Nginx-one Keepalived_healthcheckers[8180]: Using LinkWatch kernel netlink reflector...####Master status ####Aug  3 00:02:14 Nginx-one Keepalived_vrrp[8181]: VRRP_Instance(VI_1) Transition to MASTER STATEAug  3 00:02:15 Nginx-one Keepalived_vrrp[8181]: VRRP_Instance(VI_1) Entering MASTER STATEAug  3 00:02:15 Nginx-one Keepalived_vrrp[8181]: VRRP_Instance(VI_1) setting protocol VIPs.####in VIP###Aug  3 00:02:15 Nginx-one Keepalived_vrrp[8181]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 1.1.1.100Aug  3 00:02:15 Nginx-one Keepalived_healthcheckers[8180]: Netlink reflector reports IP 1.1.1.100 addedAug  3 00:02:20 Nginx-one Keepalived_vrrp[8181]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 1.1.1.100###view is VIP###[root@Nginx-one keepalived-1.2.13]# ip a show|awk '/inet/ /'    inet 127.0.0.1/8 scope host lo    inet 1.1.1.10/8 brd 1.255.255.255 scope global eth1    inet 1.1.1.100/32 scope global eth1StopMASTER, view BACKUP status [root@Nginx-one keepalived-1.2.13]# service keepalived stopStopping keepalived:                                       [  OK  ][root@nginx-two keepalived-1.2.13]# tail -f /var/log/messages Aug  3 00:05:01 nginx-two Keepalived_vrrp[5148]: Using LinkWatch kernel netlink reflector...Aug  3 00:05:01 nginx-two Keepalived_vrrp[5148]: VRRP_Instance(VI_1) Entering BACKUP STATEAug  3 00:05:01 nginx-two Keepalived_healthcheckers[5147]: Using LinkWatch kernel netlink reflector...Aug  3 00:05:01 nginx-two Keepalived_vrrp[5148]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]Aug  3 00:05:40 nginx-two Keepalived_vrrp[5148]: VRRP_Instance(VI_1) Transition to MASTER STATEAug  3 00:05:41 nginx-two Keepalived_vrrp[5148]: VRRP_Instance(VI_1) Entering MASTER STATEAug  3 00:05:41 nginx-two Keepalived_vrrp[5148]: VRRP_Instance(VI_1) setting protocol VIPs.Aug  3 00:05:41 nginx-two Keepalived_healthcheckers[5147]: Netlink reflector reports IP 1.1.1.100 addedAug  3 00:05:41 nginx-two Keepalived_vrrp[5148]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 1.1.1.100Aug  3 00:05:46 nginx-two Keepalived_vrrp[5148]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 1.1.1.100#### and , MASTERto VIP, can  to , Keepalivedsupport , has BACKUPin MASTER, VIP, ####

 

Keepalived

### nginx is in ###[root@nginx-two ~]# cat nginx_check.sh #!/bin/bashalive=`netstat -pant|awk '/0.0.0.0:80/&&/LISTEN/'|wc -l`if [ $alive -eq 1 ]; then    exit 0else    exit 1fi###keepalivedconfiguration ###vrrp_script nginx_check{    script "/root/nginx_check.sh"    interval 1		### 1s###    weigh -60		###if , -60###}####will track_scriptinstance configuration ####    track_script    {        nginx_check    }[root@Nginx-one ~]# service keepalived restartStopping keepalived:                                       [  OK  ]Starting keepalived:                                       [  OK  ]###,  to nginx  80is  , is ###[root@Nginx-one ~]# ip a show|awk '/inet/ /'    inet 127.0.0.1/8 scope host lo    inet 1.1.1.10/8 brd 1.255.255.255 scope global eth1    inet 1.1.1.100/32 scope global eth1###Nginxservice ###[root@Nginx-one ~]# service nginx stopStopping nginx:                                            [  OK  ]Aug  3 00:52:13 Nginx-one Keepalived_vrrp[8490]: VRRP_Script(nginx_check) failedAug  3 00:52:14 Nginx-one Keepalived_vrrp[8490]: VRRP_Instance(VI_1) Entering FAULT STATEAug  3 00:52:14 Nginx-one Keepalived_vrrp[8490]: VRRP_Instance(VI_1) removing protocol VIPs.Aug  3 00:52:14 Nginx-one Keepalived_vrrp[8490]: VRRP_Instance(VI_1) Now in FAULT stateAug  3 00:52:14 Nginx-one Keepalived_healthcheckers[8489]: Netlink reflector reports IP 1.1.1.100 removed###BackupMaster###[root@nginx-two ~]# ip a show|awk '/inet/ /'    inet 127.0.0.1/8 scope host lo    inet 1.1.1.20/8 brd 1.255.255.255 scope global eth1    inet 1.1.1.100/32 scope global eth1

 
Original http://www.ipython.me/centos/keepalived-config-using.html

 

Leave a Comment

Your email address will not be published.