ipvsadm命令总结
ipvsadm工具介紹
從2.4版本開始,linux內(nèi)核默認支持LVS。要使用LVS的能力,只需安裝一個LVS的管理工具:ipvsadm。
LVS的結(jié)構(gòu)主要分為兩部分:
- 工作在內(nèi)核空間的IPVS模塊。LVS的能力實際上都是由IVPS模塊實現(xiàn)。
- 工作在用戶空間的ipvsadm管理工具。其作用是向用戶提供一個命令接口,用于將配置的虛擬服務(wù)、真實服務(wù)等傳給IPVS模塊。
以下選項用于list命令:
?-c, --connection:列出當前的IPVS連接。
????--timeout:列出超時
????--daemon:?顯示同步守護進程狀態(tài)
????--stats:狀態(tài)信息
????--rate:傳輸速率
????--thresholds:列出閾值
????--persistent-conn:堅持連接
????--sor:把列表排序。
????--nosort:不排序
????-n, --numeric:不對ip地址進行dns查詢
????--exact:單位
查看統(tǒng)計
- 查看當前配置的虛擬服務(wù)和各個RS的權(quán)重
ipvsadm -Ln
- 查看當前ipvs模塊中記錄的連接(可用于觀察轉(zhuǎn)發(fā)情況)
ipvsadm -lnc
- 查看ipvs模塊的轉(zhuǎn)發(fā)情況統(tǒng)計
ipvsadm -Ln --stats | --rate
--stat選項是統(tǒng)計自該條轉(zhuǎn)發(fā)規(guī)則生效以來的包
1. Conns ???(connections scheduled) ?已經(jīng)轉(zhuǎn)發(fā)過的連接數(shù)
2. InPkts ??(incoming packets) ??????入包個數(shù)
3. OutPkts ?(outgoing packets) ??????出包個數(shù)
4. InBytes ?(incoming bytes) ????????入流量(字節(jié)) ?
5. OutBytes (outgoing bytes) ????????出流量(字節(jié))
--rate選項是顯示速率信息
1. CPS ?????(current connection rate) ??每秒連接數(shù)
2. InPPS ???(current in packet rate) ???每秒的入包個數(shù)
3. OutPPS ??(current out packet rate) ??每秒的出包個數(shù)
4. InBPS ???(current in byte rate) ?????每秒入流量(字節(jié))
5. OutBPS ??(current out byte rate) ?????每秒入流量(字節(jié))
1.使用NAT模式
添加地址為207.175.44.110:80的虛擬服務(wù),指定調(diào)度算法為輪轉(zhuǎn)。
ipvsadm -A -t 207.175.44.110:80 -s rr
添加真實服務(wù)器,指定傳輸模式為NAT
ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.1:80 -m
ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.2:80 -m
ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.3:80 -m
NAT模式是lvs的三種模式中最簡單的一種。此種模式下只需要保證調(diào)度服務(wù)器與真實服務(wù)器互通就可以運行。
2.使用DR模式
對于DR模式首先要配置真實服務(wù)器:
對于每臺真實服務(wù)器要進行以下操作:
a、設(shè)置真實服務(wù)器的lo接口不做ARP應(yīng)答
echo 1 > /proc/sys/net/ipv4/conf/all/arg_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arg_ignore
設(shè)置這個選項可以使得各個接口只對本接口上的地址進行響應(yīng)
還需要設(shè)置arp_announce選項為2,設(shè)置方法同上
b、在真實服務(wù)器上添加虛擬IP
ifconfig lo:0 192.168.10.10 boradcast 207.175.44.110 netmask 255.255.255.255
ip r add 192.168.10.10 dev lo
接著添加ipvs規(guī)則:
添加地址為192.168.10.10:80的虛擬服務(wù),指定調(diào)度算法為輪轉(zhuǎn)。
ipvsadm -A -t 192.168.10.10:80 -s rr
添加真實服務(wù)器,指定傳輸模式為DR
ipvsadm -a -t 192.168.10.10:80 -r 192.168.10.1:80 -g
ipvsadm -a -t 192.168.10.10:80 -r 192.168.10.2:80 -g
ipvsadm -a -t 192.168.10.10:80 -r 192.168.10.3:80 -g
注意:此處的例子中客戶、調(diào)度服務(wù)器、真實服務(wù)器都是位于同一網(wǎng)段的
| 命令 | ? |
| ./ipvsadm -A|E -t|u|q|f service-address [-s scheduler] [-j eanble/disable] [-p [timeout]] [-M netmask] [--pe persistence_engine] | ipvsadm -A|E -t|u|f <集群服務(wù)地址> [-s <調(diào)度算法>] [-p <超時時間>] [-M <掩碼>] [-b <標志>] |
| ./ipvsadm -D -t|u|q|f service-address | ?ipvsadm -D -t|u|f <集群服務(wù)地址> |
| ./ipvsadm -C | ? |
| ./ipvsadm -R | ? |
| ./ipvsadm -S [-n] | ? |
| ./ipvsadm -P|Q -t|u|q|f service-address -z local-address | ? |
| ./ipvsadm -G -t|u|q|f service-address | ? |
| ./ipvsadm -U|V -t|u|q|f service-address -k blacklist-address | ? |
| ./ipvsadm -a|e -t|u|q|f service-address -r server-address [options] | ?ipvsadm -a|e -t|u|f <集群服務(wù)地址> -r <真實服務(wù)器地址> [選項] |
| ./ipvsadm -d -t|u|q|f service-address -r server-address | ?ipvsadm -d -t|u|f <集群服務(wù)地址> -r <真實服務(wù)器地址> |
| ./ipvsadm -L|l [options] | ?ipvsadm -L|l [options] |
| ./ipvsadm -Z [-t|u|q|f service-address] | ipvsadm -Z [-t|u|f <集群服務(wù)地址>] |
| ./ipvsadm --set tcp tcpfin udp | ipvsadm --set <超時時間> |
| ./ipvsadm --start-daemon state [--mcast-interface interface] [--syncid sid] | ipvsadm --start-daemon <主或備> [--mcast-interface <組播接口>] [--syncid <SID>] |
| ./ipvsadm --stop-daemon state | ?ipvsadm --stop-daemon <主或備> |
| ./ipvsadm -h | ? |
?
| 完整命令 | 縮寫命令 | 解釋 | 中文解釋 |
| --add-service | -A | add virtual service with options | 添加一條新的虛擬服務(wù) |
| --edit-service | -E | edit virtual service with options | 編輯虛擬服務(wù) |
| --delete-service | -D | delete virtual service | 刪除虛擬服務(wù) |
| --clear | -C | clear the whole table | 清除所有的虛擬服務(wù)規(guī)則 |
| --restore | -R | restore rules from stdin | 從標準輸入中恢復(fù)策略規(guī)則 |
| --add-laddr | -P | add local address | ? |
| --del-laddr | -Q | del local address | ? |
| --get-laddr | -G | get local address | ? |
| --add-blklst | -U | add blacklist address | ? |
| --del-blklst | -V | del blacklist address | ? |
| --get-blklst | -B | get blacklist address | ? |
| --save | -S | save rules to stdout | 保存策略規(guī)則到標準輸出 |
| --add-server | -a | add real server with options | 添加一個真實服務(wù)器,需要使用選項 |
| --edit-server | -e | edit real server with options | 編輯一個真實服務(wù)器,需要使用選項 |
| --delete-server | -d | delete real server | 刪除一個真實服務(wù)器,需要使用選項 |
| --list | -L|-l | list the table | 查看集群服務(wù)列表,包括真實服務(wù)器轉(zhuǎn)發(fā)策略規(guī)則 |
| --zero | -Z | zero counters in a service or all services | 計數(shù)器清零。清除連接數(shù)、包轉(zhuǎn)發(fā)等數(shù)量統(tǒng)計信息 |
| --set tcp tcpfin udp | ? | set connection timeout values | 設(shè)置TCP、TCPFIN(TCP關(guān)閉連接狀態(tài))、UDP連接超時時間,用于 會話保持。一般情況下TCP和UDP超時時間保持默認就好,TCPFIN 可以根據(jù)情況設(shè)定,指定它則用戶請求連接關(guān)閉,該連接則會變 為非活躍(InActive)空閑等待狀態(tài),在空閑等待時間內(nèi),如果 來自同一源IP的請求,則還會轉(zhuǎn)發(fā)給后端的同一臺真實服務(wù)器上 |
| --start-daemon | ? | start connection sync daemon | 開啟連接同步守護進程。在選項后面指定自己是Master(主)還 是backup(備),主負載調(diào)度器會同步所有策略及連接狀態(tài)到備 負載調(diào)度器,當主故障,備可以接替其工作 |
| --stop-daemon | ? | stop connection sync daemon | 停止連接同步守護進程 |
| --help | -h | display this help message | 顯示幫助信息 |
| --tcp-service? ? ? -t? service-address | service-address is host[:port] | <集群服務(wù)地址> 允許集群服務(wù)使用的傳輸協(xié)議為TCP |
| --udp-service? ? -u service-address | service-address is host[:port] | <集群服務(wù)地址> 允許集群服務(wù)使用的傳輸協(xié)議為UDP |
| --icmp-service? ? -q service-address | service-address is host[:port] | ? |
| --icmpv6-service? ?-1 service-address | service-address is host[:port] | ? |
| --fwmark-service? ? -f fwmark | fwmark is an integer greater than zero | 使用一個整數(shù)值來防火墻標識集群服務(wù),而不是地址、 端口和協(xié)議使用它,我們可以通過結(jié)合IPtables將多 個以調(diào)度器為目標的端口定義成一個防火墻標識,由 ipvsdam通過此項關(guān)聯(lián)標識,則可以實現(xiàn)對一個IP多 端口調(diào)度,即實現(xiàn)后端服務(wù)器可以開放多個服務(wù) |
| --ipv6? ? ?-6 fwmark | entry uses IPv6 | ? |
| --scheduler? ? ? -s?scheduler | one of rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq, the default scheduler is wlc. | 指定集群服務(wù)使用的調(diào)度算法:rr|wrr|lc|wlc|lblc |lblcr|dh|sh|sed|nq,默認為wlc |
| --pe engine | alternate persistence engine may be sip, not set by default. | ? |
| --persistent? ? ?-p [timeout] | persistent service | <超時時間> 開啟持久化服務(wù),開啟它則表示在指定時間內(nèi),來自同 一IP的請求都會轉(zhuǎn)發(fā)到后端同一臺真實服務(wù)器上 |
| --netmask? ? ? -M netmask | persistent granularity mask | <網(wǎng)絡(luò)掩碼> 使用網(wǎng)絡(luò)掩碼來屏蔽持久化來源IP的地址范圍,默認值 為255.255.255.255,即所有來源IP請求都會享受持久 化服務(wù) |
| --real-server? ? ?-r server-address | server-address is host (and port) | <真實服務(wù)器地址> 指定真實服務(wù)器的主機IP與端口 |
| --gatewaying? ? -g | gatewaying (direct routing) (default) | 指定真實服務(wù)器轉(zhuǎn)發(fā)工作模式,使用DR模式,默認 |
| --ipip? ? -i | ipip encapsulation (tunneling) | 指定真實服務(wù)器轉(zhuǎn)發(fā)工作模式,使用TUN模式 |
| --fullnat? ? ? -b | fullnat mode | ? |
| --snat? ? ??-J | SNAT mode | ? |
| --masquerading? ? ? -m | masquerading (NAT) | 指定真實服務(wù)器轉(zhuǎn)發(fā)工作模式,使用NAT模式 |
| --weight? ? ? ? -w weight | capacity of real server | <權(quán)重值> 指定真實服務(wù)器的權(quán)重值 |
| --u-threshold? ? ? ?-x uthreshold | upper threshold of connections | <上閥值> 設(shè)置轉(zhuǎn)發(fā)請求的最大上連接閥值,范圍為0~65535,當 當連接數(shù)超過指定上限時,LVS則不會轉(zhuǎn)發(fā)請求 |
| --l-threshold? ? ? ? -y lthreshold | lower threshold of connections | 設(shè)置轉(zhuǎn)發(fā)請求的下連接閥值,范圍為0~65535,當連接 數(shù)降低至指定值時,LVS則繼續(xù)提供服務(wù),默認值為0 |
| --mcast-interface interface | multicast interface for connection sync | 設(shè)置用于連接同步守護進程的組播接口 |
| --syncid sid | syncid for connection sync (default=255) | 設(shè)置連接同步守護進程的SID號,用于標識,范圍0~255 |
| --connection? ? ? ?-c | output of current IPVS connections | 顯示連接信息,一般與"-l"連用 |
| --timeout | output of timeout (tcp tcpfin udp) | 顯示TCP、TCPFIN、UDP超時時間信息,一般與"-l"連用 |
| --daemon | output of daemon information | 顯示連接同步守護信息,一般與"-l"連用 |
| --stats | output of statistics information | 顯示統(tǒng)計信息,一般與"-l"連用 |
| --rate | output of rate information | 顯示轉(zhuǎn)發(fā)速率信息,一般與"-l"連用 |
| --exact | expand numbers (display exact values) | 顯示數(shù)據(jù)包和字節(jié)計數(shù)器的確切值,擴大字符長度 |
| --thresholds | output of thresholds information | 顯示閥值信息,一般與"-l"連用 |
| --persistent-conn | output of persistent connection info | 顯示持久化連接信息,一般與"-l"連用 |
| --sockpair | output connection info of specified socket pair (proto:sip:sport:tip:tport) | ? ? |
總結(jié)
以上是生活随笔為你收集整理的ipvsadm命令总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里云Linux服务器查杀木马经历
- 下一篇: 基于ol-plot的openlayers