**Four virtual machines
Client | lvs server | rs1 server |
---|---|---|
172.22.144.188 | VIP-172.22.144.59 DIP-192.168.49.2 | RIP-192.168.49.3 |
rs2 server |
---|
RIP-192.168.49.4 |
**Note that LVS server needs to play the role of scheduling and routing. Two IP addresses need to be enabled Whether lvs server, rs1 server and rs2 server are in time synchronization seliunx and whether the firewall is closed Check whether the value cat / proc / sys / net / IPv4 / IP forward of this directory is 1 on lvs server. If 0, change to 1**
Configuration of RS server
vim /etc/sysconfig/network-scripts/ifcfg-ens33 DEVICE=ens33 NAME=ens33 BOOTPROTO=static IPADDR=192.168.49.3 PREFIX=24 ONBOOT=yes GATEWAY=192.168.49.2 **rs1 The server points its gateway to the lvs The server DIP address rs2 The same is true for servers**
route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.49.2 0.0.0.0 UG 100 0 0 ens33 192.168.49.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 **See rs1,2 Is the gateway pointing to the correct**
ping 192.168.49.4 ping 192.168.49.2 **stay rs1,2 Server ping The other side also has lvs Server to check whether the network is smooth**
`yum install httpd -y`` **Download httpd service on rs1, 2 server**
echo lvyaoyuanyuan1 > /var/www/html/index.html echo lvyaoyuanyuan > /var/www/html/index.html **stay rs1,2 Import content on the server to the home directory**
curl 192.168.49.3 curl 192.168.49.4 **stay rs1,2 View on server httpd Whether the service is normal**
LVS server configuration
`yum install ipvsadm.x86_64 -y` **download ipvsadm package **
echo 0 > /proc/sys/net/ipv4/ip_forward **Start routing and forwarding service**
vim /etc/sysctl.conf net.ipv4.ip_forward=1 **Add last entry to profile**
sysctl -p **start-up ipforward service**
ipvsadm -A -t 172.22.144.59:80 -s rr Add cluster VIP SET protocol as TCP protocol port as 80 port scheduling algorithm as polling
ipvsadm -a -t 172.22.144.59 -r 192.168.49.3:80 -m ipvsadm -a -t 172.22.144.59 -r 192.168.49.4:80 -m Add two RS servers to TCP protocol mode as NAT mode
ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.22.144.59:80 rr -> 192.168.49.3:80 Masq 1 0 0 -> 192.168.49.4:80 Masq 1 0 0 //Check whether the RS server of lvs cluster content joins
Client operation test lvs nat Whether the cluster of mode is built successfully while true;do curl 172.22.144.59;sleep 1;done lvyaoyuanyuan1 lvyaoyuanyuan lvyaoyuanyuan1 lvyaoyuanyuan lvyaoyuanyuan1 lvyaoyuanyuan lvyaoyuanyuan1 lvyaoyuanyuan lvyaoyuanyuan1 lvyaoyuanyuan lvyaoyuanyuan1 lvyaoyuanyuan lvyaoyuanyuan1 lvyaoyuanyuan .......... //This command accesses the lvs server for an infinite loop every second