LVS (Linux Virtual Server) is a load balancing technology based on Linux operating system. It distributes client requests to multiple actual servers through network load balancing technology to improve the performance and reliability of the system.
In LVS, the commonly used command line tools are mainly ipvsadm, as well as some related auxiliary commands and parameters.
The following is a detailed introduction to the LVS command line tool:
1. ipvsadm command
ipvsadm is the core command of LVS, used to configure and manage IPVS (IP Virtual Server) rules.
The following are some commonly used ipvsadm commands and their parameters:
-
Add a virtual server
- ipvsadm -A -t [vip:port] -s [scheduler]: Add a new virtual server, where vip:port is the IP address and port number of the virtual server, and scheduler is a load balancing algorithm (such as rr, wrr, etc.).
-
Delete the virtual server
- ipvsadm -D -t [vip:port]: Delete an existing virtual server.
-
Edit the virtual server
- ipvsadm -E -t [vip:port] -s [scheduler]: Edit an existing virtual server, which can change its load balancing algorithm and other parameters.
-
List virtual servers
- ipvsadm -L -n: Lists all virtual servers currently configured, and the -n parameter indicates that the IP port is displayed in digital form.
-
Add a real server
- ipvsadm -a -t [vip:port] -r [rip:port] -g|-m|-i: Add a new real server to a virtual server, where rip:port is the IP address and port number of the real server, and -g|-m|-i specifies the working mode of LVS (DR, NAT, TUN).
-
Delete the real server
- ipvsadm -d -t [vip:port] -r [rip:port]: Delete a real server from the virtual server.
-
Edit the real server
- ipvsadm -e -t [vip:port] -r [rip:port] -g|-m|-i (Note: There is no direct command to edit the real server in the regular usage of ipvsadm, and it usually needs to be deleted first and then added again): The parameters of the real server, such as weights, etc. can be modified. But the more common practice is to delete the old real server first and then add a new real server.
-
Clear the configuration
- ipvsadm -C: Clear all virtual server and real server configurations.
-
Show connection information
- ipvsadm -L -c: Displays the connection information in the current IPVS, including the number of connections to each real server, etc.
-
Reset the counter
- ipvsadm -Z: Reset statistics of forwarded messages.
- Set persistence time
- ipvsadm --persistent -p [timeout]: Set up a persistent and stable service. Multiple requests from the same client will be processed by the same real server, and timeout is the persistence time.
-
Set the connection timeout time
- ipvsadm --set tcp tcpfin udp [timeout]: Set the timeout time for TCP, TCPFIN and UDP connections.
-
Display statistics
- ipvsadm --stats: Displays statistics (accumulated value) of historical forwarded messages.
-
Display rate information
- ipvsadm --rate: Display forwarding rate information (instantaneous value).
2. Auxiliary commands
In addition to the ipvsadm command, there are some auxiliary commands that can be used to view and manage the configuration and status of LVS:
-
lvs command
- lvs -a: Displays all LVS cluster information.
- lvs -s: Displays statistics of the LVS cluster.
- lvs -c: Displays configuration information of the LVS cluster.
- lvs --all: Displays all service and node information.
-
Other commands
- ifconfig and route commands: used to configure and manage network interfaces and routing tables. These are the basic commands for configuring the LVS network environment.
- iptables command: used to configure and manage Linux firewalls, can be used to set NAT rules, etc. to support NAT mode of LVS.
- cat /proc/net/ip_vs_stat: View the status information of IPVS, including various connection and forwarding statistics.
3. Use examples
Here is an example of configuring LVS using the ipvsadm command:
- Add a virtual server with IP address 192.168.1.100 and port 80, using the polling (rr) scheduling algorithm:
ipvsadm -A -t 192.168.1.100:80 -s rr
- Add two real servers to this virtual server, with IP addresses of 192.168.1.101 and 192.168.1.102, and ports are both 80. Use direct routing (DR) mode:
ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.101:80 -g ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.102:80 -g
- Check the current LVS configuration:
ipvsadm -L -n
- Delete a real server:
ipvsadm -d -t 192.168.1.100:80 -r 192.168.1.101:80
- Clear all LVS configurations:
ipvsadm -C
Through the above commands, the LVS load balancer can be easily configured and managed to achieve high-performance and scalable network load balancing.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.