安裝centos
centos7---vs
centos6---RS1、RS2
centos6---client
最小化安裝centos,配置yum源;
cd /etc/yum.repos.d/
rm-rf *
vi base.repo
[base]
baseurl=file:///mnt
gpgcheck=0
#yum repolist
#yum makecache
#yum install vim
#yum install autofs
chkconfig autofs on
service autofs start
#vim base.repo
[base]
baseurl=file:///misc/cd
gpgcheck=0
設置ip地址,設置為靜態ip;
使用VMware 僅主機和自定義模式(僅主機)
1、vs外網網卡設置為自定義模式;ip;192.168.183.151
vs內網網卡設置為僅主機模式;ip:192.168.226.151
2、RS1;僅主機模式,ip;192.168.226.140
RS2;僅主機模式,ip;192.168.226.141
3、client;自定義模式;ip;192.168.183.130
關閉防火墻及SElinux設置;
centos6;
#chkconfig iptables off
#chkconfig list iptables
#vim /etc/selinux/conf
#setenforce 0
#getenforce
centos7;
systemctl enable firewalld
systemctl stop firewalld
#vim /etc/selinux/conf
#setenforce 0
#getenforce
1、VS(centos7)安裝ipvsadm;
設置VS服務模式;
設置VS的算法;
開啟ipv4轉發功能;
2、RS(centos6)安裝httpd;
設置簡單的網頁;
將RS網關指向VS(192.168.226.151);
3、client客戶端訪問vs端網頁;
1、VS (centos 7)上安裝ipvsadm,設置/etc/sysctl.conf配置文件、設置VS服務模式及算法;
#yum install ipvsadm
#Vim /etc/sysctl.conf
Net.ipv4.ip_forward=1
#ipvsadm -A -t 192.168.183.151:80 -s rr---模式
#ipvsadm -a -t 192.168.183.151:80 -r 192.168.226.140 -m ---算法
#ipvsadm -a -t 192.168.183.151:80 -r 192.168.226.141 -m
2、RS服務器將網關指向VS服務器,安裝httpd并啟用;
RS1;
# vim /etc/sysconfig/network-scripts
DEVICE=eth0
IPADDR=192.168.226.140
PREFIX=24
GATEWAY=192.168.226.151
RS2;
# vim /etc/sysconfig/network-scripts
DEVICE=eth0
IPADDR=192.168.226.141
PREFIX=24
GATWAY=192.168.226.151
#yum install httpd
#service httpd start
#chkconfig httpd on
創建簡單的網頁;
echo RS1 SERVER >/var/www/html/index.html
echo RS2 SERVER >/var/www/html/index.html
3、client客戶端訪問網頁,檢測是否成功;
#curl 192.168.183.151
#if i in {1..10};do curl 192.168.183.151;done
[root@client ~]#for i in {1..10};do curl 192.168.183.151;sleep 1;done
RS1 SERVICE
RS2 SERVICE
RS1 SERVICE
RS2 SERVICE
RS1 SERVICE
RS2 SERVICE
RS1 SERVICE
RS2 SERVICE
RS1 SERVICE
RS2 SERVICE
4、在vs上查看連接狀態;
#Ipvsadm -Ln
[root@VS1 ~]# 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.183.151:80 rr
-> 192.168.226.140:80 Masq 1 0 8
-> 192.168.226.141:80 Masq 1 0 8
5、測試性能;
[root@client ~]#ab -c 100 -n 10000 http://192.168.183.151/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.183.151 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.2.15
Server Hostname: 192.168.183.151
Server Port: 80
Document Path: /
Document Length: 12 bytes
Concurrency Level: 100
Time taken for tests: 4.102 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2785829 bytes
HTML transferred: 120036 bytes
Requests per second: 2437.62 [#/sec] (mean)
Time per request: 41.024 [ms] (mean)
Time per request: 0.410 [ms] (mean, across all concurrent requests)
Transfer rate: 663.16 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 8 9.4 6 188
Processing: 5 33 16.7 30 231
Waiting: 3 32 16.2 30 231
Total: 22 40 19.1 39 240
Percentage of the requests served within a certain time (ms)
50% 39
66% 41
75% 42
80% 42
90% 44
95% 45
98% 48
99% 56
100% 240 (longest request)
6、查看誰在訪問;
Cat /var/log/httpd/access_log
7、查看誰訪問的數量;
[root@RS1 network-scripts]#cut -d" " -f1 /var/log/httpd/access_log |sort - nr|uniq -c|sort -n
1 192.168.226.140
3 192.168.226.151
10 ::1
102 192.168.183.151
10328 192.168.183.130
8、查看每秒鐘的訪問數據平均速度;
[root@VS1 ~]# ipvsadm -Ln --rate
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port CPS InPPS OutPPS InBPS OutBPS
-> RemoteAddress:Port
TCP 192.168.183.151:80 1 5 5 447 545
-> 192.168.226.140:80 0 3 2 223 272
-> 192.168.226.141:80 0 3 2 224 273
9、更改vs算法,更改RS權數;
Ipvsadm -E -t 192.168.183.151:80 -s wrr
Ipvsadm -e -t 192.168.183.151:80 -r 192.168.226.141 -m -w 3
再次訪問時會有變化;
[root@client ~]#for i in {1..100};do curl 192.168.183.151;sleep 1;done
RS2 SERVICE
RS1 SERVICE
RS2 SERVICE
RS2 SERVICE
RS2 SERVICE
RS1 SERVICE
刪除網卡模塊;
/etc/udev/rules.d/70-persistent-ipoib.rules
- 卸載模塊
- Rmmod e1000
- Modprobe e1000
添加ip地址
ip a add 192.168.226.151/24 dev eth0
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。