keeplived Configuration Nginx Dual Machine High Availability

Source: Internet
Author: User

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

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.