start() {
[ -x $exec ] || exit 5
[ -e $config ] || exit 6
echo -n $"Starting $prog: "
daemon $exec $KEEPALIVED_OPTIONS
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
killproc $prog -1
retval=$?
echo
return $retval
}
force_reload() {
restart
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status &>/dev/null
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $
[root@lvsmaster ~]# chmod u+x /etc/rc.d/init.d/keepalived
[root@lvsmaster ~]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
……
smtp_connect_timeout 30
router_id LVS_Master #表示运行Keepalived服务器的一个标识
}
vrrp_instance VI_1 {
state MASTER #指定Keepalived的角色
interface eth0 #指定HA监测网络的接口
virtual_router_id 51 #同一个vrrp实例使用唯一的标识,即同一个vrrp_instance下,Master和Backup必须是一致的
priority 100 #定义优先级,数值越大,优先级越高
advert_int 1 #设定Mater和Backup负载均衡器之间同步检查时间间隔
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.24.8.100 #设置虚拟IP地址
}
}
virtual_server 172.24.8.100 80 {
delay_loop 6 #运行情况检查时间
lb_algo rr #设置负载均衡算法
lb_kind DR #设置LVS实现负载均衡的机制,有NAT/DR/TUN
persistence_timeout 50 #会话保持时间
protocol TCP #指定转发类型
real_server 172.24.8.12 80 {
weight 1 #服务节点的权值,数值越大,权值越高
TCP_CHECK {
connect_timeout 5 #表示无响应超时时间,单位是秒
nb_get_retry 3 #表示重试次数
delay_before_retry 3 #表示重试间隔
}
}
real_server 172.24.8.13 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@lvsmaster ~]# scp /etc/keepalived/keepalived.conf 172.24.8.11:/etc/keepalived/keepalived.conf
[root@lvsbackup ~]# vi /etc/keepalived/keepalived.conf
state BACKUP
priority 80
注意;备用Director Server上需要修改状态为BACKUP和priority优先级。
2.5 安装IPVS管理工具1 [root@lvsmaster ~]# yum -y install ipvsadm
2.6 配置Real Server节点