Nginx + keepalive availability

    
 

First, what is keepalived?
         Keepalived software was originally designed for LVS load balancing software designed to manage and monitor the status of each service node of LVS cluster system, and later joined the VRRP (Virtual Router Redundancy Protocol can achieve high availability, virtual router redundancy protocol) function. Therefore, Keepalived addition to management LVS software, but also can be used as additional services (for example: Nginx, Haproxy, MySQL, etc.) high availability software solutions

Second, how failover?
        Keepalived failover transition between high availability service support is achieved by the VRRP. When Keepalived service work, the main Master node will continue to send to the standby node (multicast mode) heartbeat messages to tell the backup Backup node to be alive when the main Master node fails, it can not send heartbeat messages and backup node will continue to detect the arrival of the heartbeat can not be independent master node, and then calls itself to take over the program, to take over the IP resources and services of the main master node. When the master node recovery Master, prepared Backup node will release the IP resources and services to take over when the primary node fails itself, and restored to its original standby role.

Experimental environment configuration is as follows:

        192.168.1.110:nginx + keepalived   master 主

  192.168.1.111:nginx + keepalived   backup 从

  192.168.1.111:tomcat_8080

  192.168.1.111:tomcat_8081

  Virtual ip (VIP): 192.168.1.200, ip external service provider, may also be referred to as the floating IP, the relationship between the various components are as follows:

 

Third, the installation and configuration
1. Download: https: //pan.baidu.com/s/1G7sLL-YkZGSMu8G76yz1Rw Password: adbw.

2. keepalived installation steps: 192.168.1.110: nginx + keepalived master node:

      2.1 ./configure --prefix=/data/program/keepalived --sysconf=/etc

            ## because keepalive start time will default read /etc/keepalived/keepalived.conf

       2.2. make && make install

3. Modify /etc/keepalived/keepalived.conf profile information

global_defs {             #全局配置
 
    notification_email {
 
        [email protected]  #设置报警邮件地址,可以设置多个,每行一个。需要开启sendmail服务。
 
    }
 
    notification_email_from [email protected]
 
    smtp_server smtp.hysec.com   #设置SMTP Server地址
 
    smtp_connection_timeout 30   #设置SMTP Server的超时时间
 
    router_id nginx_master       #表示运行Keepalived服务器的一个标识,唯一的
 
}
 
vrrp_script chk_http_port {
 
    script "/usr/local/src/check_nginx_pid.sh" #心跳执行的脚本
 
    interval 2                          #(检测脚本执行的间隔,单位是秒)
 
    weight 2
 
}
 
vrrp_instance VI_1 {        #vrrp 实例定义部分
 
    state MASTER            # 指定keepalived的角色,MASTER为主,BACKUP为备
 
    interface ens33         # 当前进行vrrp通讯的网络接口卡(当前centos的网卡)
 
    virtual_router_id 66    # 虚拟路由编号,主从要一直
 
    priority 100            # 优先级,数值越大,获取处理请求的优先级越高
 
    advert_int 1            # 检查间隔,默认为1s(vrrp组播周期秒数)
 
    authentication {
 
        auth_type PASS #设置验证类型和密码,MASTER和BACKUP必须使用相同的密码才能正常通信
 
        auth_pass 1111
 
    }
 
    track_script {
 
        chk_http_port            #(调用检测脚本)
 
    }
 
    virtual_ipaddress {
 
        192.168.1.200            # 定义虚拟ip(VIP),可多设,每行一个
 
    }
 
}


The master node configuration above, from the same node and master node configuration backup, but we wanted to change state backup, priority value than a small point to master

 

四、启动keepalived
           /data/program/keepalived/sbin/keepalived

 Boot sequence:

1. Start tomcat8080 192.168.1.111 on the server and tomcat8081

2. Start Master Keepalived node of 192.168.1.110, sh script will be executed automatically and start Nginx

3. Start Backup 192.168.1.111 of Keepalived node, sh script will be executed automatically and start Nginx

Note: do not need to manually start Nginx

4. Check keepalived log: tail -f / var / log / messages

Five, KEEPLIVED from the main fault testing
    1. After two Keepalied + Nginx applications started successfully, using VIP load balancing access to two Tomcat

    2. Stop Nginx application 192.168.1.110 master node, Nginx observation state, and access the Tomcat;

    3. Stop 192.168.1.110 master node application Keepalived observed log / var / log / messages, and access tomcat

    4. Observe 1.111 from the log node role to change the situation.
 

Guess you like

Origin blog.csdn.net/m0_37450089/article/details/88879631