lvs服务---nat模式

安装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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容