Every time you configure LVS, you need to re-access the internet to find configuration methods. some of these methods are incorrect, and most of them are not very comprehensive. it takes some time to troubleshoot each time, therefore, I decided to write an article and record it to avoid wasting time in the future. LVS installation will not be mentioned. if I do not install software like LVS in linux, I cannot say so.
Every time you configure LVS, you need to re-access the internet to find configuration methods. some of these methods are incorrect, and most of them are not very comprehensive. it takes some time to troubleshoot each time, therefore, I decided to write an article and record it to avoid wasting time in the future. The installation of LVS will not be mentioned. if you do not install software like LVS in linux, you cannot say it. This article only records how to configure LVS. The lvs dr method is the most commonly used, so only this method is introduced.
Configuration environment description: System CentOS6.2, virtual IP (VIP) is 192.168.9.191, and the actual server IP addresses are 192.168.9.192 and 192.168.9.193, respectively.
1. ctor configuration
1) add VIP
Add a VIP to the NIC (assuming the nic name is eth0), first switch to the/etc/sysconfig/network-scripts/directory, copy the ifcfg-eth0 file named ifcfg-eth0: 0, then edit ifcfg-eth0: 0 to change IPADDR in the file to VIP and DEVICE to eth0: 0 as follows:
After the configuration is complete, restart the network service (networkrestart) and run the ifconfig command to check whether the network service is successful. If the setting is successful, an additional device named eth0: 0 will be displayed, as shown below:
2) modify the system configuration, enable/etc/sysctl. conf, set the value of net. ipv4.ip _ forward to 1, save, use the sysctl-p command to make the configuration take effect, or restart the system.
3) disableIptablesService. if you do not want to disableIptablesService, enable the server port number in iptables configuration rules
4) disable SElinux. this service sometimes causes very strange problems. it is best to disable SElinux.
5) add the actual server and put it in the script. the script content is as follows:
#! /Bin/sh
Ipvsadm-C
Ipvsadm-A-t 192.168.9.191: 80-s wlc
Ipvsadm-a-t 192.168.9.191: 80-r 192.168.9.192-g
Ipvsadm-a-t 192.168.9.191: 80-r 192.168.9.193-g
II. real server settings
1) add VIP
The VIP in the actual server must be configured in the loop interface. The operation steps are the same as those in the scheduler. The difference is that the script file ifcfg-lo of the lo interface is copied, the saved file name is ifcfg-lo: 0. the configuration content is as follows:
2) modify the system configuration and enable/etc/sysctl. in the conf file, modify the following configuration items. if not, add them to the file, as shown in (the first two configuration items are flexibly configured based on different network interfaces. here I am eth1 ):
Save and run the sysctl-p command to make the configuration take effect or restart the system.
3) modify the server configuration so that the server listening address is VIP (192.168.9.191), that is, the address on the lo: 0 interface.
4) disable iptables and SElinux.