机器: node01~node04
node01,清空之前配置的lvs信息:
ipvsadm -C ifconfig eth0:8 down
node01、node04,安装keepalived:
yum install keepalived ipvsadm -y
cd /etc/keepalived/
#备份
cp keepalived.conf keepalived.conf.bak
vi keepalived.conf
修改的keepalived.conf文件中 vrrp(虚拟路由冗余协议):
vrrp_instance VI_1 { state MASTER //node04中为BACKUP interface eth0 #网卡 virtual_router_id 51 priority 100 //node04中改为50或其他小于100的数 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.150.100/24 dev eth0 label eth0:3
#此处配置类似上篇文章中的 ipvsadm -A配置虚拟子网卡IP、子掩码 } }
virtual_server 192.168.150.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 0
protocol TCP
real_server 192.168.150.12 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.150.13 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}