Nginx + Keepalived hot standby

Based Nginx and Keepalived Hot Standby

Keepalived achieve hot standby, a machine eliminate the occurrence of single point of failure. Prepare two machines were 192.168.163.34,192.168.163.35 ip address. At the same time these two machines are set to the same virtual ip,
where ip virtual machines are set to 192.168.163.100.2 need to install nginx and keepalived.

Set the virtual ip

Here to use virtual ip, ip settings for virtual reference .

Installation and start nginx

install nginx

##### 192.168.163.34 start

192.168.163.35 start

Installation Keepalived

tar –zxvf keepalived-1.2.19.tar.gz
cd keepalived-1.2.19
./configure --prefix=/usr/local/keepalived
make
make install

keepalived.conf configuration (192.168.163.34)

! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVELA #MASTER节点
}

vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 51 #主、备必须一样  
    priority 100 #优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.163.100 #VRRP HA虚拟地址
    }
}

keepalived.conf configuration (192.168.163.35)

! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVELB #BACKUP节点
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 51 #主、备必须一样  
    priority 99#优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.163.100 #VRRP HA虚拟地址
    }
}

Softlinks and start keepalived

ln -s /usr/local/keepalived/sbin/keepalived /sbin/
ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf

test

Test visible, the browser we accessed via a virtual ip, as above, the set will have access to the machine master 34. 34 priority than the machine 35.

Disable master machine

Disable master machine (down, nginx crashes, etc.) will automatically switch to see that machine 35 backup. That is 192.168.163.34 that machine can not access.

reference

nginx-ha-keepalived
keepalived

Published 58 original articles · won praise 9 · views 70000 +

Guess you like

Origin blog.csdn.net/rui888/article/details/103668508