(转)keepalive.conf参数配置详细说明

keepalived既可以作为HA热备,也能作健康检查。

1,安装keepalived

2,把配置文件复制到/etc/keepalived/路径下,cp /usr/share/doc/keepalived/examples/ldirectord.conf.example /etc/keepalived/keepalived.conf

3,修改配置文件

global_defs {
   notification_email {  #指定keepalived在发生切换时需要发送email到的对象,一行一个
    sysadmin@fire.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc #指定发件人
   smtp_server localhost #指定smtp服务器地址
   smtp_connect_timeout 30 #指定smtp连接超时时间
   router_id LVS_DEVEL #运行keepalived机器的一个标识
}
vrrp_sync_group VG_1{ #监控多个网段的实例
group {
inside_network #实例名
outside_network
}
notify_master /path/xx.sh #指定当切换到master时,执行的脚本
netify_backup /path/xx.sh #指定当切换到backup时,执行的脚本
notify_fault "path/xx.sh VG_1" #故障时执行的脚本
notify /path/xx.sh 
smtp_alert #使用global_defs中提供的邮件地址和smtp服务器发送邮件通知
}
vrrp_instance inside_network {
    state BACKUP #指定那个为master,那个为backup,如果设置了nopreempt这个值不起作用,主备考priority决


    interface eth0 #设置实例绑定的网卡
    dont_track_primary #忽略vrrp的interface错误(默认不设置)
    track_interface{ #设置额外的监控,里面那个网卡出现问题都会切换
    eth0
    eth1
    }
    mcast_src_ip #发送多播包的地址,如果不设置默认使用绑定网卡的primary ip
    garp_master_delay #在切换到master状态后,延迟进行gratuitous ARP请求
    virtual_router_id 50 #VPID标记
    priority 99 #优先级,高优先级竞选为master
    advert_int 1 #检查间隔,默认1秒
    nopreempt #设置为不抢占 注:这个配置只能设置在backup主机上,而且这个主机优先级要比另外一台高
    preempt_delay #抢占延时,默认5分钟
    debug #debug级别
    authentication { #设置认证
        auth_type PASS #认证方式
        auth_pass 111111 #认证密码
    }
    virtual_ipaddress { #设置vip
        192.168.202.200
    }
}
virtual_server 192.168.202.200 23 {
    delay_loop 6 #健康检查时间间隔
    lb_algo rr  #lvs调度算法rr|wrr|lc|wlc|lblc|sh|dh
    lb_kind DR  #负载均衡转发规则NAT|DR|RUN
    persistence_timeout 5 #会话保持时间
    protocol TCP #使用的协议
    persistence_granularity <NETMASK> #lvs会话保持粒度
    virtualhost <string> #检查的web服务器的虚拟主机(host:头)    
    sorry_server<IPADDR> <port> #备用机,所有realserver失效后启用
real_server 192.168.200.5 23 {
            weight 1 #默认为1,0为失效
            inhibit_on_failure #在服务器健康检查失效时,将其设为0,而不是直接从ipvs中删除 
            notify_up <string> | <quoted-string> #在检测到server up后执行脚本
            notify_down <string> | <quoted-string> #在检测到server down后执行脚本
            
TCP_CHECK {
            connect_timeout 3 #连接超时时间
            nb_get_retry 3 #重连次数
            delay_before_retry 3 #重连间隔时间
            connect_port 23  健康检查的端口的端口
            bindto <ip>   
          }
HTTP_GET | SSL_GET{
    url{ #检查url,可以指定多个
         path /
         digest <string> #检查后的摘要信息
         status_code 200 #检查的返回状态码
        }
    connect_port <port> 
    bindto <IPADD>
    connect_timeout 5
    nb_get_retry 3
    delay_before_retry 2
}

SMTP_CHECK{
    host{
    connect_ip <IP ADDRESS>
    connect_port <port> #默认检查25端口
    bindto <IP ADDRESS>
         }
    connect_timeout 5
    retry 3
    delay_before_retry 2
    helo_name <string> | <quoted-string> #smtp helo请求命令参数,可选
}
MISC_CHECK{
    misc_path <string> | <quoted-string> #外部脚本路径
    misc_timeout #脚本执行超时时间
    misc_dynamic #如设置该项,则退出状态码会用来动态调整服务器的权重,返回0 正常,不修改;返回1,

检查失败,权重改为0;返回2-255,正常,权重设置为:返回状态码-2
}
    }

 

 

keepalived健康检查 HTTP_GET

 

一:
real_server 192.168.2.188 80 {
     weight 1
     HTTP_GET {
       url {
       path /index.html
       digest bfaa334fdd71444e45eca3b7a1679a4a  #http://192.168.2.188/index.html的digest值          }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
digest值的获取方法:
[root@188-test html]# genhash -s 192.168.2.188 -p 80 -u /index.html
MD5SUM = bfaa334fdd71444e45eca3b7a1679a4a
genhash命令:
[root@188-test html]# genhash
genhash v1.0.0 (18/11, 2002)
Usage:
  genhash -s server-address -p port -u url
  genhash -S -s server-address -p port -u url
  genhash -h
  genhash -r

Commands:
Either long or short options are allowed.
  genhash --use-ssl         -S       Use SSL connection to remote server.
  genhash --server          -s       Use the specified remote server address.
  genhash --port            -p       Use the specified remote server port.
  genhash --url             -u       Use the specified remote server url.
  genhash --use-virtualhost -V       Use the specified virtualhost in GET query.
  genhash --verbose         -v       Use verbose mode output.
  genhash --help            -h       Display this short inlined help screen.
  genhash --release         -r       Display the release number


二:
real_server 192.168.2.188 80 {
      weight 1
      HTTP_GET {
          url {
          path /index.html
          status_code 200      #http://192.168.2.188/index.html的返回状态码
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }

 

 

转至:http://blog.csdn.net/jibcy/article/details/7826158

posted @ 2015-06-11 18:52  玩石  阅读(2669)  评论(0)    收藏  举报