Building LVS+Keepalived High availability Cluster by CentOS7.4-
LVS+Keepalived High availability Cluster
Catalogue
Part I Environmental preparation
The second part uses Keepalived to build dual-computer hot backup.
The third part configures the Web node server
Part IV testing LVS+Keepalived High availability Cluster
Part I Environmental preparation
One: two dispatchers (dual hot standby)
System: Linux-CentOS 7.4
IP address: 192.168.80.10 (primary)
IP address: 192.168.80.20 (standby)
Two Web servers
System: Linux-CentOS 7.4
IP address: 192.168.80.30 (SERVER AA)
IP address: 192.168.80.40 (SERVER BB)
Three: a client computer: take win7 as an example, for testing
IP address: 192.168.80.2
The second part uses Keepalived to build dual-computer hot backup.
Step 1: configure the main scheduler
[root@dd01 ~] # modprobe ip_vs / / load ip_vs module
[root@dd01] # rpm-ivh / mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm / / install the management software ipvsadm
[root@dd01 ~] # yum-y install gcc gcc-c++ make popt-devel kernel-devel openssl-devel
/ / install compilation tools and plug-ins
[root@dd01 ~] # tar xzvf keepalived-1.4.2.tar.gz / / extract the keepalived installation package
[root@dd01 ~] # cd keepalived-1.4.2/
[root@dd01 keepalived-1.4.2] # / configure-- prefix=/ configuration
[root@dd01 keepalived-1.4.2] # make & & make install / / compile and install
[root@dd01 keepalived-1.4.2] # cp keepalived/etc/init.d/keepalived / etc/init.d/
/ / join the system management service
[root@dd01 keepalived-1.4.2] # systemctl enable keepalived / / set boot self-startup
[root@dd01 keepalived-1.4.2] # vi / etc/keepalived/keepalived.conf / / Edit configuration file
! Configuration File for keepalived
Global_defs {
Router_id LVS_01 / / name of this server
}
Vrrp_instance VI_1 {/ / define VRRP hot backup instance
State MASTER / / Hot standby status. MASTER represents master server and BACKUP represents slave server.
Interface ens33 / / physical interface that carries the VIP address
Virtual_router_id 51 / / ID number of the virtual router, consistent with each hot backup group
Priority 110 / / priority, the higher the number, the higher the priority.
Advert_int 1 / / seconds between announcements (heartbeat rate)
Authentication {/ / hot backup authentication information, which is consistent with each hot backup group
Auth_type PASS / / authentication type
Auth_pass 6666 / / password string
}
Virtual_ipaddress {/ / specify drift address (VIP), which can have more than one
192.168.80.100
}
}
Virtual_server 192.168.80.100 80 {/ / Virtual server address (VIP), port
Delay_loop 6 / / interval between health check-ups (seconds)
Lb_algo rr / / polling (rr) scheduling algorithm
Lb_kind DR / / Direct routing (DR) cluster operation mode
Persistence_timeout 60 / / connection hold time (seconds)
The protocol TCP / / application server uses TCP protocol
Real_server 192.168.80.30 80 {/ / the address and port of the first Web server node
Weight of weight 1 / / nod
TCP_CHECK {/ / Health check method
Connect_port 80 / / Target port for check
Connect_timeout 3 / / connection timeout (seconds)
Nb_get_retry 3 / / number of retries
Delay_before_retry 3 / / retry interval
}
}
Real_server 192.168.80.40 80 {/ / the address and port of the second Web server node
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
Save exit
[root@dd01 keepalived-1.4.2] # service keepalived start
[root@dd01 keepalived-1.4.2] # ip addr show dev ens33 / / verify the bound virtual address
[root@dd01 keepalived-1.4.2] # ipvsadm-L / / View LVS virtual server
[root@dd01 keepalived-1.4.2] # tail-f / var/log/messages
Step 2: configure the slave scheduler
[root@dd02 ~] # modprobe ip_vs / / load ip_vs module
[root@dd02] # rpm-ivh / mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm / / install the management software ipvsadm
[root@dd02 ~] # yum-y install gcc gcc-c++ make popt-devel kernel-devel openssl-devel
[root@dd02 ~] # tar xzvf keepalived-1.4.2.tar.gz
[root@dd02 ~] cd keepalived-1.4.2/
[root@dd02 keepalived-1.4.2] #. / configure-prefix=/
[root@dd02 keepalived-1.4.2] # make & & make install
[root@dd02 keepalived-1.4.2] # cp keepalived/etc/init.d/keepalived / etc/init.d/
[root@dd02 keepalived-1.4.2] # systemctl enable keepalived
[root@dd02 keepalived-1.4.2] # vi / etc/keepalived/keepalived.conf
! Configuration File for keepalived
Global_defs {
Router_id LVS_02
}
Vrrp_instance VI_1 {
State BACKUP
Interface ens33
Virtual_router_id 51
Priority 105
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 6666
}
Virtual_ipaddress {
192.168.80.100
}
}
Virtual_server 192.168.80.100 80 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Persistence_timeout 60
Protocol TCP
Real_server 192.168.80.30 80 {
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 192.168.80.40 80 {
Weight 1
TCP_CHECK {
Connect_port 80
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
Save exit
[root@dd02 keepalived-1.4.2] # service keepalived start
[root@dd02 keepalived-1.4.2] # ipvsadm-L
Step 3: verify the results
Dd01 master server keepalived service on status, verify dd02 slave server status
[root@dd02 keepalived-1.4.2] # ip addr show dev ens33
[root@dd02 keepalived-1.4.2] # tail-f / var/log/messages
/ / standby status simulates the failure of the master server, shuts down the keepalived service of the dd01 master server, and verifies the dd02 slave server status
[root@dd01 keepalived-1.4.2] # systemctl stop keepalived
/ / switch the standby to the host state
/ / A pair of hot standby machines have been built.
The third part configures the Web node server
Step 1: configure the SERVER AA server (192.168.80.30)
Configure the http service
/ / install http service
[root@aa ~] # yum install-y httpd
/ / Edit the main configuration file
[root@aa ~] # vi / etc/httpd/conf/httpd.conf
ServerName aa / / remove the "#" number and modify the host name
Save exit
/ / configure the default display web page
[root@aa ~] # cd / var/www/html/
[root@aa html] # echo "SERVER AA" > index.html
[root@aa html] # service httpd start / / restart the http service
/ / win7 verifies the http service
Visit http://192.168.80.30
Configure DR mode
[root@aa ~] # vi web.sh
#! / bin/bash
#
Ifconfig lo:0 192.168.80.100 broadcast 192.168.80.100 netmask 255.255.255.255 up
Route add-host 192.168.80.100 dev lo:0
Echo "1" > / proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "2" > / proc/sys/net/ipv4/conf/lo/arp_announce
Echo "1" > / proc/sys/net/ipv4/conf/all/arp_ignore
Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce
Sysctl-p & > / dev/null
Save exit
[root@aa ~] # sh web.sh / / execute script
[root@aa ~] # ifconfig / / View virtual interface
Step 2: configure the SERVER BB server (192.168.80.40)
Configure the http service
/ / install http service
[root@bb ~] # yum install-y httpd
/ / Edit the main configuration file
[root@bb ~] # vi / etc/httpd/conf/httpd.conf
ServerName bb / / remove the "#" number and modify the host name
Save exit
/ / configure the default display web page
[root@bb ~] # cd / var/www/html/
[root@bb html] # echo "SERVER BB" > index.html
[root@bb html] # service httpd start / / restart the http service
/ / win7 verifies the http service
Visit http://192.168.80.40
-configure DR mode-
[root@bb ~] # vi web.sh
#! / bin/bash
# hehe
Ifconfig lo:0 192.168.80.100 broadcast 192.168.80.100 netmask 255.255.255.255 up
Route add-host 192.168.80.100 dev lo:0
Echo "1" > / proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "2" > / proc/sys/net/ipv4/conf/lo/arp_announce
Echo "1" > / proc/sys/net/ipv4/conf/all/arp_ignore
Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce
Sysctl-p & > / dev/null
Save exit
[root@bb ~] # sh web.sh / / execute script
[root@bb ~] # ifconfig / / View virtual interface
Part IV testing LVS+Keepalived High availability Cluster
Verify that the cluster is built successfully if the web page content can be accessed normally from the drift address of the LVS+Keepalived cluster (192.168.80.100) in the client's browser.
Verify the polling work of two Web servers
Win7 accesses http://192.168.80.100
/ / since the connection retention time is set to 60 seconds, revisit the address one minute later.
/ / automatic polling to another Web server
Simulate the failure of the main scheduler and verify the results
[root@dd01 keepalived-1.4.2] # systemctl stop keepalived
/ / the main scheduler keepalived stops working
/ / automatically switch from the scheduler and continue to work
/ / win7 accesses http://192.168.80.100 to view the result
/ / one minute later, revisit http://192.168.80.100 to view the result
/ / A pair of computer hot backup has worked.
Simulate Web server aa failure
[root@bb ~] # service httpd stop / / stop the bb server
[root@dd01 keepalived-1.4.2] # tail-f / var/log/messages
Visit http://192.168.80.40
One minute later, revisit http://192.168.80.40
/ / unable to access, verification is successful
[root@bb ~] # service httpd start / / resume starting bb server
/ / View the scheduler log:
/ / the bb server has been successfully added to the server pool
/ / LVS+Keepalived has been successfully built and tested.