您的位置:首页 > 其它

keepalived健康检查方式配置笔记

2013-03-20 16:09 555 查看
keepalived健康检查方式:HTTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|MISC_CHECK

HTTP_GET | SSL_GET
{
url {

path /                       # HTTP/SSL 检查的url 可以是多个
digest <STRING> # HTTP/SSL 检查后的摘要信息 用工具genhash生成
status_code 200  # HTTP/SSL 检查返回的状态码

}
connect_port 80 # 连接端口

bindto <IPADD>
connect_timeout # 连接超时时间
nb_get_retry 3 # 重连次数

delay_before_retry 2 #连接间隔时间

} # END OF HTTP_GET|SSL_GET


TCP健康检查方式

TCP_CHECK {
connect_port 80
bindto 192.168.1.1
connect_timeout 4
} # TCP_CHECK


# SMTP健康检查方式

SMTP_CHECK
host {
connect_ip <IP ADDRESS>
connect_port <PORT> # 默认检查端口25

}
connect_timeout <INTEGER>
retry <INTEGER>
delay_before_retry <INTEGER>
# "请求命令参数,可选

helo_name <STRING>|<QUOTED-STRING>
} #SMTP_CHECK


#MISC

健康检查方式MISC_CHECK
{
# 外部程序或者脚本路径

misc_path <STRING>|<QUOTED-STRING>
# 执行脚本的超时时间
misc_timeout <INT>
# XJ
misc_dynamic{§ healthchecker§S
misc_dynamic
}




其中 工具genhash使用

[root@localhost bin]# ./genhash -h
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

工具产生结果如下:

[root@localhost bin]# ./genhash -s  10.7.11.12 -p 80 -u http://10.7.11 .40/index.html
MD5SUM = b7bd8391367e4cf9e4e85263ce313ae8


 

配置如下:

real_server 10.7.11.12 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
HTTP_GET {
url {
path /
digest b7bd8391367e4cf9e4e85263ce313ae8
status_code 200
}
#url {
#path /mrtg/
#digest 9b3a0c85a887a256d6939da88aabd8cd
#}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}


TCP健康检查方式配置例子:

real_server 192.168.191.130 80 {
weight 3
inhibit_on_failure #在服务器健康检查失效时,将其设为0
TCP_CHECK {
connect_timeout 5 #连接超时时间
nb_get_retry 3  #重连次数
delay_before_retry 3 #重连间隔时间
connect_port 80 #健康检查的端口
}
}


SSL健康检查方式同HTTP,例子如下:

virtual_server 192.168.200.100 443 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP

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


SNMP方式例子:

real_server 172.16.1.12 25 {
weight 1
SMTP_CHECK {
connect_timeout 10
retry 2
delay_before_retry 5
helo_name "foo.bar.com"

host {
connect_ip 172.16.1.12
connect_port 25
bindto 172.16.1.2
}

host {
connect_ip  192.168.155.11
connect_port 25
bindto 192.168.155.2
}

host {
connect_ip  64.233.167.100
connect_port 587
}
}
}


MISC方式脚本带参数例子:

real_server 192.168.200.6 1358 {
weight 1
MISC_CHECK {
misc_path "/usr/local/bin/script.sh arg1 arg2"
}
}

MISC方式脚本不带参数例子:

real_server 192.168.200.6 1358 {
weight 1
MISC_CHECK {
misc_path /usr/local/bin/script.sh
!          misc_dynamic
}
}


参考keepalived权威指南和keepalived中的例子
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: