1、DR模式下vip不在同一网段上实现过程(跨网段)
环境
共五台
一台:客户端 桥接 172.16.17.77/24 GW: 172.16.17.17 桥接
一台:ROUTER
eth0:172.16.17.17/24 桥接
eth1:192.168.16.7/24 NAT
eth1:1:10.0.0.200/24
一台:LVS
lo:VIP:10.0.0.100/32
eth0:192.168.16.8/24 NAT GW:192.168.16.7
两台RS:
RS1:
lo:VIP:10.0.0.100/32
eth0:192.168.16.17/24 GW:192.168.16.7
RS2:
lo:VIP:10.0.0.100/32
eth0:192.168.16.27/24 GW:192.168.16.7
1.1 配置客户端网络
[root@client ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=172.16.17.77
PREFIX=24
GATEWAY=172.16.17.17
7ONBOOT=yes
1.2 配置路由器网络
[root@router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=172.16.17.17
PREFIX=24
ONBOOT=yes
[root@router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth1
BOOTPROTO=static
IPADDR=192.168.16.7
PREFIX=24
ONBOOT=yes
IPADDR1=10.0.0.200
PREFIX=24
#开启ip_forward
[root@router ~]#cat /etc/sysctl.conf
net.ipv4.ip_forward=1
[root@router ~]#sysctl -p
net.ipv4.ip_forward = 1
1.4 配置VS
[root@vs ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.16.8
PREFIX=24
GATEWAY=192.168.16.7
ONBOOT=yes
#执行lvs_dr_vs.sh
[root@vs ~]#cat lvs_dr_vs.sh
vip=10.0.0.100
mask=255.255.255.255
dev='lo:1'
port=80
rs1=192.168.16.17
rs2=192.168.16.27
scheduler='wrr'
type='-g'
rs1_weight=1
rs2_weight=1
rpm -ql ipvsadm &> /dev/null || yum -y install ipvsadm &> /dev/null
case $1 in
start)
ifconfig $dev $vip netmask $mask
ipvsadm -A -t ${vip}:${port} -s ${scheduler}
ipvsadm -a -t ${vip}:${port} -r ${rs1} ${type} -w ${rs1_weight}
ipvsadm -a -t ${vip}:${port} -r ${rs2} ${type} -w ${rs2_weight}
echo "The VS server is Ready!"
;;
stop)
ipvsadm -C
ifconfig $dev down
echo "The VS server is Canceled!"
;;
*)
echo "Usage: $(basename $0) start|stop"
exit 1
;;
esac
[root@vs ~]#bash lvs_dr_vs.sh start
1.3 配置RS
[root@rs1 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.16.17
PREFIX=24
GATEWAY=192.168.16.7
7ONBOOT=yes
[root@rs2 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.16.27
PREFIX=24
GATEWAY=192.168.16.7
ONBOOT=yes
#在两个RS上执行脚本
[root@rs1 ~]#cat lvs_dr_rs.sh
vip=10.0.0.100
mask='255.255.255.255'
dev='lo:1'
rpm -q httpd &> /dev/null || yum -y install httpd &> /dev/null
systemctl start httpd > /dev/null && echo "The httpd server is Ready!"
echo `hostname -I` > /var/www/html/indec.html
case $1 in
start)
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
ifconfig $dev $vip netmask $mask
echo "The RS server is Ready!"
;;
stop)
ifconfig $dev down
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "The RS server is Canceled!"
;;
*)
echo "Usage: $(basename $0) start|stop"
exit 1
;;
esac
[root@rs1 ~]#bash lvs_dr_rs.sh start
1.5 测试
[root@client ~]#while :; do curl 10.0.0.100;sleep 0.5 ;done
192.168.16.17
192.168.16.27
192.168.16.17
192.168.16.27
192.168.16.17
192.168.16.27
192.168.16.17
192.168.16.27
2、CentOS7.6 中 nfs 客户端使用 /etc/fatab 实现开机自动挂载
#创建共享文件夹
mkdir /data/nfs -pv
setfacl -m u:nobody:rwx /data/nfs
#安装nfs和rpc
yum install nfs-utils rpcbind -y
#修改配置文件
vim /etc/exports
/data/nfs 10.0.0.0/24(rw,all_squash,async)
#重读配置文件
exportfs -r
systemctl start nfs-server rpcbind
#在centos7 修改/etc/fstab 添加一下行
vim /etc/fstab
/data 10.0.0.8:/data/nfs nfs _netdev,noexec 0 0
3、CentOS7.6 中 nfs 客户端使用 autofs 实现使用 nfs 时实时挂载
yum install autofs -y
vim /etc/auto.master
/data /etc/data.nfs
vim /etc/data.nfs
* 10.0.0.8:/data/nfs