Keepalived build under linux

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43687990/article/details/102468129

keepalived is the cluster management to ensure high availability cluster service software, the Available High Availability High
1. needs heartbeat mechanism to detect whether the back-end RS to provide services.
a) detecting down, it needs to be removed from the RS in lvs
B) sent from the probe down to up, again from the RS to add the lvs.
2.Lvs DR, require standby
keepalived principle:
VRRP protocol (Virtual Router Redundancy Protocol) - Virtual Router Redundancy Protocol
IP drift?
With keepalived premise: the need for several RS (real back-end server), a master of load balancing lvs server, a backup server lvs using a virtual machine alternative, namely to prepare several virtual machines node1, node2, node3, Node4
node1-based lvs
node2 and node3 for the RS,
Node4 to spare lvs
RS mix in another article has been said, it is not explained here, the following is mainly talk about the configuration keepalived under standby lvs

First
download keepalived in node1 and node4, ipvsadm can be installed or may not be installed

yum install keepalived

Edit / etc / keepalived.conf keepalived files in the directory, you first need to copy.

cp keepalived.conf keepalived.conf.bak

Enter the edit page, and edit

! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected] #发送提醒邮件的目标地址,可以有多个
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]   #发送邮件的from地址,可以随意写,邮件地址无所谓
   smtp_server 127.0.0.1  #邮件服务地址,一般写本地
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

#虚拟路由冗余协议vrrp的配置
vrrp_instance VI_1 {
    state MASTER  #MASTER主,BACKUP为从,即声明为MASTER时为主的服务器,声明为BACKUP时为备用服务器
    interface eth0
    virtual_router_id 51
    priority 100  #优先级,主的优先级高
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.163.100/24 dev eth0 label etho:2  #设置VIP(虚拟服务器地址
    }
}

virtual_server 192.168.163.100 80 {  #设置虚拟lvs服务  ,VIP  PORT
    delay_loop 6
    lb_algo rr #调度算法
    lb_kind DR  #lvs的模式
    nat_mask 255.255.255.0
    persistence_timeout 0  # 同一个IP地址在多长时间内lvs转发给同一个后端服务器
    protocol TCP

    real_server 192.168.163.22 80 {  #设置真实服务器的心跳机制 ,可以配置多个真实服务器的心跳机制
        weight 1   #权重
        SSL_GET {
            url {
              path /    #心跳检测地址
              status_code 200 #心跳检测返回的状态
            }
            
            connect_timeout 3   #超时时间
            nb_get_retry 3   #重复检查3次
            delay_before_retry 3   #每个多少秒再次检查
        }
    }
	   real_server 192.168.163.23 80 {  #设置真实服务器的心跳机制 ,可以配置多个真实服务器的心跳机制
        weight 1   #权重
        SSL_GET {
            url {
              path /    #心跳检测地址
              status_code 200 #心跳检测返回的状态
            }
            
            connect_timeout 3   #超时时间
            nb_get_retry 3   #重复检查3次
            delay_before_retry 3   #每个多少秒再次检查
        }
    }
}

#下面的内容可以删除
virtual_server 10.10.10.2 1358 {
    delay_loop 6
    lb_algo rr 
    lb_kind NAT
    persistence_timeout 50
    protocol TCP

    sorry_server 192.168.200.200 1358

    real_server 192.168.200.2 1358 {
        weight 1
        HTTP_GET {
            url { 
              path /testurl/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            url { 
              path /testurl2/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            url { 
              path /testurl3/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.200.3 1358 {
        weight 1
        HTTP_GET {
            url { 
              path /testurl/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334c
            }
            url { 
              path /testurl2/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334c
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

virtual_server 10.10.10.3 1358 {
    delay_loop 3
    lb_algo rr 
    lb_kind NAT
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.200.4 1358 {
        weight 1
        HTTP_GET {
            url { 
              path /testurl/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            url { 
              path /testurl2/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            url { 
              path /testurl3/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.200.5 1358 {
        weight 1
        HTTP_GET {
            url { 
              path /testurl/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            url { 
              path /testurl2/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            url { 
              path /testurl3/test.jsp
              digest 640205b7b0fc66c1ea91c463fac6334d
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

Lvs standby server same configuration with the above, it is necessary to file keepalived.conf state MASTER to the BACKUP, and the lower priority than the priority of the master server lvs

Guess you like

Origin blog.csdn.net/qq_43687990/article/details/102468129