2.1:直接路由模式(LVS-DR)
实验环境
关闭所有测试环境的防火墙
[root@bogon ~]# systemctl stop firewalld
[root@bogon ~]# setenforce 0
1.配置LVS调速器
(1)配置虚拟IP地址VIP
[root@lvs ~]# cd /etc/sysconfig/network-scripts/
[root@lvs network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@lvs network-scripts]# vim ifcfg-ens33:0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.10.172
NETMASK=255.255.255.0
#GATEWAY=192.168.10.254
DNS1=114.114.114.114
DNS2=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
[root@lvs network-scripts]# systemctl restart network
(2)调整内核参数,禁止转发重定向报文
[root@lvs network-scripts]# vim /etc/sysctl.conf
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects=0
[root@lvs network-scripts]# sysctl -p
(3)配置负载分配策略
[root@lvs network-scripts]# ipvsadm -C
[root@lvs network-scripts]# ipvsadm -A -t 192.168.10.172:80 -s wrr
[root@lvs network-scripts]# ipvsadm -a -t 192.168.10.172:80 -r 192.168.10.102 -g -w1
[root@lvs network-scripts]# ipvsadm -a -t 192.168.10.172:80 -r 192.168.10.103 -g -w1
[root@lvs network-scripts]# ipvsadm-save
-A -t bogon:http -s wrr
-a -t bogon:http -r bogon:http -g -w 1
-a -t bogon:http -r bogon:http -g -w 1
[root@lvs network-scripts]# systemctl enable ipvsadm
2.配置web节点服务器
(1)配置虚拟ip地址VIP
[root@web1 ~]# cd /etc/sysconfig/network-scripts/
[root@web1 network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@web1 network-scripts]# vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.10.172
NETMASK=255.255.255.255
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback
[root@web1 network-scripts]# systemctl restart network
[root@web1 network-scripts]# vim /etc/rc.local
/sbin/route add -host 192.168.10.172 dev lo:0
[root@web1 network-scripts]# route add -host 192.168.10.172 dev lo:0
(2)调整内核参数
[root@web1 network-scripts]# vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.lo.arp_ignore=1
net.ipv4.conf.lo.arp_announce=2
[root@web1 network-scripts]# sysctl -p
3.NFS共享存储服务
(1)安装nfs-utils、rpcbind软件包
[root@nfs ~]# yum -y install nfs-utils rpcbind
(2)设置共享目录
[root@nfs ~]# mkdir /opt/wwwroot
[root@nfs ~]# vim /etc/exports
/opt/wwwroot 192.168.10.0/24(rw,sync,no_root_squash)
(3)启动NFS服务程序
[root@nfs ~]# systemctl start nfs
[root@nfs ~]# systemctl start rpcbind
[root@nfs ~]# netstat -anpt | grep rpc
tcp 0 0 0.0.0.0:54815 0.0.0.0:* LISTEN 1718/rpc.statd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 1732/rpc.mountd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1728/rpcbind
tcp6 0 0 :::34675 :::* LISTEN 1718/rpc.statd
tcp6 0 0 :::20048 :::* LISTEN 1732/rpc.mountd
tcp6 0 0 :::111 :::* LISTEN 1728/rpcbind
[root@nfs ~]#
(4)查看本机发布的NFS共享目录
[root@nfs ~]# showmount -e
Export list for nfs:
/opt/wwwroot 192.168.10.0/24
[root@nfs ~]#
(5)在web节点挂载nfs
[root@web1 network-scripts]# yum -y install httpd nfs-utils
[root@web1 network-scripts]# systemctl start httpd
[root@web1 network-scripts]# mount 192.168.10.104:/opt/wwwroot/ /var/www/html/
(6)在nfs上创建测试网页
[root@nfs ~]# echo 'test' > /opt/wwwroot/index.html
4.去客户端测试
[root@bogon ~]# for i in $(seq 30); do curl http://192.168.10.172 ;done
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
5:在LVS调度器上查看LVS策略
[root@lvs network-scripts]# 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.10.172:80 wrr
-> 192.168.10.102:80 Route 1 0 18
-> 192.168.10.103:80 Route 1 0 18
[root@lvs network-scripts]#
标签:02,network,LVS,DR,192.168,nfs,scripts,test,root From: https://blog.csdn.net/qq_51678989/article/details/140930946