Installation and use of ipvs,ipvsadm
Ipvs installation:
Check whether lvs:lsmod is installed | grep ip_vs (check whether the ipvs module is loaded successfully)
Install lvs
Method 1:
You can install yum directly in the production environment.
# yum install ipvsadm-y
Ipvsadm is a tool for managing ipvs
Method 2:
After keepalived is installed and keepalived is started, ip_vs will automatically install and load
Load the ip_vs module into the kernel
# ipvsadm (this is the command to load the ip_vs module)
# lsmod | grep ip_vs (check whether the ipvs module is loaded successfully
Ipvs's cluster service:
Tcp,udp,ah,esp,ah_esp,stcp
(1) An ipvs host can define multiple cluster service at the same time.
(2) there should be at least one real server on a cluster service:
When defining, specify lvs-type, and lvs scheduler
The usage of ipvsadm:
Manage cluster services:
Ipvsadm-A | E-t | u | f service-address [- s scheduler] [- p [timeout]]
-A: add a cluster
-D: delete the cluster
-E: modify the cluster
-C: clear the cluster
Example: add a lvs cluster
# ipvsadm-A-t 192.168.0.198 80-s rr
-t: follow up with IP and port (in fact, client-oriented VIP)
-s: specify the algorithm
Example: delete a cluster
# ipvsadm-D-t 192.168.50.199pur80
Service-address: cluster IP address
Tcp:-t ip:port
Udp:-u ip:port
Fwm:-f mark
-s scheduler: default is wlc
-p: implements session persistence. The default time is 360 seconds.
Manage the RS in the cluster:
Ipvsadm-a | e-t | u | f service-address-r server-address [- g | I | m] [- w weight]
Example: add a node to the cluster
# ipvsadm-a-t 192.168.0.199virtual 80-r 192.168.0.164purl 80-g
-t: specify which lvs to add RS to
-r: specify the real hosts to join the lvs cluster, and add ports
-g: specify as director rout, and this mode is also the default
Ipvsadm-d-t | u | f service-address-r server-address
Example: delete a node in the cluster
# ipvsadm-d-t 192.168.50.199Viru 80-r 192.168.50.164RV 80
Service-address: real host address
Ip [: port]
Lvs-type:
-gpurgateway.dr (default to this model)
-iRank ipiptide tun
-mlug masquerade.mat.
Clear and view:
Ipvsadm-C
Ipvsadm-L | l [options]
-n:numric, which displays the address port based on the numeric format (InActConn represents the number of calls to the back-end RS)
-c:connection, showing the ipvs connection
# ipvsadm-Lnc / / shows all connections being established, including which backend server to connect to
-- stats: the sum of statistics for all kinds of information
-- rate: rate statistics
-- exact: displays the exact value without unit conversion
Save and reload:
Ipvsadm-R
Ipvsadm-S [- n]
Set zero counter:
Ipvsadm-Z [- t | u | f service-address]
Set the timeout:
Usage:-- set tcp tcpfin udp set connection timeout values
Example: ipvsadm-set 30 5 60