Nginx + keepalive HA

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

nginx + Keepalive - Zhuzhu - five. Nine Si (Dalian Linux host maintenance)

A topological environment:

The main nginx 192.168.166.203 load balance
Auxiliary nginx load balancer 192.168.166.177
The VIP address 192.168.166.178


tar -zxvf keepalived-1.2.1.tar.gz
cd keepalived-1.2.1
./configure --prefix=/usr/local/keepalived --sysconf=/etc
make && make install

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 /bin/
chkconfig --add keepalived
chmod 755 /etc/init.d/keepalived
chkconfig keepalived on
service keepalived start

Two. Modify the configuration file for the following: [master slave]
MASTER
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {

}
notification_email_from
smtp_server xxx.smtp.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script Monitor_Nginx {
script "/root/monitor_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER #(host MASTER, the standby machine for BACKUP)
interface eth0 #(HA monitoring network interface)

virtual_router_id 61 #(the main production machine, virtual_router_id must be the same)
#mcast_src_ip 192.168.166.203 #(multicast source IP, set the machine outside the IP network, and VIP the same card) this can not set
priority 90 #(the main production machine, different priority, the host value large, backup machine value value smaller, more higher priority)
advert_int 1 #(VRRP Multicast broadcast cycle number of seconds)
authentication {
auth_type PASS #(VRRP certification)
auth_pass 1234 #Cipher.
}

track_script {
Monitor_Nginx #(call nginx process detection script)
}
virtual_ipaddress {
192.168.166.178 #(VRRP HA virtual address)
}
}

###BACKUP only need to modify the state to BACKUP, priority is smaller than that of MASTER OK

Three: Note: monitor_nginx.sh is the process of monitoring nginx script, as follows
#!/bin/bash
if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]
then
/usr/local/nginx/sbin/nginx
sleep 5
if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]
then
killall keepalived
fi
fi
#chmod +x monitor_nginx.sh

Start keepalived four
service keepalived start
Or
/usr/local/keepalived/sbin/keepalived -D -f /etc/keepalived/keepalived.conf

Test step five
1. Visit VIP to see whether can normal visit back to Web
2. Stop one of the web and see if I can access to another table
3. Stop any nginx process two nginx, see monitoring process is the script will automatically start the nginx
4. Stop any nginx keepalived process on another station is over VIP

Track_interface means the Linux network interface card you want to monitor the monitoring, when there is a failure in one of the keepalived will be regarded as a router failure.
Please note: virtual_router_id 61, the same group of master/backup, that is if you have multiple VRRP, the same group of the ID must be the same, or start the master-slave will give the VIP to start
Survival of keepalived multicast reception with an virtual_router_id packet is sent via the and in the member, to determine each other is not available, once detected, each other is not available, which will switch its backup role.
That is when the real machine: keepalived 192.168.166.177 detected on keepalived real machine on 192.168.166.203 is not available, 177, using the vip:192.168.166.178 service and transformed by backup master role




keepalived+Nginx HA and load balance in keepalived to realize HA function, control of VIP (virtual network address) transfer function, nginx implementation of the RealServer seven layer load balance function, nginx provides agency services and cache functions, DNS load balancing service can be responsible for some VIP.

nginx + Keepalive - Zhuzhu - five. Nine Si (Dalian Linux host maintenance)

The keepalived configuration
192.168.200.1 keepalived configuration
! Configuration File for keepalived

global_defs {
notification_email {

}
notification_email_from
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_TEST_YDQ
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 61
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.200.101/24 dev eth0 label eth0:0
}
}

vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 62
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.200.102/24 dev eth0 label eth0:1
}
}


vrrp_instance VI_3 {
state BACKUP
interface eth0
virtual_router_id 63
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 3333
}
virtual_ipaddress {
192.168.200.103/24 dev eth0 label eth0:1
}
}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Mick at March 06, 2014 - 3:50 PM