1. Cluster classification
*
Load balancing cluster: such as nginx (solving high concurrency)
*
High-availability cluster: such as MHA, MMM
*
High-performance cluster, using more computing services
2. Load balancing cluster
* LVS:linux virtual service (linux虚拟服务)
3. The difference between nginx and LVS
*
nginx:
*
Do 7-layer load, four-layer load can also be done through the module
*
Only load balance for web and mail
*
LVS:
*
Do 4-layer load, forwarding traffic to achieve load balancing
*
You can do load balancing for any service, such as mysql load balancing can’t use nginx, you can use lvs
4. LVS working mode
*
NAT: address translation
*
DR: direct routing
*
TUN: IP tunnel
*
FULL-NAT
*
ENT
ps:
*
SNAT: source IP
*
DNAT: destination IP
5. LVS scheduling algorithm
*
rr: round-robin
*
wrr: weighted round-robin
*
lc: minimum connection (allocate to whomever has the least number of connections)
*
wlc: weighted minimum link (distribute connections in proportion)
*
blc, blcr, dh, sh, sed, nq
6. LVS-NAT is to use DNAT mode
*
Advantages: Security, all requests go through the LVS server
*
Disadvantages: LVS is under pressure
7. modprobe loads the kernel module
*
modprobe ip_vs
*
lsmod | grep ip_vs view
*
cat /proc/modules | grep ip_vs view
8. ipvsadm option
*
-A: specify virtual server address (vip)
*
-a: add real server
*
-E: edit virtual server
*
-D: delete virtual server
*
-s: specify scheduling algorithm (rr, wrr, lc, wlc, blc, blcr, dh, sh, sed, nq)
*
-w: designated weight
*
-g: designated mode DR
*
-i: designated mode TUN
*
-m: designated mode NAT
*
-r: designated real server address
*
-t: tcp protocol
*
-u: udp protocol
*
-c: connection status display
9. LVS-NAT implementation key points:
*
LVS server has dual network cards, internal network and external network
* The
gateway address of the real server points to the address of the LVS internal network card
10. The concrete realization of LVS-NAT
- Need three servers, one LVS host, two apache
- First, configure the network card of the two apache hosts to host-
only mode, then power on and modify the network card configuration file
vim /etc/sysconfig/network-scripts/ifcfg-ens33.
Note that the gateway address needs to be set to the LVS internal network card IP. Second An apache host also performs copper sleeve operations. - Modify the LVS server network
card. One network card is the host only (internal network IP), and the other is in bridge mode (external network).
- Install httpd service on two apache machines
[root@apache1 ~]# yum -y install httpd
[root@apache1 ~]# systemctl start httpd
[root@apache1 ~]# echo “apache111111”> /var/www/html/index. html
[root@apache2 ~]# echo "apache22222222"> /var/www/html/index.htmlAccess
test
- LVS host install ipvsadm
[root@lvs ~]# yum -y install ipvsadm
[root@lvs ~]# ipvsadm -A -t 192.168.10.74:80 -s rr //设置虚拟服务
[root@lvs ~]# ipvsadm -a -t 192.168.10.74:80 -r 192.168.8.20:80 -m -w 1 //添加地址转换
[root@lvs ~]# ipvsadm -a -t 192.168.10.74:80 -r 192.168.8.21:80 -m -w 1 //添加地址转换
Note: In CentOS7, restarting the ipvsadm service will report an error, and restarting the service after the rule is created will cause loss.
The method to solve the above problems:
ipvsadm -s > /etc/sysconfig/ipvsadm
servicectl restart ipvsadm 成功。
[root@lvs ~]# ipvsadm -l -n //查看设置的规则
6. Enable routing and forwarding function
[root@lvs ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p view
- Access test
[root@lvs ~]# ipvsadm -L -c -n //查看连接状态