I. build lvs cluster of DR mode
Environment: DS: 192.168.4.53 VIP: 192.168.4.100
RS: 192.168.4.51 192.168.4.52
1. Establish three experimental machines and configure ip and yum warehouses
2. Configure VIP on DR
[root@53 ~]#cp /etc/sysconfig/network-scripts/ifcfg-eth0 {,:0} [root@53 ~]#vim /etc/sysconfig/network-scripts/ifcfg-eth0:0 ##Configure eth0:0 TYPE=Ethernet BOOTPROTO=none NAME=eth0:0 ##This item must be modified to eth0:0 DEVICE=eth0:0 ##This item must be modified to eth0:0 ONBOOT=yes IPADDR=192.168.4.100 ##This item must be modified to eth0:0 PREFIX=24 : wq [root@53 ~]#ifup eth0:0 [root@53 ~]#yum -y install ipvsadm.x86_64 ##Install cluster layout software [root@53 ~]#ipvsadm -A -t 192.168.4.100:80 -s rr ##Setting clusters [root@53 ~]#ipvsadm -a -t 192.168.4.100:80 -r 192.168.4.51 -g ##Add server [root@53 ~]#ipvsadm -a -t 192.168.4.100:80 -r 192.168.4.52 -g [root@53 ~]#ipvsadm -ln ##View cluster information [root@53 ~]#ipvsadm -save -n > /etc/sysconfig/ipvsadm ##Save configuration permanently
3. Deploy vip on the back segment server
[root@51 ~]#cp /etc/sysconfig/network-scripts/ifcfg-lo{,:0} [root@51 ~]#vim /etc/sysconfig/network-scripts/ifcfg-lo:0 DEVICE=lo:0 IPADDR=192.168.4.100 NETMASK=255.255.255.255 NETWORK=192.168.4.100 BROADCAST=192.168.4.100 ONBOOT=yes NAME=lo:0 [root@51 ~]#ifup lo:0 [root@51 ~]#sysctl -a | grep arp_ignore ##View options related to arpannounce net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.default.arp_ignore = 0 net.ipv4.conf.eth0.arp_ignore = 0 net.ipv4.conf.eth1.arp_ignore = 0 net.ipv4.conf.eth2.arp_ignore = 0 net.ipv4.conf.eth3.arp_ignore = 0 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.virbr0.arp_ignore = 0 net.ipv4.conf.virbr0-nic.arp_ignore = 0 [root@51 ~]#echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf [root@51 ~]#echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf [root@51 ~]#sysctl -a | grep arp_announce ##View options related to arpannounce net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.default.arp_announce = 0 net.ipv4.conf.eth0.arp_announce = 0 net.ipv4.conf.eth1.arp_announce = 0 net.ipv4.conf.eth2.arp_announce = 0 net.ipv4.conf.eth3.arp_announce = 0 net.ipv4.conf.lo.arp_announce = 2 net.ipv4.conf.virbr0.arp_announce = 0 net.ipv4.conf.virbr0-nic.arp_announce = 0 [root@51 ~]#echo "net.ipv4.conf.all.arp_announce = 2" >> /etc/sysctl.conf [root@51 ~]#echo "net.ipv4.conf.lo.arp_ignore = 1" >> /etc/sysctl.conf [root@51 ~]#sysctl -p ##This command allows the above write to take effect
**
Do the same operation on another back segment server, and then complete the DR mode cluster configuration
**
II. keepalived and lvs to achieve high availability
Environment: Based on the environment of Experiment 1, the following operations are arranged: add a scheduler to achieve high availability of DS, delete the cluster setting on the original DS, and the command is ipvsadm-d-t 192.168.4.100:80
1. Add a DS with ip of 192.168.4.54
The following operations are required on both machines:
2. Install ipvsadm and keepalived.x86-64 on both dispatchers
3. Modify the configuration file
vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { ##Mail configuration (keealived can realize mail alarm function) root@localhost ##Inbox } notification_email_from sally@firewall.loc ##Mail box smtp_server 127.0.0.1 ##Back end mail server (this machine can only write 127.0.0.1) smtp_connect_timeout 30 router_id LVS_DEVEL vrrp_skip_check_adv_addr #vrrp_strict ##This item requires comments, otherwise iptables will be started, causing rules to restrict access vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_instance VI_1 { ##vrp example state MASTER ##Divided into Master and Backup interface eth0 ##Network card used virtual_router_id 51 ##Virtual id number priority 150 ##Priority (active priority is high) advert_int 1 authentication { ##Authentication information of two dispatchers auth_type PASS auth_pass 1111 } virtual_ipaddress { ##Set up cluster VIP 192.168.4.100 } } //If you want to cluster websites, just do the above. Here is the lvs rule information virtual_server 192.168.4.100 80 { ##Cluster configuration, 80 port for website, equivalent to ipvsadm-a setting delay_loop 6 lb_algo rr lb_kind DR persistence_timeout 50 ##The same client accesses the same server within 50 seconds, which is conducive to performance improvement protocol TCP real_server 192.168.4.62 80 { ##Server configuration in cluster weight 1 TCP_CHECK { ##TCP type, there must be a space between TCP_CHECK and {, remember!!!!!! connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.4.63 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } :wq
4. Startup Test
[root@54 ~]# systemctl restart keepalived.service [root@54 ~]#ip a s eth0 [root@54 ~]#ipvsadm
5. In the client access test, it will be found that only one server will be accessed. After stopping one server, httpd will be checked to see whether the email will be received and the client access will be transferred to another server