lvs + keepalived build dual-master-slave architecture

安装nginx:
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

Nginx ensure normal access to:

I'm here now 129 146 as follows:

 

 

 

 

 

 

 

安装keepalived:
1.安装基础必备包.
yum install popt-devel
2. 编译.
tar -zxvf keepalived-1.2.15.tar.gz -C /usr/local/
cd keepalived-1.2.15/ && ./configure --prefix=/usr/local/keepalived
make && make install

3.配置相关文件
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/sbin/keepalived /usr/sbin/
LN -s / usr / local / keepalived / sbin / keepalived / sbin / 
4 . 
vim / etc / keepalived / keepalived.conf
 
Master: 

vrrp_script chk_nginx { 
    Script "/etc/keepalived/nginx_check.sh" # run the script, the script content below there is a play nginx down after automatic opening service 
    interval the 2 # detection interval 
    weight -20 # If the conditions are satisfied, then the weights -20 
} 
# define virtual routing, VI_1 virtual route identifier, define their own name 
{VI_1 vrrp_instance State to determine the master from the mASTER #
     
   interface virtual IP network interface eth0 # binding, according to their fill machine 
    virtual_router_id 121 # virtual routing ID, must be provided as two nodes 
    mcast_src_ip 192.168.139.129  # fill local ip
    priority 100 # node priority, mainly from the node higher priority than 
    nopreempt high priority setting # nopreempt solve the problem again after recovery from the abnormality seize the 
    advert_int 1 # multicast transmission interval, two nodes must be set as the default 1S 
    authentication { 
        PASS AUTH_TYPE 
        AUTH_PASS 1111 
    } 
    # track_script block will join instance configuration block 
    track_script { 
        chk_nginx # Nginx execution monitoring service 
    } 

    virtual_ipaddress { 
        192.168.139.110 # virtual ip, ip how to solve that is to write a program ip dead switching can also be extended, Wide range of uses. You can configure multiple top three must be consistent with the server. 
    } 
} 

Service keepalived Start start without error keepalived successful installation:

 

 

 

Backup: 

vrrp_script chk_nginx { 
    Script "/etc/keepalived/nginx_check.sh" # run the script, the script has the following content is played down after a nginx automatically open service 
    interval 2 # detection interval 
    weight -20 # If the conditions are satisfied , then the weight of -20 
} 
# define virtual routing, VI_1 virtual route identifier himself define the name 
vrrp_instance VI_1 { State the BACKUP # to determine the master from the 
    virtual IP network interface interface eth2 # binding, filled according to their own machine 
    virtual_router_id # 121 virtual routing ID number, set up two nodes must be the same 
    mcast_src_ip 192.168.139.129 # fill the machine ip 
    priority # 100 node priority, mainly from the node higher priority than 
    nopreempt high priority setting # nopreempt resolved abnormal recovery again preemption problem 
    advert_int 1 # multicast transmission interval, two nodes must be set as the default lS 
    authentication { 
        AUTH_TYPE the PASS 
        AUTH_PASS 1111 
    }
    
    # Join the track_script block instance configuration block
    {track_script 
        chk_nginx # Nginx execution monitoring service 
    } 

    virtual_ipaddress { 192.168.139.110 # virtual ip, ip how to solve that is to write a program ip dead switch, but also scalable, and versatile. You can configure multiple top three must be consistent with the server. 
    } 
} 
Keepalived common command 
-Service keepalived Start 
-Service keepalived STOP 
1. achieve the effect of access to the master node nginx virtual access configuration by vip ip
       

 

 

 

Master node from the node without vip ip 110

  

 

 

 

 

 

3: Restart the primary site can be seen vip ip need to wait a few seconds

  

 

 

 

 

Double-point main completed structures (a master-slave nginx) from the hot spare architecture 

longer access Tomcat cluster actually made by vip ip access nginx nginx keeplived generated

  

 

Guess you like

Origin www.cnblogs.com/coderdxj/p/12301433.html