##测试,看看能不能访问web
[iyunv@haproxy-1 haproxy]# curl 10.0.0.11
It is web1
[iyunv@haproxy-1 haproxy]# curl 10.0.0.11
It is web2
[iyunv@haproxy-1 haproxy]# curl 10.0.0.11
It is web1
[iyunv@haproxy-1 haproxy]# curl 10.0.0.11
It is web2
##现在haproxy就已经配置好了
[iyunv@haproxy-2 ~]# systemctl start keepalived
[iyunv@haproxy-2 ~]# systemctl enable keepalived
[iyunv@haproxy-2 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2017-10-28 12:30:09 CST; 5s ago
Process: 9158 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 9159 (keepalived)
CGroup: /system.slice/keepalived.service
├─9159 /usr/sbin/keepalived -D
├─9160 /usr/sbin/keepalived -D
└─9161 /usr/sbin/keepalived -D
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: VRRP_Instance(VI_1) Changing effective priority from 100 to 102
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: VRRP_Instance(VI_2) Changing effective priority from 150 to 152
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: VRRP_Instance(VI_2) Entering MASTER STATE
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: VRRP_Instance(VI_2) setting protocol VIPs.
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: VRRP_Instance(VI_2) Sending/queueing gratuitous ARPs on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.200
Oct 28 12:30:10 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.200
[iyunv@haproxy-2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:76:bf:48 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.12/24 brd 10.0.0.255 scope global ens33
valid_lft forever preferred_lft forever
inet 10.0.0.200/32 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::f87c:449f:eb4a:ba03/64 scope link
valid_lft forever preferred_lft forever
访问web服务:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@localhost ~]# curl 10.0.0.100
It is web1
[iyunv@localhost ~]# curl 10.0.0.100
It is web2
[iyunv@localhost ~]# curl 10.0.0.100
It is web1
[iyunv@localhost ~]# curl 10.0.0.100
It is web2
[iyunv@localhost ~]#
[iyunv@localhost ~]# curl 10.0.0.200
It is web1
[iyunv@localhost ~]# curl 10.0.0.200
It is web2
[iyunv@localhost ~]# curl 10.0.0.200
It is web1
[iyunv@localhost ~]# curl 10.0.0.200
It is web2
[iyunv@haproxy-2 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2017-10-28 12:30:09 CST; 21min ago
Process: 9158 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 9159 (keepalived)
CGroup: /system.slice/keepalived.service
├─9159 /usr/sbin/keepalived -D
├─9160 /usr/sbin/keepalived -D
└─9161 /usr/sbin/keepalived -D
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:07 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp[9161]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
Oct 28 12:51:12 haproxy-2 Keepalived_vrrp[9161]: Sending gratuitous ARP on ens33 for 10.0.0.100
[iyunv@haproxy-2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:76:bf:48 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.12/24 brd 10.0.0.255 scope global ens33
valid_lft forever preferred_lft forever
inet 10.0.0.200/32 scope global ens33
valid_lft forever preferred_lft forever
inet 10.0.0.100/32 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::f87c:449f:eb4a:ba03/64 scope link
valid_lft forever preferred_lft forever
##访问web网页(可以看到web页面还是可以正常访问的)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[iyunv@localhost ~]# curl 10.0.0.100
It is web1
[iyunv@localhost ~]# curl 10.0.0.100
It is web2
[iyunv@localhost ~]# curl 10.0.0.100
It is web1
[iyunv@localhost ~]# curl 10.0.0.100
It is web2
[iyunv@localhost ~]# curl 10.0.0.200
It is web1
[iyunv@localhost ~]# curl 10.0.0.200
It is web2
[iyunv@localhost ~]# curl 10.0.0.200
It is web1
[iyunv@localhost ~]# curl 10.0.0.200
It is web2