在2的实验基于上修改,添加一个机器159.50,将其159.30和159.50都改为keepalived服务器:
先实现keepalived服务器双方的ssh验证:
在keepalived服务器上修改hosts文件:
在159.30和159.50上安装keepalived服务和ipvsadmin:
master进行文件配置:
具体配置文件:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka1
vrrp_mcast_group4 224.100.100.100
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 6
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.159.100/24 dev eth0 label eth0:1
}
}
virtual_server 192.168.159.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 192.168.159.30 80
real_server 192.168.159.10 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.159.20 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
backup配置:
具体配置文件:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka1
vrrp_mcast_group4 224.100.100.100
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 6
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.159.100/24 dev eth0 label eth0:1
}
}
virtual_server 192.168.159.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 192.168.159.50 80
real_server 192.168.159.10 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.159.20 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
} }
}
在keepalived服务器上,启动keepalived服务:
//启动之前使用ls.sh停止之前的配置。