一./etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id wfc
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass pass_wfc
}
virtual_ipaddress {
10.21.10.32
}
}
virtual_server 10.21.10.32 6667 {
delay_loop 6
lb_algo wlc
lb_kind DR
ops
persistence_timeout 50
protocol TCP
nat_mask 255.255.255.0
include realserver_wfc
}
二./etc/keepalived/realserver_wfc
1.80 port
real_server 10.21.10.30 80 {
weight 1
HTTP_GET {
url {
path /keeptest/index.html
digest 3b9bc8d36a113971683321ad4fa02daf
}
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
/usr/bin/genhash -s 10.21.10.30 -p 80 -u /keeptest/index.html
2.自帶檢測
/etc/keepalived/realserver_wfc
real_server 10.21.10.30 80 {
weight 4
include only_tcp_80
}
/etc/keepalived/only_tcp_80
TCP_CHECK {
connect_timeout 5
connect_port 80
}
3.腳本檢測
/etc/keepalived/realserver_wfc
real_server 10.21.10.30 80 {
weight 1
MISC_CHECK {
misc_path "/etc/keepalived/check_port.sh 10.21.10.30 80"
misc_timeout 10
}
}
4.腳本如下
/etc/keepalived/check_port.sh
#!/bin/bash
/usr/bin/nc -z -w1 $1 $2 | grep succeeded > /dev/null
exit $?