In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The following brings you LVS load balancing-keepalived content and configuration introduction, hope to give you some help in practical application, load balancing involves more things, there are not many theories, there are many books online, today we use the accumulated experience in the industry to do an answer.
Main points of content:
1. Keepalived:
Second, configuration steps:
1. Keepalived:
(1) what is keepalived
Keepalived is a service software that ensures the high availability of clusters in cluster management. Its function is similar to heartbeat and is used to prevent single point of failure.
1. Three core modules of keepalived:
Core core module
Chech health monitoring
Vrrp Virtual routing redundancy Protocol
2. Three important functions of Keepalived service:
Manage LVS
Check the LVS cluster node
High availability as a system network service
(2) working principle of keepalived
1. Keepalived is based on VRRP protocol. The full name of VRRP is Virtual Router Redundancy Protocol, that is, virtual routing redundancy protocol.
2. Virtual routing redundancy protocol can be considered as a protocol to achieve high availability of routers, that is, N routers with the same function form a router group, in which there is a master and multiple backup,master with a vip providing external services (the default route of other machines in the local area network of the router is the vip). Master sends multicast, and when the backup does not receive the vrrp packet, it is considered that the master is down. At this point, you need to choose a backup as master according to the priority of VRRP. In this way, the high availability of the router can be ensured.
3. Keepalived has three main modules, which are core, check and vrrp. Core module is the core of keepalived, which is responsible for the startup and maintenance of the main process as well as the loading and parsing of global configuration files. Check is responsible for health check-ups, including common check-ups. The vrrp module is used to implement the VRRP protocol.
Second, configuration steps:
Lab environment description:
(1) prepare four virtual machines, two for scheduling cloud servers and two for node servers
(2) the scheduling server deploys LVS and keepalived to achieve load balancing and dual-server hot backup
(3) the client host can access the web page of the background Web server through the virtual ip address.
(4) the experimental results verify that one of the DR is down, the access is normal, and all services are running as usual.
Role IP address scheduling server DR1 (primary) 192.168.100.201 scheduling server DR2 (standby) 192.168.100.202 node server web1192.168.100.221 node server web2192.168.100.222 virtual IP192.168.100.10 client test machine win7192.168.100.50
Step 1: configure two DR
(1) install ipvsadm and keepalived packages
Yum install ipvsadm keepalived-y
(2) modify the / etc/sysctl.conf file and add the following code:
Net.ipv4.ip_forward=1//proc response to turn off the redirect function net.ipv4.conf.all.send_redirects = 0net.ipv4.conf.default.send_redirects = 0net.ipv4.conf.ens33.send_redirects = 0sysctl-p this command is to make the above configuration take effect
(3) configure virtual network card (ens33:0):
1. Note the path: / etc/sysconfig/network-scripts/
2. Directly copy the existing Nic information and modify it:
Cp ifcfg-ens33 ifcfg-ens33:0vim ifcfg-ens33:0 deletes all the original information and adds the following code: DEVICE=ens33:0ONBOOT=yesIPADDR=192.168.100.10NETMASK=255.255.255.0
3. Enable the virtual network card:
Ifup ens33:0
(4) write the service startup script, path: / etc/init.d
1. The content of vim dr.sh script is as follows:
#! / bin/bashGW=192.168.100.1VIP=192.168.100.10RIP1=192.168.100.221RIP2=192.168.100.222case "$1" instart) / sbin/ipvsadm-- save > / etc/sysconfig/ipvsadm systemctl start ipvsadm / sbin/ifconfig ens33:0$ VIP broadcast $VIP netmask 255.255.255.255 broadcast $VIP up / sbin/route add-host $VIP dev ens33:0 / sbin/ipvsadm-A-t $VIP:80-s rr / sbin/ipvsadm-a-t $VIP:80-r $RIP1:80-g / sbin/ipvsadm-a-t $VIP:80-r $RIP2:80-g echo "ipvsadm starting- [ok]" ; stop) / sbin/ipvsadm-C systemctl stop ipvsadm ifconfig ens33:0 down route del $VIP echo "ipvsamd stoped- [ok]" Stop) / sbin/ipvsadm-C systemctl stop ipvsadm ifconfig ens33:0 down route del $VIP echo "ipvsamd stoped- [ok]";; status) if [!-e ar/lock/subsys/ipvsadm] Then echo "ipvsadm stoped-" exit 1 else echo "ipvsamd Runing- [ok]" fi;; *) echo "Usage: $0 {start | stop | status}" exit 1 esac exit 0
2. Add permissions and start the script
Chmod + x dr.shservice dr.sh start
(5) the configuration of the second DR is exactly the same as that of the first. You can repeat the operation.
Step 2: configure the first node server web1
(1) install httpd
Yum install httpd-y
Systemctl start httpd.service / / enable the service
(2) write a test page on the site, and it will be convenient to verify the test results later.
Path: / var/www/htmlecho "this is accp web" > index.html
(3) create a virtual network card
1. Path: / etc/sysconfig/network-scripts/2, copy the Nic information to modify cp ifcfg-lo ifcfg-lo:03, vim ifcfg-lo:0 delete all the original information, and add the following: DEVICE=lo:0IPADDR=192.168.100.10NETMASK=255.255.255.0ONBOOT=yes
(4) write the service startup script, path: / etc/init.d
1. The content of vim web.sh script is as follows:
#! / bin/bashVIP=192.168.100.10 case "$1" in start) ifconfig lo:0$ VIP netmask 255.255.255.255 broadcast $VIP / sbin/route add-host $VIP 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/lo/arp_ignore echo "2" > / proc/sys/net/ipv4/conf/lo/arp_announce sysctl-p > / dev/null 2 > & 1 echo "RealServer Start OK" Stop) ifconfig lo:0 down route del $VIP / dev/null 2 > & 1 echo "0" > / proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" > / proc/sys/net/ipv4/conf/lo/arp_announce echo "0" > / proc/sys/net/ipv4/conf/all/arp_ignore Echo "0" > / proc/sys/net/ipv4/conf/all/arp_announce echo "RealServer Stoped" ; *) echo "Usage: $0 {start | stop}" exit 1 esac exit 0
2. Add permissions and execute
Chmod + x web.sh / / add permissions service web.sh start / / start the service
(5) enable virtual network card
Ifup lo:0
(6) Test whether the web page is normal or not
Step 3: configure the second node server web2
The configuration of the second web is exactly the same as that of the first, except that in order to distinguish the experimental results, the content of the test page of the second has been changed:
Path: / var/www/htmlecho "this is benet web" > index.html
Test whether the web page is normal:
Step 4: client testing
(1) configure the IP address of the client
(2) Test
1. Can it be interconnected with 192.168.100.10:
2. Whether it is normal to visit the web page
Step 5: deploy keepalived
First, deploy on the first DR:
(1) modify the keepalived.conf file, path / etc/keepalived/
Modify the following:
(2) start the service
Systemctl start keepalived.service
Second, deploy on the second DR:
(1) modify keepalived.conf file
(2) start the service
Systemctl start keepalived.service
Step 6: verify the experimental results
Due to the deployment of LVS and keepalived, the purpose is to load balancing and dual hot backup.
At this point, we simulate the failure and shut down one of the DR1. If the client can still communicate with the virtual IP address and visit the website normally, it means that DR2 will work instead of DR1, and the effect of preventing single point of failure has been achieved.
(1) Fault simulation: shutting down DR1
Ifdown ens33:0
(2) result verification
1. Ping the virtual ip on the client side.
2. The website is still accessible.
After reading the above introduction to the content and configuration of LVS load balancing-keepalived, if you have anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers for answers. 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.