Linux cluster (iii)-IPVSADM tools

Source: Internet
Author: User

What is Ipvsadm?

LVS consists of two parts composed of Ipvs and Ipvsadm, Ipvs is the core implementation of LVS need to use the management tool IPVSADM define the LVS cluster rules, Ipvs to work according to the defined rules.

Related documents for Ipvsadm
服务名:         ipvsadm.service主程序:        /usr/sbin/ipvsadm规则保存工具:  /usr/sbin/ipvsadm-save规则重载工具:  /usr/sbin/ipvsadm-restore配置文件:      /etc/sysconfig/ipvsadm-config
IPVSADM Syntax Management Cluster service
ipvsadm -A|E -t|u|f service-address:port [-s scheduler] [-p [timeout]]-A  创建一个LVS集群-E  修改一个LVS集群-C  清空LVS规则-R  重载LVS规则,重载规则时需要利用重定向<-S  保存-Z  清空计数器-L  查看LVS规则    -n:        以数字形式输出地址和端口号    --exact:   扩展信息,精确值    -c:        当前IPVS连接输出    --stats:   统计信息    --rate :   输出速率信息ipvsadm -D -t|u|f service-address-D  删除service-address:    -t|u|f:创建LVS集群服务为tcp/udp/firewall mark服务    -t: TCP协议的端口,VIP:TCP端口    -u: UDP协议的端口,VIP:UDP端口    -f:firewall MARK,标记,一个数字[-s scheduler]:指定集群的调度算法,默认为wlc(加权最少链路)
Managing Realserver on a Cluster service
ipvsadm -a|e -t|u|f service-address -r server-address [-g|i|m] [-w weight]server-address:格式:rip[:port] 如省略port,不作端口映射-a  添加一个RealServer到集群中。-d  删除一个RealServer服务器-r  指定将要添加的Realserver的IP地址。-m  表示LVS集群的工作模式为LVS-NAT模式-g  表示LVS集群的工作模式为LVS-DR模式,默认-i  表示LVS集群的工作模式为LVS-TUN模式-w  权重
Instance

Topology diagram

Lvs-nat Cluster

1. Turn on the packet forwarding function of the Scheduler vs Host

# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf && sysctl -p

2. Create a Lvs-nat cluster

在LVS主机上:# ipvsadm -A -t 172.18.44.220:80 -s rr

3. Add Realserver

# ipvsadm -a -t 172.18.44.220:80 -m -r 192.168.7.201:80# ipvsadm -a -t 172.18.44.220:80 -m -r 192.168.7.203:8080

4. Inspection

# ipvsadm -LnIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  172.18.44.220:80 rr  -> 192.168.7.201:80             Masq    1      0          0           -> 192.168.7.203:8080           Masq    1      0          

5. Save Ipvs

# ipvsadm-save -n > /etc/sysconfig/ipvsadm

6. Testing

在外网的客户机# for ((i=1;i<=10;i++));do curl 172.18.44.220;donenginx on RS1nginx on RS2nginx on RS1nginx on RS2nginx on RS1nginx on RS2nginx on RS1nginx on RS2nginx on RS1nginx on RS2

7. Adjust the scheduling algorithm and realserver weights

# ipvsadm -E -t 172.18.44.220:80 -s wrr# ipvsadm -e -t 172.18.44.220:80 -m -r 192.168.7.201:80 -w 2# ipvsadm -e -t 172.18.44.220:80 -m -r 192.168.7.203:8080 -w 1# ipvsadm -lnIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  172.18.44.220:80 wrr  -> 192.168.7.201:80             Masq    2      0          0           -> 192.168.7.203:8080           Masq    1      0          0

8. Testing

# for ((i=1;i<=10;i++));do curl 172.18.44.220;donenginx on RS1nginx on RS1nginx on RS2nginx on RS1nginx on RS1nginx on RS2nginx on RS1nginx on RS1nginx on RS2nginx on RS1

Note: The LVS rules will take effect immediately after they are modified.

LVS-DR Cluster

LVS Configuration

#!/bin/bashvip=‘192.168.7.250‘iface=‘eth0:1‘mask=‘255.255.255.255‘port=‘80‘rs1=‘192.168.7.201‘rs2=‘192.168.7.203‘scheduler=‘rr‘type=‘-g‘case $1 instart)    ifconfig $iface $vip netmask $mask    iptables -F    ipvsadm -A -t ${vip}:${port} -s $scheduler    ipvsadm -a -t ${vip}:${port} -r ${rs1} $type    ipvsadm -a -t ${vip}:${port} -r ${rs2} $type    echo "The VS Server is Ready!"    ;;stop)    ipvsadm -C    ifconfig $iface down    echo "The VS Server is Canceled!"    ;;*)    echo "Usage: $(basename $0) start|stop"    exit 1    ;;esac

RS Configuration (2 units)

#!/bin/bashvip=192.168.7.250mask=‘255.255.255.255‘dev=lo:1case $1 instart)    echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore    echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore    echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce    echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce    ifconfig $dev $vip netmask $mask    #route add -host $vip dev $dev    echo "The RS Server is Ready!"    ;;stop)    ifconfig $dev down    echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore    echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore    echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce    echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce    echo "The RS Server is Canceled!"    ;;*)    echo "Usage: $(basename $0) start|stop"    exit 1    ;;esac

Client

# for ((i=1;i<=10;i++));do curl 192.168.7.250;doneRS2RS1RS2RS1RS2RS1RS2RS1RS2RS1

Linux cluster (iii)-IPVSADM tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.