编辑vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
****@qq.com
}
notification_email_from ****@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 15
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eno16777736:0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.127.138
}
}
virtual_server 192.168.127.138 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 5
protocol TCP
real_server 192.168.127.129 80 {
weight 1
inhibit_on_failure
notify_up "/sbin/ipvsadm -a -u 192.168.127.138:52100 -r 192.168.127.129:52100 -g"
notify_down "/sbin/ipvsadm -d -u 192.168.127.138:52100 -r 192.168.127.129:52100"
TCP_CHECK {
connnect_timeout 5
connect_port 80
}
}
real_server 192.168.127.130 80 {
weight 1
inhibit_on_failure
notify_up "/sbin/ipvsadm -a -u 192.168.127.138:52100 -r 192.168.127.130:52100 -g"
notify_down "/sbin/ipvsadm -d -u 192.168.127.138:52100 -r 192.168.127.130:52100"
TCP_CHECK {
connect_timeout 5
connect_port 80
}
}
}
保存退出
开启keepalived服务:
service keepalived start
停止命令:
service keepalived stop
注意开启之前必须先开启ipvsadm服务才能生效。