In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use ipvsadm to configure LVS cluster in Linux". In daily operation, I believe many people have doubts about how to use ipvsadm to configure LVS cluster in Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to use ipvsadm to configure LVS cluster in Linux". Next, please follow the editor to study!
There are three configuration modes of LVS cluster: DR, TUN and NAT, which can be used as load balancer for www service, FTP service, MAIL service and so on. The following describes the configuration of LVS cluster based on DR mode by building a load balancing instance of www service.
I. configuration of Director Server
There are two ways to configure a LVS load balancer cluster on Director Server:
a. Configure through the ipvsadm command line
b. Configure LVS through piranha, a tool provided by Redhat
Configure LVS through the ipvsadm command line
After installing IPVS, you can configure the LVS cluster. First, bind a virtual IP (also known as VIP) to the Director Server. This IP is used to provide services. Execute the following command:
The code is as follows:
[root@localhost ~] # ifconfig eth0:0 192.168.60.200 broadcast 192.168.60.200 netmask 255.255.255.255 up
Here, a virtual device eth0:0 is bound to the eth0 device, and a virtual IP is set to 192.168.60.200, which is the IP address we planned above, and then the broadcast address is also 192.168.60.200. It is important to note that the subnet mask here is 255.255.255.255.
Then assign a route to the device eth0:0 and execute the following instructions:
The code is as follows:
[root@localhost ~] # route add-host 192.168.60.200 dev eth0:0
The packet forwarding function of the system is then enabled so that the system acts as a router and executes the following instructions:
The code is as follows:
[root@localhost ~] # echo "1" > / proc/sys/net/ipv4/ip_forward
In the directive, ip forwarding is enabled when the parameter value is 1, and ip forwarding is disabled when it is 0. In fact, it is not necessary to turn on the packet forwarding function of the system in DR mode, but it is necessary in NAT mode.
Then start configuring ipvs and do the following:
The code is as follows:
[root@localhost] # ipvsadm-C
[root@localhost] # ipvsadm-A-t 192.168.60.200 rr 80-s rr-p 600
[root@localhost] # ipvsadm-a-t 192.168.60.200 80-r 192.168.60.132
[root@localhost] # ipvsadm-a-t 192.168.60.200 80-r 192.168.60.144V 80-g
In the above operation, the first line clears all records from the kernel virtual server list, and the second line adds a new virtual IP record. The new IP is 192.168.60.200, with a specified duration of 600 seconds. The third and fourth lines add two new IP records to the new virtual Real Server record, and specify that the working mode of the LVS is direct routing mode.
Finally, start the LVS service and do the following:
The code is as follows:
[root@localhost ~] # ipvsadm
In this way, the configuration of LVS on Director Server is complete.
For the convenience of management and configuration, you can write a script file for the above operations. The script content is as follows:
The code is as follows:
#! / bin/bash
VIP=192.168.60.200
RIP1=192.168.60.132
RIP2=192.168.60.144
GW=192.168.60.1
# set the Virtual IP Address
/ sbin/ifconfig eth0:0$ VIP broadcast $VIP netmask 255.255.255.255 up
/ sbin/route add-host $VIP dev eth0:0
Echo "1" > / proc/sys/net/ipv4/ip_forward
# Clear IPVS table
/ sbin/ipvsadm-C
# set LVS
/ sbin/ipvsadm-A-t $VIP:80-s rr-p 600
/ sbin/ipvsadm-a-t $VIP:80-r $RIP1:80-g
/ sbin/ipvsadm-a-t $VIP:80-r $RIP2:80-g
# Run LVS
/ sbin/ipvsadm
# end
It can also be written as a service script that can be started and stopped, as follows:
The code is as follows:
#! / bin/sh
# description: Start LVS of Director server
VIP=192.168.60.200
RIP1=192.168.60.132
RIP2=192.168.60.144
. / etc/rc.d/init.d/functions
Case "$1" in
Start)
Echo "start LVS of Director Server"
# set the Virtual IP Address and sysctl parameter
/ sbin/ifconfig eth0:0$ VIP broadcast $VIP netmask 255.255.255.255 up
Echo "1" > / proc/sys/net/ipv4/ip_forward
# Clear IPVS table
/ sbin/ipvsadm-C
# set LVS
/ sbin/ipvsadm-A-t $VIP:80-s rr-p 600
/ sbin/ipvsadm-a-t $VIP:80-r $RIP1:80-g
/ sbin/ipvsadm-a-t $VIP:80-r $RIP2:80-g
# Run LVS
/ sbin/ipvsadm
Stop)
Echo "close LVS Directorserver"
Echo "0" > / proc/sys/net/ipv4/ip_forward
/ sbin/ipvsadm-C
/ sbin/ifconfig eth0:0 down
*)
Echo "Usage: $0 {start | stop}"
Exit 1
Esac
Name this script the lvsDR file, then put the file under / etc/init.d, and execute:
The code is as follows:
[root@localhost ~] # chomd 755 / etc/init.d/lvsDR
Finally, you can start or stop the LVS service with the following command:
The code is as follows:
Service lvsDR {start | stop}
At this point, the command line configuration of Director Server is complete.
II. Configuration of Real server
In lvs's DR and TUn mode, when a user's access request reaches the real server, it is returned directly to the user instead of going through the front-end Director Server. Therefore, a virtual VIP address needs to be added on each Real server node so that the data can be returned directly to the user. The operation of increasing the VIP address can be achieved by creating a script to create a file / etc / init.d/lvsrs, which contains the following contents:
The code is as follows:
#! / bin/bash
VIP=192.168.60.200
/ sbin/ifconfig lo:0$ VIP broadcast $VIP netmask 255.255.255.255 up
/ 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/all/arp_ignore
Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce
Sysctl-p
# end
This operation binds a virtual IP address on the loopback device, sets its subnet mask to 255.255.255.255, maintains interconnection with the virtual IP on the Director Server, and then disables native ARP requests.
The usage and format of the PS:ipvsadm command are as follows:
Ipvsadm-A | E-t | u | f virutal-service-address:port [- s scheduler] [- p [timeout]] [- M netmask]
Ipvsadm-D-t | u | f virtual-service-address
Ipvsadm-C
Ipvsadm-R
Ipvsadm-S [- n]
Ipvsadm-a | e-t | u | f service-address:port-r real-server-address:port
[- g | I | m] [- w weight]
Ipvsadm-d-t | u | f service-address-r server-address
Ipvsadm-L | l [options]
Ipvsadm-Z [- t | u | f service-address]
Ipvsadm-set tcp tcpfin udp
Ipvsadm-- start-daemon state [--mcast-interface interface]
Ipvsadm-stop-daemon
Ipvsadm-h
Command options explain:
There are two command option formats, long and short, with the same meaning. In practical use, both are fine.
-A-- add-service adds a new virtual server record to the virtual server table in the kernel. That is to add a new virtual server.
-E-- edit-service edits a virtual server record in the kernel virtual server table.
-D-- delete-service deletes a virtual server record in the kernel virtual server table.
-C-- clear clears all records in the kernel virtual server table.
-R-- restore restore virtual server rules
-S-- save saves virtual server rules and outputs them in a readable format with the-R option
-a-- add-server adds a new real server record to a record in the kernel virtual server table. That is, to add a new real server to a virtual server.
-e-- edit-server edits a real server record in a virtual server record
-d-- delete-server deletes a real server record from a virtual server record
-L |-l-- list displays the kernel virtual server table
-Z-- zero virtual service table counter is cleared (clear the current number of connections, etc.)
-- set tcp tcpfin udp sets connection timeout value
Start-daemon starts the synchronization daemon. It can be followed by master or backup to indicate whether LVS Router is aster or backup. The VRRP function of keepalived can also be used in this function.
-- stop-daemon stops the synchronization daemon
-h-- help displays help information
Other options:
-t-- tcp-service service-address indicates that the virtual server provides tcp services [vip:port] or [real-server-ip:port]
-u-- udp-service service-address indicates that the virtual server provides udp services [vip:port] or [real-server-ip:port]
-f-- the fwmark-service fwmark description is a service type marked by iptables.
-s-the scheduling algorithm used by scheduler scheduler. There are several options: rr | wrr | lc | wlc | lblc | lblcr | dh | sh | sed | nq. The default scheduling algorithm is: wlc.
-p-- persistent [timeout] durable service. This option means that multiple requests from the same customer will be processed by the same real server. The default value for timeout is 300 seconds.
-M-- netmask netmask persistent granularity mask
-r-- real-server server-address real server [Real-Server:port]
-g-- gatewaying specifies that the operating mode of LVS is direct routing mode (which is also the default mode of LVS)
-I-- ipip specifies that the operating mode of LVS is tunnel mode
-m-- masquerading specifies that the operating mode of LVS is NAT mode
-w-- the weight of the weight weight real server
-- mcast-interface interface specifies the synchronization interface of multicast
-c-- connection shows LVS's current connections such as: ipvsadm-L-c
-- timeout displays the timeout value of tcp tcpfin udp, such as: ipvsadm-L-- timeout
-- daemon displays the status of the synchronous daemon
-- stats displays statistics
-- rate displays rate information
-- sort sorts the output of virtual servers and real servers
-- numeric-n output numeric form of IP address and port
At this point, the study on "how to configure LVS clusters with ipvsadm in Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.