Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A case introduction to LVS load balancing Cluster

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following is a brief introduction to the case of LVS Load Balancer Cluster. I hope it can bring some help to you in practical application. Load Balancer involves many things, but there are not many theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to make an answer.

1. Case profile 1. Case environment

2. Experimental results

Using NAT mode clustering technology, the LVS Load Scheduler is the gateway for all nodes to access the Internet. The Cloud Virtual Machine has 192.168.200.10 as the VIP address for the entire cluster.

Scheduling algorithm using round robin (rr).

web1 and web2 first build web services, prepare different web pages for client access, so as to determine that the client accesses 192.168.200.10 of the LVS server, and can access two web servers.

After the client test is successful, web1 and web2 can mount the shared directory provided by the NFS server to provide the same web file for the client. 2. Start building replication balanced cluster 1. Deploy Web1 server: [root@centos01 ~]# yum -y install httpd [root@centos01 ~]# echo "www.benet.com" >/var/www/html/index. html [root@centos01 ~]# systemctl start httpd [root@centos01 ~]# systemctl enable httpd [root@centos01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32 GATEWAY=192.168.100.40 [root@centos01 ~]# systemctl restart network2. Deploy Web2 server: [root@centos02 ~]# yum -y install httpd [root@centos02 ~]# echo "www.accp.com" > /var/www/html/index.html [root@centos02 ~]# systemctl start httpd [root@centos02 ~]# systemctl enable httpd [root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32 GATEWAY=192.168.100.40 [root@centos02 ~]# systemctl restart network 3. Deploy gateway/LVS server: [root@centos04 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens34 [root@centos04 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens34 TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=staticDEFROUTE=yesNAME=ens34 DEVICE=ens34 ONBOOT=yesIPADDR=192.168.200.10 NATEMASK=255.255.255.0[root@centos04 ~]# systemctl restart network [root@centos04 ~]# vim /etc/sysctl.conf net.ipv4.ip_forward = 1[root@centos04 ~]# sysctl -p net.ipv4.ip_forward = 1[root@centos04 ~]# modprobe ip_vs [root@centos04 ~]# yum -y install ipvsadm[root@centos04 ~]# ipvsadm -C [root@centos04 ~]# ipvsadm -A -t 192.168.200.10:80 -s rr [root@centos04 ~]# ipvsadm -a -t 192.168.200.10:80 -r 192.168.100.10:80 -m -w 1 [root@centos04 ~]# ipvsadm -a -t 192.168.200.10:80 -r 192.168.100.20:80 -m -w 1 [root@centos04 ~]# ipvsadm-save -A -t centos04:http -s rr-a -t centos04:http -r 192.168.100.10:http-m -w 1-a -t centos04:http -r 192.168.100.20:http -m -w 1[root@centos04 ~]# ipvsadm-save > /etc/sysconfig/ipvsadm.bak[root@centos04 ~]# cat/etc/sysconfig/ipvsadm. bak-A -t centos04:http -s rr-a -t centos04:http -r 192.168.100.20:http -m -w 1-a -t centos04:http-r 192.168.100.10: http-m -w 14. Configure client

1) Client configuration IP address

2) Test whether the LVS Load Balancer server works normally (visit 192.168.200.10 several times and you can get two different pages):

5. Configure NFS shared storage [root@centos03 ~]# yum -y install nfs-utils rpcbind [root@centos03 ~]# systemctl enable nfs [root@centos03 ~]# systemctl enable rpcbind [root@centos03 ~]# mkdir -p /opt/wwwroot [root@centos03 ~]# echo "www.wangyi.com" > /opt/wwwroot/index.html [root@centos03 ~]# vim /etc/exports /opt/wwwroot 192.168.100.0/24(rw,sync,no_root_squash) [root@centos03 ~]# systemctl restart rpcbind [root@centos03 ~]# systemctl restart nfs [root@centos03 ~]# showmount -e Export list for centos03:/opt/wwwroot 192.168.100.0/241) Web server 1 mount shared directory [root@centos01 ~]# yum -y install rpcbind nfs-utils[root@centos01 ~]# systemctl enable rpcbind [root@centos01 ~]# systemctl start rpcbind [root@centos01 ~]# showmount -e 192.168.100.30 Export list for 192.168.100.30:/opt/wwwroot 192.168.100.0/24[root@centos01 ~]# mount 192.168.100.30:/opt/wwwroot /var/www/html/ [root@centos01 ~]# df -hT /var/www/html/file system Type Capacity used Available % Mount point 192.168.100.30:/opt/wwwroot nfs4 76G 3.7G 73G 5% /var/www/html[root@centos01 ~]# vim /etc/fstab 192.168.100.30:/opt/wwwroot /var/www/html nfs defaults,_netdev 0 02) Web server 2 mount shared directory [root@centos02 ~]# yum -y install rpcbind nfs-utils [root@centos02 ~]# systemctl enable rpcbind [root@centos02 ~]# systemctl start rpcbind [root@centos02 ~]# showmount -e 192.168.100.30 Export list for 192.168.100.30:/opt/wwwroot 192.168.100.0/24[root@centos02 ~]# mount 192.168.100.30:/opt/wwwroot /var/www/html/ [root@centos02 ~]# df -hT /var/www/html/file system Type Capacity used Available % Mount point 192.168.100.30:/opt/wwwroot nfs4 76G 3.7G 73G 5% /var/www/html[root@centos02 ~]# vim /etc/fstab 192.168.100.30:/opt/wwwroot /var/www/html nfs defaults,_netdev 0 06, Client access

No matter how you refresh your visit, you will see the same page. The final LVS Load Balancer effect is achieved.

When the LVS server restarts, the LVS rules will be lost, which uses backup. It should be noted that the host name at the time of backup must be consistent with the host name at the time of recovery, and attention should be paid to the problem of network card priority. Otherwise, after recovery, it will be found that VIP (virtual IP of the cluster) becomes another IP address of the LVS server.

[root@centos04 ~]# ipvsadm -ln IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn[root@centos04 ~]# ipvsadm-restore

< /etc/sysconfig/ipvsadm.bak [root@centos04 ~]# ipvsadm -ln IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags ->

RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 192.168.100.40:80 rr -> 192.168.100.10:80 Masq 1 0 0 -> 192.168.100.20:80 Masq 1 0 0

After reading the above brief introduction about LVS Load Balancer Cluster, if you still have anything to know, you can find something you are interested in the industry information or find our professional technical engineers to answer. Technical engineers have more than ten years of experience in the industry.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report