欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Keepalived系列一:Keepalived.conf 详解

程序员文章站 2022-07-12 17:41:25
...

接上一篇博客:

http://www.cnblogs.com/xiaoit/p/4499703.html

 

1:按照上篇博客安装后的配置文件在

/usr/local/etc/keepalived/keepalived.conf

默认内容如下:

! 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_DEVEL
}

#前面定义的后备的负载均衡服务器名称
vrrp_instance VI_1 {
    #只有MASTER和BACKUP 两种状态,都必须大写。
    state MASTER
    #进行通信的端口
    interface eth0

    #同一个vrrp实例的唯一标识。即同一个vrrp_stance,MASTER和BACKUP的virtual_router_id是一致的。在整个vrrp内也唯一。
    virtual_router_id 51
    
    #权重,数值越大,权重越大。MASTER大于SLAVE
    priority 100
    
    #MASTER和SLAVE负载均衡器之间同步检查的时间间隔。单位是:秒
    advert_int 1
    
    #MASTER和SLAVE的认证方式
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.200.16
        192.168.200.17
        192.168.200.18
    }
}

#virtual_ipaddress,需要添加端口
virtual_server 192.168.200.100 443 {
    #服务健康检查周期,6秒
    delay_loop 6
    
    #负载均衡调度算法rr|wrr|lc|wlc|sh|dh|lblc
    lb_algo rr
    
    #负载均衡转发规则NAT|DR|TUN
    lb_kind NAT
    nat_mask 255.255.255.0
    
    #回话保持时间,如果是动态服务,建议开启。默认50秒
    persistence_timeout 50
    protocol TCP

    #真是IP
    real_server 192.168.201.100 443 {
        
        #权重,数值越大,权重越高。分发的可能越大
        weight 1
        SSL_GET {
            url {
              path /
              digest ff20ad2481f97b1754ef3e12ecd3a9cc
            }
            url {
              path /mrtg/
              digest 9b3a0c85a887a256d6939da88aabd8cd
            }
            connect_timeout 3
            nb_get_retry 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
        }
    }
}

参考:

http://www.keepalived.org/documentation.html