First, Introduction
whether it is keepalived or heartbeat do high availability, its high availability, are standing in the server script to say the high availability, rather than the angle of the service.
In other words, if the server down or network failure, high availability can be achieved automatically switch. If the service is running, such as nginx hanging off
These high-availability software is not aware of, need to write their own scripts to implement the service switch.
Second, installation configuration keepalived
# ./configure# make# make install# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/# cp / usr/local/sbin/keepalived /usr/bin/# chkconfig --add keepalived # mkdir / etc/keepalived/# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/# vim / etc/keepalived/keepalived.conf! configuration file for keepalivedglobal_defs { router_id lvs_devel} vrrp_script chk_nginx { script "/opt/monnginx.sh" interval 2 weight 2} vrrp_instance vi_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass mdnginx } virtual_ipaddress { 1.1.1.100 } track_script { chk_nginx &NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP: Edit BACKUP's Master profile (backup:1.1.1.2) # vim /etc/keepalived/ keepalived.conf! configuration file for keepalivedglobal_defs { router_id lvs_devel} vrrp_script chk_nginx { script "/opt/monnginx.sh" interval 2 weight 2 } vrrp_instance vi_1 { state backup interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass mdnginx } virtual_ipaddress { 1.1.1.100 } track_script { chk_nginx } third, start service and scripting (both host and standby are executed) # service nginx start# Service keepalived start write a script to monitor Nginx # vim /opt/monnginx.sh#!/bin/bash# author: hujianli# date: 2013-03-15if [ $ (ps -c nginx --no-header | wc -l) -eq 0 ]; then service nginx start fi sleep 3 if [ $ (ps -c nginx --no-header | &NBSP;WC&NBSP;-L) -eq 0 ]; then service keepalived stop fi improved script, plus alarm function. # vim /opt/monnginx.sh#!/bin/bash# author: hujianli# date: 2013-03-15ipaddr=$ (IP addr show eth0|awk ' {print $2} ' | sed -n 3p) contact= ([email protected]) num=${#contact [@]}function email () {for ((i=0;i<num;i++));d o echo "$IPADDR service problem" | mail -s "WARNING" ${contact[i]} -- -f [email protected] done} if [ $ (ps -c nginx --no-header | wc -l) -eq 0 ]; then service nginx start fi email sleep 3if [ $ (ps -c nginx --no-header | &NBSP;WC&NBSP;-L) -eq 0 ]; then service keepalived stopemailfi
This article from the "heartbroken people in the Tianya" blog, please be sure to keep this source http://8649605.blog.51cto.com/8639605/1710470
keeplived Configuration Nginx Dual Machine High Availability