LVS集羣之IP TUN模式以及網站壓力測試

今天來看一下LVS的第三種模式IP TUN。html

TUN方式,是經過給數據包加上新的IP頭部來實現,這個能夠跨整個廣域網。web

環境:vim

主機名 IP 系統 角色
tiandong63

RIP:192.168.199.十一、DG:192.168.199.1服務器

VIP:192.168.199.63網絡

rhel6.5 real server1
tiandong64

RIP:192.168.199.十二、DG:192.168.199.1併發

VIP:192.168.199.63oop

rhel6.5 real server2
OpenStack

DIP:192.168.199.七、DG:192.168.199.1性能

VIP:192.168.199.63測試

rhel7.4 分發器
localhost 192.168.199.8 rhel7.4 測試機

分發器:
一、配置網絡:網站

ens33  192.168.199.7    DIP

ens33:1 192.168.199.63  VIP

[root@openstack ~]#ifconfig ens33:1 192.168.199.63 netmask 255.255.255.0 up

[root@openstack ~]# echo 1 > /proc/sys/net/ipv4/ip_forward   開啓路由轉發功能

二、配置IP TUN模式

root@openstack ~]#yum install ipvsadm -y

[root@openstack ~]#ipvsadm -A -t 192.168.199.63:80 -s rr
[root@openstack ~]#ipvsadm -a -t 192.168.199.63:80 -r 192.168.199.11:80 -i      #-i隧道模式
[root@openstack ~]#ipvsadm -a -t 192.168.199.63:80 -r 192.168.199.12:80 -i

[root@openstack ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.199.63:80 rr
  -> 192.168.199.11:80            Tunnel  1      0          0         
  -> 192.168.199.12:80            Tunnel  1      0          0

 

Realserver1:tiandong63

一、配置網絡:

eth0 RIP:192.168.199.11

[root@tiandong63 ~]# modprobe ipip   #在加載好ipip模塊後就會有默認的tunl0隧道。

[root@tiandong63 ~]# lsmod |grep ipip
ipip                    8371  0
tunnel4                 2943  1 ipip

[root@tiandong63 ~]#ifconfig tunl0 192.168.199.63 netmask 255.255.255.255 up

[root@tiandong63 ~]# service network restart

[root@tiandong63 ~]# ifconfig -a     此時就能夠看到tunl0的網卡了。
eth0      Link encap:Ethernet  HWaddr 00:0C:29:38:0B:14  
          inet addr:192.168.199.11  Bcast:192.168.199.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe38:b14/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:113954 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40448 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:164480499 (156.8 MiB)  TX bytes:2794350 (2.6 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

tunl0     Link encap:IPIP Tunnel  HWaddr   
          inet addr:192.168.199.63  Mask:255.255.255.255
          UP RUNNING NOARP  MTU:1480  Metric:1
          RX packets:20 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1664 (1.6 KiB)  TX bytes:0 (0.0 b)

二、關閉ARP轉發:

[root@tiandong63 ~]# vim /etc/sysctl.conf    在最後加上:
net.ipv4.conf.tunl0.arp_ignore = 1
net.ipv4.conf.tunl0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.tunl0.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0

[root@tiandong63 ~]# sysctl -p    是配置生效
三、配置web服務器

[root@tiandong63 ~]#yum install httpd -y

[root@tiandong63 ~]# echo 'this is 192.168.199.11' > /var/www/html/index.html    寫一個測試頁面
[root@tiandong63 ~]# /etc/init.d/httpd start

 

Realserver2:tiandong64

一、配置網絡

eth0 RIP:192.168.199.12

[root@tiandong64 ~]# modprobe ipip
[root@tiandong64 ~]# lsmod |grep ipip
ipip                    8371  0
tunnel4                 2943  1 ipip

[root@tiandong64 ~]#ifconfig tunl0 192.168.199.63 netmask 255.255.255.255 up

[root@tiandong64 ~]# service network restart

[root@tiandong64 ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:C7:20:71  
          inet addr:192.168.199.12  Bcast:192.168.199.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fec7:2071/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:41108 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13848 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:57855802 (55.1 MiB)  TX bytes:884097 (863.3 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

tunl0     Link encap:IPIP Tunnel  HWaddr   
          inet addr:192.168.199.63  Mask:255.255.255.255
          UP RUNNING NOARP  MTU:1480  Metric:1
          RX packets:25 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2080 (2.0 KiB)  TX bytes:0 (0.0 b)

二、關閉ARP轉發:

[root@tiandong64 ~]# vim /etc/sysctl.conf    在最後加上:
net.ipv4.conf.tunl0.arp_ignore = 1
net.ipv4.conf.tunl0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.tunl0.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0

[root@tiandong64 ~]# sysctl -p    是配置生效
三、配置web服務器

[root@tiandong64 ~]#yum install httpd -y

[root@tiandong64 ~]# echo 'this is 192.168.199.12' > /var/www/html/index.html    寫一個測試頁面
[root@tiandong64 ~]# /etc/init.d/httpd start

而後進行測試:

[root@localhost ~]#yum install elinks -y

[root@localhost ~]# elinks 192.168.199.63 --dump
   this is 192.168.199.11
[root@localhost ~]# elinks 192.168.199.63 --dump
   this is 192.168.199.12
[root@localhost ~]# elinks 192.168.199.63 --dump
   this is 192.168.199.11
[root@localhost ~]# elinks 192.168.199.63 --dump
   this is 192.168.199.12
在分發器上查看:  是平均分配的。

[root@openstack ~]# ipvsadm -ln --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  192.168.199.63:80                 4       20        0     1664        0
  -> 192.168.199.11:80                   2       10        0      832        0
  -> 192.168.199.12:80                   2       10        0      832        0

 使用webbench測試網站性能

下載並安裝webbench:

[root@tiandong63 ~]# wget http://www.ha97.com/code/webbench-1.5.tar.gz
[root@tiandong63 ~]# tar zxvf webbench-1.5.tar.gz
[root@tiandong63 ~]# cd webbench-1.5
[root@tiandong63 webbench-1.5]# yum install automake autoconf gcc -y
[root@tiandong63 webbench-1.5]# mkdir -p /usr/local/man/man1
[root@tiandong63 webbench-1.5]# make install
install -s webbench /usr/local/bin    
install -m 644 webbench.1 /usr/local/man/man1    
install -d /usr/local/share/doc/webbench
install -m 644 debian/copyright /usr/local/share/doc/webbench
install -m 644 debian/changelog /usr/local/share/doc/webbench

測試:

一個客戶端,持續時間1秒: 

-c爲客戶端數,-t爲時間(秒)
[root@tiandong63 webbench-1.5]# webbench -c 1 -t 1 http://192.168.199.11/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.199.11/index.html
1 client, running 1 sec.

Speed=233339 pages/min, 1127520 bytes/sec.

#當只有一個客戶端時,一分鐘能夠響應233329個頁面,1秒能夠傳輸1127520字節
Requests: 3889 susceed, 0 failed.
#1個客戶端,1秒產生了3889個請求,0個失敗。


使用20個客戶端併發訪問並持續訪問10秒

[root@tiandong63 webbench-1.5]# webbench -c 20 -t 10 http://192.168.199.11/index.htmlWebbench - Simple Web Benchmark 1.5Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.Benchmarking: GET http://192.168.199.11/index.html20 clients, running 10 sec.Speed=329556 pages/min, 1593115 bytes/sec.Requests: 54926 susceed, 0 failed.能夠同時查看被測試機器的性能:[root@tiandong63 ~]# vmstat 1 20procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st21  0      0 284568  61060 512612    0    0    23    62   42   46  1  1 97  1  0     4  0      0 282552  61060 513016    0    0     0     0 1005 19827 40 60  0  0  0     4  0      0 279824  61060 513612    0    0     0     0 1003 30257 44 56  0  0  0     4  0      0 277716  61060 514080    0    0     0     0 1004 23301 38 62  0  0  0     4  0      0 276476  61060 514520    0    0     0     0 1002 20532 41 59  0  0  0    19  0      0 274244  61068 514928    0    0     0    20 1003 18902 42 58  0  0  0     4  0      0 272632  61068 515532    0    0     0     0 1003 28352 40 60  0  0  0     5  0      0 272144  61068 516160    0    0     0     0 1004 31111 46 54  0  0  0     4  0      0 271896  61068 516720    0    0     0     0 1002 30103 44 56  0  0  0     4  0      0 273392  61068 517368    0    0     0     0 1003 31856 42 58  0  0  0   

相關文章
相關標籤/搜索