国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Linux > 正文

linux服務(wù)之lvs

2024-06-28 13:27:06
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
linux服務(wù)之lvs

開發(fā)語(yǔ)言:

服務(wù)器端:在內(nèi)核中實(shí)現(xiàn),無(wú)守護(hù)程序

客戶端:一般是cli界面下的ipvsadm命令

相關(guān)包:ipvsadm

在LVS框架中,提供了含有三種IP負(fù)載均衡技術(shù)的IP虛擬服務(wù)器軟件IPVS、基于內(nèi)容請(qǐng)求分發(fā)的內(nèi)核Layer-7交換機(jī)KTCPVS和集群管理軟件。可以利用LVS框架實(shí)現(xiàn)高可伸縮的、高可用的Web、Cache、Mail和Media等網(wǎng)絡(luò)服務(wù);在此基礎(chǔ)上,可以開發(fā)支持龐大用戶數(shù)的、高可伸縮的、高可用的電子商務(wù)應(yīng)用。VS/NAT技術(shù)(Virtual Server via Network Address Translation),大多數(shù)商品化的IP負(fù)載均衡調(diào)度器產(chǎn)品都是使用此方法,如Cisco的LocalDirector、F5的Big/IP和 Alteon的ACEDirector。在分析VS/NAT的缺點(diǎn)和網(wǎng)絡(luò)服務(wù)的非對(duì)稱性的基礎(chǔ)上,我們提出通過(guò)IP隧道實(shí)現(xiàn)虛擬服務(wù)器的方法VS/TUN (Virtual Server via IP Tunneling),和通過(guò)直接路由實(shí)現(xiàn)虛擬服務(wù)器的方法VS/DR(Virtual Server via Direct Routing),它們可以極大地提高系統(tǒng)的伸縮性。所以,IPVS軟件實(shí)現(xiàn)了這三種IP負(fù)載均衡技術(shù),

檢查內(nèi)核是否支持lvs的ipvs模塊[root@com1 ~]# modPRobe -l|grep ipvskernel/net/netfilter/ipvs/ip_vs.kokernel/net/netfilter/ipvs/ip_vs_rr.kokernel/net/netfilter/ipvs/ip_vs_wrr.kokernel/net/netfilter/ipvs/ip_vs_lc.kokernel/net/netfilter/ipvs/ip_vs_wlc.kokernel/net/netfilter/ipvs/ip_vs_lblc.kokernel/net/netfilter/ipvs/ip_vs_lblcr.kokernel/net/netfilter/ipvs/ip_vs_dh.kokernel/net/netfilter/ipvs/ip_vs_sh.kokernel/net/netfilter/ipvs/ip_vs_sed.kokernel/net/netfilter/ipvs/ip_vs_nq.kokernel/net/netfilter/ipvs/ip_vs_ftp.ko可以看到內(nèi)核默認(rèn)支持ipvs模塊,下來(lái)安裝ipvs管理軟件[root@com1 ~]# yum install ipvsadm

1.NAT方式:NAT配置方式最簡(jiǎn)單,只需要在LVS主機(jī)上配置就可以了,如下例子:設(shè)置VIP主機(jī):ipvsadm -A -t 202.103.106.5:80 -s wlcipvsadm -A -t 202.103.106.5:21 -s wrripvsadm -a -t 202.103.106.5:80 -r 172.16.0.2:80 -m ipvsadm -a -t 202.103.106.5:80 -r 172.16.0.3:8000 -m -w 2 ipvsadm -a -t 202.103.106.5:21 -r 172.16.0.2:21 -m

2.TUN方式:對(duì)LVS主機(jī)設(shè)置:設(shè)置VIP主機(jī):ipvsadm -A -t 172.26.20.110:23 -s wlcipvsadm -a -t 172.26.20.110:23 -r 172.26.20.112 -i

對(duì)每臺(tái)real主機(jī)的設(shè)置:echo 1 > /proc/sys/net/ipv4/ip_forward#加載ipip模塊modprobe ipipifconfig tunl0 0.0.0.0 upecho 1 > /proc/sys/net/ipv4/conf/all/hiddenecho 1 > /proc/sys/net/ipv4/conf/tunl0/hiddenifconfig tunl0 172.26.20.110 netmask 255.255.255.255 broadcast 172.26.20.110 up

ipvsadm配置A 堡壘 eth0 192.168.3.187/24 外網(wǎng)IP eth1 192.168.200.1/24 實(shí)驗(yàn)內(nèi)網(wǎng)ipB eth0 192.168.200.10/24C eth0 192.168.200.20/24下面是對(duì)堡壘機(jī)的配置重定向幾個(gè)文件#echo "1" >/proc/sys/net/ipv4/ip_forward#echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects#echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects#echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects#echo "0" >/proc/sys/net/ipv4/conf/eth1/send_redirects

ipvsadm -C -C 清除表中所有的記錄ipvsadm -A -t 192.168.3.187:80 -s rr -A --add-service在服務(wù)器列表中新添加一條新的虛擬服務(wù)器記錄-t 表示為tcp服務(wù)-u 表示為udp服務(wù)-s --scheduler 使用的調(diào)度算法, rr | wrr | lc | wlc | lblb | lblcr | dh | sh | sed | nq 默認(rèn)調(diào)度算法是 wlcipvsadm -a -t 192.168.3.187:80 -r 192.168.200.10:80 -m -w 1-a --add-server 在服務(wù)器表中添加一條新的真實(shí)主機(jī)記錄-t --tcp-service 說(shuō)明虛擬服務(wù)器提供tcp服務(wù)-u --udp-service 說(shuō)明虛擬服務(wù)器提供udp服務(wù)-r --real-server 真實(shí)服務(wù)器地址-m --masquerading 指定LVS工作模式為NAT模式-w --weight 真實(shí)服務(wù)器的權(quán)值-g --gatewaying 指定LVS工作模式為直接路由器模式(也是LVS默認(rèn)的模式)-i --ipip 指定LVS的工作模式為隧道模式-p 會(huì)話保持時(shí)間,定義流量唄轉(zhuǎn)到同一個(gè)realserver的會(huì)話存留時(shí)間調(diào)度算法rr 輪詢 round robin, wrr 加強(qiáng)輪詢 weighted round robin, 新的請(qǐng)求被輪流分配到RealServer上,它假設(shè)服務(wù)器處理性能都相同,不管服務(wù)器當(dāng)前的連接數(shù)和響應(yīng)速度,不適合服務(wù)器性能不同的集群,這會(huì)導(dǎo)致服務(wù)器間的負(fù)載不平衡dh 目的地址散列調(diào)度 destination hashing,針對(duì)IP地址的負(fù)載,

The command has two basic formats for execution:ipvsadm command [protocol] service-address [scheduling-method] [persistence options]ipvsadm command [protocol] service-address server-address [packet-forwarding-method] [weight options]

The first format manipulates a virtual service and the algorithm for assigning service requests to real servers. Optionally, a persistent timeout and network mask for the granularity of a persistent service may be specified. The second format manipulates a real server that is associated with an exist-ing virtual service. When specifying a real server, the packet-forwarding method and the weight of the real server, relative to other real servers for the virtual service, may be specified, otherwise defaults will be used.

three packet-forwarding methods (NAT, tunneling, and direct routing), and eight load balancing algorithms (round robin, weighted round robin, least-connection, weighted least-connection, locality-based least-con-nection, locality-based least-connection with replication, destination-hashing, and source-hashing). --gatewaying     -g gatewaying (direct routing) (default) --ipip       -i ipip encapsulation (tunneling) --masquerading     -m masquerading (NAT) --scheduler      -s scheduler one of rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq,the default scheduler is wlc. --list     -L|-l list the table --connection   -c output of current IPVS connections --numeric   -n numeric output of addresses and ports

-p --persistent [timeout] 持久穩(wěn)固的服務(wù)。這個(gè)選項(xiàng)的意思是來(lái)自同一個(gè)客戶的多次請(qǐng)求,將被同一臺(tái)真實(shí)的服務(wù)器處理-g --gatewaying 指定LVS 的工作模式為直接路由模式(也是LVS 默認(rèn)的模式)

lvs無(wú)故障隔離以及失敗切換框架,要實(shí)現(xiàn)這個(gè)功能,需要配合keepalived等工具實(shí)現(xiàn)。DR方式適合所有的RealServer同一網(wǎng)段下,即接在同一個(gè)交換機(jī)上.TUNL方式就對(duì)于RealServer的位置可以任意了,完全可以跨地域、空間,只要系統(tǒng)支持Tunnel就可以,方便以后擴(kuò)充的話直接Tunl方式即可

1、InActConn并不代表錯(cuò)誤連接,它是指不活躍連接(Inactive Connections),我們將處于TCP ESTABLISH狀態(tài)以外的連接都稱為不活躍連接,例如處于SYN_RECV狀態(tài)的連接,處于TIME_WAIT狀態(tài)的連接等。

[root@210-lvs ~]# ipvsadm -lIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  192.168.2.215:ndmp rr  -> 192.168.2.109:ndmp           Route   1      447        2  -> 192.168.2.221:ndmp           Route   1      512        7[root@210-lvs ~]# ipvsadm -l -cn|grep -v "EST"IPVS connection entriespro expire state       source             virtual            destinationTCP 00:41  SYN_RECV    223.104.27.91:33407 192.168.2.215:10000 192.168.2.109:10000TCP 01:16  FIN_WAIT    58.83.209.187:57555 192.168.2.215:10000 192.168.2.221:10000TCP 00:41  SYN_RECV    117.136.25.196:19271 192.168.2.215:10000 192.168.2.221:10000TCP 01:55  FIN_WAIT    58.83.209.186:36565 192.168.2.215:10000 192.168.2.221:10000TCP 00:01  CLOSE       117.136.25.143:30661 192.168.2.215:10000 192.168.2.221:10000TCP 00:03  CLOSE       117.136.25.139:45468 192.168.2.215:10000 192.168.2.221:10000TCP 01:02  FIN_WAIT    58.83.209.185:28186 192.168.2.215:10000 192.168.2.221:10000TCP 01:41  FIN_WAIT    58.83.209.188:11868 192.168.2.215:10000 192.168.2.109:10000TCP 01:30  FIN_WAIT    58.83.209.180:12424 192.168.2.215:10000 192.168.2.221:10000

2、用四個(gè)參數(shù)來(lái)關(guān)閉arp查詢響應(yīng)請(qǐng)求:echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 > /proc/sys/net/ipv4/conf/lo/arp_announceecho 1 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 2 > /proc/sys/net/ipv4/conf/all/arp_announce

在LVS方案中,虛擬ip地址與普通網(wǎng)絡(luò)接口大大不同,這點(diǎn)需要特別注意。虛擬ip地址的廣播地址是它本身,子網(wǎng)掩碼是255.255.255.255。 為什么要這樣呢?因?yàn)橛腥舾蓹C(jī)器要使用同一個(gè)ip地址,用本身做廣播地址和把子網(wǎng)掩碼設(shè)成4個(gè)255就不會(huì)造成ip地址沖突了,否則lvs將不能正常轉(zhuǎn)發(fā)訪問(wèn)請(qǐng)求。

假如兩臺(tái)VS之間使用的互備關(guān)系,那么當(dāng)一臺(tái)VS接管LVS服務(wù)時(shí),可能會(huì)網(wǎng)絡(luò)不通,這時(shí)因?yàn)槁酚善鞯腗AC緩存表里關(guān)于vip這個(gè)地址的MAC地 址還是被替換的VS的MAC,有兩種解決方法,一種是修改新VS的MAC地址,另一種是使用send_arp 命令(piranha軟件包里帶的一個(gè)小工具) 格式如下:send_arp:send_arp [-i dev] src_ip_addr src_hw_addr targ_ip_addr tar_hw_addr這個(gè)命令不一定非要在VS上執(zhí)行,只+要在同一VLAN即可。/sbin/arping -f -q -c 5 -w 5 -I eth0 -s $WEB_VIP -U $GW

[root@com1 ~]# ipvsadm -l IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 192.168.2.215:ndmp rr -> com1:ndmp Local 1 1455 1 -> com2:ndmp Route 1 1605 0 [root@com1 ~]# ipvsadm -l --rate IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port CPS InPPS OutPPS InBPS OutBPS -> RemoteAddress:PortTCP 192.168.2.215:ndmp 0 490 0 41618 0 -> com1:ndmp 0 245 0 20970 0 -> com2:ndmp 0 246 0 20648 0[root@com1 ~]# ipvsadm -l --statsIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes -> RemoteAddress:PortTCP 192.168.2.215:ndmp 28421 1971291 0 142348K 0 -> com1:ndmp 14210 1044997 0 77354965 0 -> com2:ndmp 14211 926294 0 64993846 0

[root@com1 ~]# ipvsadm -l --thresholdsIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Uthreshold Lthreshold ActiveConn InActConn -> RemoteAddress:PortTCP 192.168.2.215:ndmp rr -> com1:ndmp 0 0 386 335 -> com2:ndmp 0 0 551 313 [root@com1 ~]# ipvsadm -l --persistent-connIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Weight PersistConn ActiveConn InActConn -> RemoteAddress:PortTCP 192.168.2.215:ndmp rr -> com1:ndmp 1 0 389 335 -> com2:ndmp 1 0 553 313

[root@com1 ~]# ipvsadm -l -c -nIPVS connection entriespro expire state source virtual destinationTCP 14:12 ESTABLISHED 117.35.159.6:13589 192.168.2.215:ndmp com2:ndmpTCP 02:52 ESTABLISHED 117.35.159.6:9407 192.168.2.215:ndmp com1:ndmpTCP 14:12 ESTABLISHED 117.35.159.6:13684 192.168.2.215:ndmp com1:ndmpTCP 03:14 ESTABLISHED 117.35.159.6:7976 192.168.2.215:ndmp com1:ndmpTCP 09:26 ESTABLISHED 117.35.159.6:23373 192.168.2.215:ndmp com2:ndmp

TCP 01:15 ESTABLISHED 117.35.159.6:7415 192.168.2.215:10000 192.168.2.101:10000TCP 07:02 ESTABLISHED 117.35.159.6:23713 192.168.2.215:10000 192.168.2.100:10000TCP 11:59 ESTABLISHED 117.35.159.6:16217 192.168.2.215:10000 192.168.2.101:10000TCP 11:56 ESTABLISHED 117.35.159.6:16490 192.168.2.215:10000 192.168.2.100:10000TCP 07:04 ESTABLISHED 117.35.159.6:2617 192.168.2.215:10000 192.168.2.100:10000TCP 11:55 ESTABLISHED 117.35.159.6:14924 192.168.2.215:10000 192.168.2.100:10000TCP 07:01 ESTABLISHED 117.35.159.6:25286 192.168.2.215:10000 192.168.2.101:10000

LVS大量快速并發(fā)連接后報(bào)Connection refused的問(wèn)題

由 firestorm 在 周二, 2011-09-06 18:47 提交 LVS集群

大致環(huán)境:RedHat 4.4, 千兆網(wǎng),兩個(gè)結(jié)點(diǎn)作為L(zhǎng)VS的master與slaver,使用IP tunnel模式,同時(shí)用又作real server,大概6,7個(gè)real server。LVS服務(wù)器已經(jīng)進(jìn)行常規(guī)的高性能服務(wù)器優(yōu)化,包括LVS APP的相關(guān)配置、tcp 的TIME_WAIT快速回收與重用等等。使用2個(gè)客戶端服務(wù)器連接LVS的虛擬IP,每個(gè)客戶端啟動(dòng)8個(gè)線程連接LVS集群上特定應(yīng)用的端口,連接并進(jìn)行簡(jiǎn)單數(shù)據(jù)交互后close,發(fā)起和關(guān)閉連接比較頻繁,每個(gè)線程大概都是幾十次/秒。

情況如下:1. 大概跑2,3個(gè)小時(shí),客戶端總連接次數(shù)大概數(shù)百萬(wàn)量級(jí)后,會(huì)發(fā)生服務(wù)連接虛擬IP 報(bào)Connection refused的情況,有時(shí)候是2個(gè)客戶端節(jié)點(diǎn)同時(shí)拒絕連接,有時(shí)候一個(gè)被拒,一個(gè)可以,但是一段時(shí)間后也被拒絕。2. 連接被拒后,大概等待10分鐘左右又可以成功建立連接并繼續(xù)操作;3. 連接被拒絕后如果再用第三個(gè)客戶端節(jié)點(diǎn)來(lái)連接虛擬IP,可以成功并并發(fā)執(zhí)行;4. 連接被拒節(jié)點(diǎn)如果直接連真實(shí)服務(wù)器的實(shí)際地址與對(duì)應(yīng)端口,可以連接并操作;5. 連接被拒絕后重啟客戶端節(jié)點(diǎn)的網(wǎng)絡(luò) service network restart 可以恢復(fù)對(duì)LVS的連接;6. 重啟LVS服務(wù)可以重新連接。7. 由于客戶端也做過(guò)TIME_WAIT的tcp_tw_reuse、tcp_tw_recycle的優(yōu)化,所以用netstat和ss -s等命令看,服務(wù)器與客戶端各項(xiàng)數(shù)值都不是很大;8. /proc/sys/fs/file-max等數(shù)值在服務(wù)端客戶端都設(shè)置的比較大,服務(wù)端設(shè)置的是100萬(wàn),而且在出問(wèn)題時(shí)看/proc/sys/fs/file-nr 時(shí)也就一千多。9. 超時(shí)設(shè)置是:Timeout (tcp tcpfin udp): 36000 120 30010. 使用ipvsadm命令看activeConn不是很大,大概每個(gè)real server也就3、4左右,inactive連接時(shí)高時(shí)低,大概3000-8000之間,平均5000吧。11. lsof看服務(wù)端進(jìn)程沒(méi)有打開句柄超限的(考慮單進(jìn)程ulimit -n 1024的限制)

權(quán)重問(wèn)題:當(dāng)lvs配置文件lvs-dr.sh改變權(quán)重以及keepalived配置文件keepalived.conf修改權(quán)重后,哪個(gè)文件重新啟動(dòng),哪個(gè)文件的權(quán)重生效。同時(shí)權(quán)重在master和backup上面可以設(shè)置不同。當(dāng) 算法是rr的時(shí)候,權(quán)重沒(méi)有作用,但是當(dāng)算法是wlc和wrr的時(shí)候,必須設(shè)置權(quán)重,可以根據(jù)服務(wù)器的性能和配置,來(lái)確定權(quán)重的大小,當(dāng)權(quán)重大的時(shí) 候,lvs調(diào)度的服務(wù)也就多,同時(shí)權(quán)重高的服務(wù)器先收到鏈接。當(dāng)小的時(shí)候,lvs調(diào)度的比較少。當(dāng)權(quán)重為0的時(shí)候,表示服務(wù)器不可用,


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 福安市| 石门县| 青阳县| 什邡市| 张家港市| 佛山市| 台江县| 大同市| 临夏市| 舟曲县| 余江县| 务川| 宁远县| 泊头市| 新泰市| 明星| 昌图县| 息烽县| 洛扎县| 灵宝市| 房产| 乌拉特中旗| 阜宁县| 宁蒗| 九龙县| 马尔康县| 历史| 共和县| 漳平市| 温宿县| 凤凰县| 都安| 建宁县| 宜阳县| 繁峙县| 都昌县| 平顺县| 亚东县| 获嘉县| 池州市| 石河子市|