我要评分
获取效率
正确性
完整性
易理解

General Operations

ipvsadm is a command line tool for configuring and managing LVS. It allows administrators to add, edit, and delete cluster services and real servers (RSs) in the cluster.

ipvsadm Operations on a Cluster

Basic syntax:

1
ipvsadm -A|E|D -t|u|f  director_addr:port [-s scheduler] [-p [timeout]]

Table 1 describes the parameters.

Table 1 Parameters for ipvsadm to perform operations on a cluster

Parameter

Description

-A

Adds a cluster service.

-E

Edits a cluster service.

-D

Deletes a cluster service. For example, run ipvsadm -D -t 10.1.0.5:80.

-t

Indicates the TCP protocol service.

-u

Indicates the UDP protocol service.

-f

Indicates the firewall mark, which binds two or more services as a service for processing. It is a number.

director_addr

Indicates the virtual IP address (VIP).

-s

Indicates the scheduling algorithm.

If not specified, WLC is used by default. The available scheduling algorithms are as follows: RR (round robin), WRR (weighted round robin), SH (source hashing), DH (destination hashing), LC (least connections), WLC (weighted least connections), SED (shortest expected delay), NQ (never queue), LBLC (locality-based least connections), and LBLCR (locality-based least connections ratio).

-p

Enables the persistent connection function of LVS. If the timeout interval is specified, the default value is 300s.

service-address

Indicates the IP address and port number of the LVS server. The format is IP:port. The port type is specified by -t, -u, or -f.

For example, you can run the following command to add a cluster service that operates in the firewall mark mode to the LVS cluster and specify WRR as the scheduling algorithm.

1
ipvsadm -A -f 11 -s wrr

In the preceding command, 11 is set using the iptables xxxx -j MARK --set-mark 11 command. Similarly, you can group traffic from ports 80 and 443 under the same mark and use ipvsadm to balance the load.

ipvsadm Operations on the RS

Basic Syntax

1
ipvsadm -a -t|u|f director_addr:port -r RS_addr -[g|i|m] [-w weight]

Table 2 describes the parameters.

Table 2 Parameters of ipvsadm operations on the RS

Parameter

Description

-a

Adds an RS.

-e

Modifies an RS.

-d

Deletes an RS.

-r

Indicates the RS IP address and port number. The format is IP[:port].

-g

Indicates the direct routing (DR) mode. If not specified, the DR mode is used by default.

-m

Indicates the network address translation (NAT) mode.

-i

Indicates the IP tunneling (TUN) mode.

-w

Defines the weight. This parameter applies only to algorithms that support weights. For algorithms such as RR and LC, which do not support weights, this parameter has no effect.

More Command Rules

Rule

Command

Description

Display rules

-L or l

Displays the current LVS rule.

-n or --numeric

Displays the host IP address and port number in numeric format, without reverse resolution of the IP address and port number.

--exact

Displays the exact value.

--stats

Displays statistics.

--rate

Displays the rate.

--timeout

Displays the timeout periods of the TCP, TCP FIN, and UDP sessions.

--sort

Displays the current IPVS connections, sorted by connection count.

-c or --connection

Checks the number of connections.

Clear rule

ipvsadm -C

Clears all LVS rules.

Save rule

ipvsadm -S

Default standard output, which can be redirected to a specified file.

ipvsadm-save

Default standard output, which can be redirected to a specified file.

systemctl stop ipvsadm.service

When the ipvsadm service is stopped, rules are automatically saved. The default save path is /etc/sysconfig/ipvsadm.

Import rules

ipvsadm -R < /saved_file

Restores LVS rules from a specified file.

  

ipvsadm-restore < /saved_file

Restores LVS rules from a specified file.