keepalived availability lvs

Now rs1 and rs2 above and ready to install httpd test page

Copy the code
[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
Copy the code

 

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

Copy the code
[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
Copy the code

 

Configuring client server gateway routing point

Copy the code
[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
Copy the code

 

Rs1 and rs2 configuration of the gateway point to the router

Copy the code
[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
Copy the code

 

Lvs and configure the gateway server to a router lvs2

Copy the code
[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
Copy the code

 

Vip were added in the rs1 and rs2 and close the arp notice

Copy the code
[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
Copy the code

 

Keepalived in lvs configuration server and Lvs2 

[root@lvs ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   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
}
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
    }
}
virtual_server 10.0.0.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
    sorry_server 192.168.37.23 80
    real_server 192.168.37.24 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
        }
    }
}
 
 
 
[root@lvs2 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   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
}
vrrp_instance VI_1 {
    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
    }
}
virtual_server 10.0.0.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
    sorry_server 192.168.37.26 80
    real_server 192.168.37.24 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"
}

 

 

 

 

Guess you like

Origin www.cnblogs.com/maxuebin/p/11314407.html