网络拓扑结构
操作系统为centos7.3
1.所有主机RS1、RS2、DS1、DS2都开apache服务器,RS1、 RS2都用来测试web服务器的,DS1 、DS2是用来做sorry 服务器的。
2.所有服务器都时间同步
3.在DS上开vrrp
DS1上配置
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
[email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
}
vrrp_instance jin-vrrp {
state MASTER
interface ens37
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.200/24 devens37
}
}
virtual_server 192.168.0.200 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence timeout 50
protocol TCP
sorry_server 127.0.0.1 80
real_server 192.168.0.10380 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry3
}
}
real_server 192.168.0.10480 {
weight1
HTTP_GET{
url{
path/
status_code200
}
}
connect_timeout3
nb_get_retry3
delay_before_retry3
}
}
}
DS2上配置
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
[email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
}
vrrp_instance jin-vrrp {
state BACKUP
interface ens37
virtual_router_id 51
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.200/24 dev ens37
}
}
virtual_server 192.168.0.200 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence timeout 50
protocol TCP
sorry_server 127.0.0.1 80
real_server 192.168.0.10380 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry3
}
}
real_server 192.168.0.10480 {
weight1
HTTP_GET{
url{
path/
status_code200
}
}
connect_timeout3
nb_get_retry3
delay_before_retry3
}
}
}
做这个实验的时候要小心花括号。
4.在二个RS服务上写脚本用来做lvs-dr里的VIP
在lo上生成vip地址及路由条目。
5.由于二个DS配完keepalived的vrrp后。只要yum ipvsadm就可以了,至于ipvsadm策略会通过keepalived会自动生成
6.测试结果