Now rs1 and rs2 above and ready to install httpd test page
[root@rs1 ~]# yum install httpd -y [root@rs1 ~]# echo "this is r1" > /var/www/html/index.html [root@rs1 ~]# systemctl start httpd [root@rs2 ~]# yum install httpd -y [root@rs2 ~]# echo "this is r2" > /var/www/html/index.html [root@rs2 ~]# systemctl start httpd
And mounting the ipvsadm keepalived (see To test the effect of using) the httpd (to achieve sorryserver) on lvs and Lvs2
[root@lvs ~]# yum install ipvsadm -y
[root@lvs ~]# yum install keepalived -y
[root@lvs ~]# yum install httpd -y
[root@lvs ~]# echo "this is lvs1" > /var/www/html/index.html
[root@lvs ~]# systemctl start httpd
[root@lvs2 ~]# yum install httpd -y
[root@lvs2 ~]# echo "this is lvs2" > /var/www/html/index.html
[root@lvs2 ~]# systemctl start httpd
[root@lvs2 ~]# yum install ipvsadm -y
[root@lvs2 ~]# yum install keepalived -y
Configuring router server (add an external network card on the router, and add two network address) to open the route forward
[root @ Router Network-scripts] # cp the ifcfg-ens33 the ifcfg-eth1 [root @ Router Network-scripts] # vim the ifcfg-eth1 NAME = "eth1" the DEVICE = "eth1" ONBOOT = yes NetBoot = yes BOOTPROTO = static IPADDR = 172.16.14.100 NETMASK = 255.255.0.0 the TYPE = Ethernet [root @ Router Network-scripts] # systemctl restart Network [root @ Router Network-scripts] # ip AA 10.0.0.10/8 dev eth0: # 1: this is a temporary increase of , if you want permanent, written in the configuration file [root @ Router ~] # vim /etc/sysctl.conf net.ipv4.ip_forward = 1 [root @ Router ~] # sysctl -p
Configuring client server gateway routing point
[root@client ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 NAME="eth0" DEVICE="eth0" ONBOOT=yes NETBOOT=yes BOOTPROTO=static IPADDR=172.16.14.200 NETMASK=255.255.0.0 GATEWAY=172.16.14.100 TYPE=Ethernet
Rs1 and rs2 configuration of the gateway point to the router
[root@rs1 ~]# vinet NAME="eth0" DEVICE="eth0" ONBOOT=yes NETBOOT=yes UUID="95b18552-6cc5-48c5-b29a-91ed73675c50" BOOTPROTO=static IPADDR=192.168.37.24 NETMASK=255.255.255.0 GATEWAY=192.168.37.22 [root@rs1 ~]# systemctl restart network [root@rs2 ~]# vinet NAME="eth0" DEVICE="eth0" ONBOOT=yes NETBOOT=yes UUID="cdd70dbc-1363-45da-9c7a-0ae369f9aac3" BOOTPROTO=static IPADDR=192.168.37.25 NETMASK=255.255.255.0 GATEWAY=192.168.37.22 [root@rs2 ~]# systemctl restart network
Lvs and configure the gateway server to a router lvs2
[root@lvs ~]# vinet NAME="eth0" DEVICE="eth0" ONBOOT=yes NETBOOT=yes UUID="15caec5a-6740-4a81-8c72-5fbcb6fb9d25" BOOTPROTO=static IPADDR=192.168.37.23 NETMASK=255.255.255.0 GATEWAY=192.168.37.22 TYPE=Ethernet
[root@lvs2 ~]# vinet
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
NETBOOT=yes
UUID="686fb723-2360-4683-bb81-8bc6a20778ff"
BOOTPROTO=static
IPADDR=192.168.37.26
NETMASK=255.255.255.0
GATEWAY=192.168.37.22
Vip were added in the rs1 and rs2 and close the arp notice
[root@rs1 ~]# ifconfig lo:1 10.0.0.100 netmask 255.255.255.255 [root@rs1 ~]# route add -host 10.0.0.100 dev lo:1 [root@rs1 ~]# vim /etc/sysctl.conf net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.lo.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 net.ipv4.conf.lo.arp_announce=2 [root@rs1 ~]# sysctl -p [root@rs2 ~]# ifconfig lo:1 10.0.0.100 netmask 255.255.255.255 [root@rs2 ~]# route add -host 10.0.0.100 dev lo:1 [root@rs2 ~]# vim /etc/sysctl.conf net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.lo.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 net.ipv4.conf.lo.arp_announce=2 [root@rs2 ~]# sysctl -p
Keepalived in lvs configuration server and Lvs2
[root@lvs ~]# vim /etc/keepalived/keepalived.conf
notification_email {
root@localhost
}
notification_email_from Alexandre.Cassen@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka1
vrrp_mcast_group4 224.100.100.99
}
state MASTER
interface eth0
virtual_router_id 77
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.0.0.100/8 dev eth0 lable eth0:1
}
}
delay_loop 6
lb_kind DR
protocol TCP
sorry_server 192.168.37.23 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.37.25 80 {
weight 1
HTTP_GET {
url {
path /
status_code=200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
notification_email {
root@localhost
}
notification_email_from Alexandre.Cassen@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka2
vrrp_mcast_group4 224.100.100.99
}
state BACKUP
interface eth0
virtual_router_id 77
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.0.0.100/8 dev eth0 lable eth0:1
}
}
delay_loop 6
lb_kind DR
protocol TCP
sorry_server 192.168.37.26 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.37.25 80 {
weight 1
HTTP_GET {
url {
path /
status_code=200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
Start keepalived respectively lvs server
[root@lvs2 ~]# systemctl start keepalived
[root@lvs ~]# systemctl start keepalived
In the client server test
The following are the parameters keepalived
You can also define a notification script on keepalived
Lvs in each server configuration script
[root@lvs keepalived]# vim notify.sh #!/bin/bash # contact='root@localhost' notify() { mailsubject="$(hostname) to be $1, vip floating" mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1" echo "$mailbody" | mail -s "$mailsubject" $contact } case $1 in master) notify master ;; backup) notify backup ;; fault) notify fault ;; *) echo "Usage: $(basename $0) {master|backup|fault}" exit 1 ;; esac
在各lvs服务器配置
[root@lvs keepalived]# vim keepalived.conf vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 77 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 10.0.0.100/8 dev eth0 lable eth0:1 } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" }