1.DR模式下vip不在同一网段上实现过程
#环境
internet client:
IP:192.168.0.6/24
GW:192.168.0.200
ROUTE:
#注意:启动ip_forward功能
eth0:10.0.0.200/24 NAT模式
172.16.0.200/24 NAT模式
eth1:192.168.0.200/24 仅主机
LVS:
lo:VIP:172.16.0.100/32
eth0:10.0.0.8/24
GW:10.0.0.200
RS1:
lo:VIP:172.16.0.100
eth0:10.0.0.7/24
GW:10.0.0.200
RS2:
lo:VIP:172.16.0.100
eth0:10.0.0.17/24
GW:10.0.0.200
网络环境配置
#internet主机环境配置
[18:52:48 root@internet-client ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.10.6
NAME=eth0
PREFIX=24
GATEWAY=192.168.10.200
#Route 环境配置
#eth1是仅主机模式
[15:30:55 root@Router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth1
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.10.200
PREFIX=24
#eth0是NAT模式
[15:31:17 root@Router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24
[15:35:51 root@Router ~]#echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
[15:40:10 root@Router ~]#sysctl -p
vm.swappiness = 1
net.ipv4.ip_forward = 1
[15:35:46 root@Router ~]#ip a
eth0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:58:24:26 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe58:2426/64 scope link
valid_lft forever preferred_lft forever
eth1: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:58:24:30 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.200/24 brd 192.168.10.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe58:2430/64 scope link
valid_lft forever preferred_lft forever
#LVS 环境配置
[15:44:16 root@LVS ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.8
GATEWAY=10.0.0.200 #注意网关的配置
PREFIX=24
[15:46:01 root@LVS ~]#ip add a 10.0.0.100 dev lo
[15:44:22 root@LVS ~]#ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 10.0.0.100/32 scope global lo #添加回环网卡
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:a8:12:28 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea8:1228/64 scope link
valid_lft forever preferred_lft forever
#RS网卡配置
[root@RS1 ~]#ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 10.0.0.100/32 scope global lo #添加回环网卡命令: ip add a 10.0.0.100 dev lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:18:f1:d5 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.7/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
[root@RS1 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.7
GATEWAY=10.0.0.200
PREFIX=24
[root@RS1 ~]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@RS2 ~]#ip add a 10.0.0.100 dev lo
[root@RS2 ~]#ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 10.0.0.100/32 scope global lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:fd:47:d3 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.17/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
[root@RS2 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
OTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.17
GATEWAY=10.0.0.200
PREFIX=24
[root@RS2 ~]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
#RS1和RS2的网页设置
[root@RS1 ~]#cat /var/www/html/index.html
10.0.0.7 RS1
[root@RS2 ~]#cat /var/www/html/index.html
10.0.0.17 RS2
#测试router左右两侧能否ping通
[16:10:41 root@Router ~]#ping 192.168.10.6
PING 192.168.10.6 (192.168.10.6) 56(84) bytes of data.
64 bytes from 192.168.10.6: icmp_seq=1 ttl=64 time=1.72 ms
64 bytes from 192.168.10.6: icmp_seq=2 ttl=64 time=2.46 ms
^C
--- 192.168.10.6 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 4ms
rtt min/avg/max/mdev = 1.715/2.089/2.464/0.377 ms
[16:10:54 root@Router ~]#ping 10.0.0.8
PING 10.0.0.8 (10.0.0.8) 56(84) bytes of data.
64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=1.04 ms
64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.791 ms
^C
--- 10.0.0.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 0.791/0.915/1.040/0.128 ms
[16:11:03 root@Router ~]#ping 10.0.0.7
PING 10.0.0.7 (10.0.0.7) 56(84) bytes of data.
64 bytes from 10.0.0.7: icmp_seq=1 ttl=64 time=1.80 ms
64 bytes from 10.0.0.7: icmp_seq=2 ttl=64 time=0.636 ms
^C
--- 10.0.0.7 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 0.636/1.216/1.797/0.581 ms
[16:11:07 root@Router ~]#ping 10.0.0.17
PING 10.0.0.17 (10.0.0.17) 56(84) bytes of data.
64 bytes from 10.0.0.17: icmp_seq=1 ttl=64 time=2.40 ms
64 bytes from 10.0.0.17: icmp_seq=2 ttl=64 time=0.615 ms
^C
--- 10.0.0.17 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 0.615/1.505/2.396/0.891 ms
后端RS的IPVS配置
#RS1的IPVS配置
[root@RS1 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@RS1 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@RS1 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@RS1 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
#RS2的IPVS配置
[root@RS2 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@RS2 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@RS2 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@RS2 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
LVS主机的配置
[19:54:27 root@internet-client ~]#curl 10.0.0.100
10.0.0.7 RS1
[19:54:46 root@internet-client ~]#curl 10.0.0.100
10.0.0.17 RS2
[19:54:47 root@internet-client ~]#curl 10.0.0.100
10.0.0.7 RS1
[19:54:48 root@internet-client ~]#curl 10.0.0.100
10.0.0.17 RS2
2.CentOS7.6 中 nfs 客户端使用 /etc/fstab 实现开机自动挂载
nfs服务端
[15:42:52 root@localhost ~]#yum -y install nfs-utils
[15:44:58 root@localhost ~]#mkdir -p /data/test
[15:46:10 root@localhost ~]#vi /etc/exports.d/test.exports
/data/test *(rw,no_root_squash)
[15:47:27 root@localhost ~]#systemctl enable --now nfs
[15:47:40 root@localhost ~]#exportfs -v
/data/test (sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
nfs客户端
[15:42:55 root@localhost ~]#yum -y install nfs-utils autofs
[15:54:21 root@localhost ~]#mkdir -p /data/client
[15:45:10 root@localhost ~]#vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Jul 2 20:36:36 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=0869ea75-71ee-469c-8090-98e42b29651c / xfs defaults 0 0
UUID=31e83445-f544-4731-97c3-a9575b0ed3b7 /boot xfs defaults 0 0
UUID=392c3d3b-06bf-41eb-9a26-f39368e2fc28 /data xfs defaults 0 0
UUID=fb7894ed-d9ec-4b33-86f4-d6c8c52c1180 swap swap defaults 0 0
10.0.0.77:/data/test /data/client nfs _netdev 0 0
[15:54:27 root@localhost ~]#mount -a
[15:55:01 root@localhost ~]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda2 100G 1.6G 99G 2% /
/dev/sda1 1014M 131M 884M 13% /boot
/dev/sda3 50G 33M 50G 1% /data
tmpfs 98M 0 98M 0% /run/user/0
10.0.0.77:/data/test 50G 33M 50G 1% /data/client
3.CentOS7.6 中 nfs 客户端使用 autofs 实现使用 nfs 时实时挂载
nfs服务端
[15:42:52 root@localhost ~]#yum -y install nfs-utils
[15:44:58 root@localhost ~]#mkdir -p /data/test
[15:46:10 root@localhost ~]#vi /etc/exports.d/test.exports
/data/test *(rw,no_root_squash)
[15:47:27 root@localhost ~]#systemctl enable --now nfs
[15:47:40 root@localhost ~]#exportfs -v
/data/test (sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
nfs客户端
[15:42:55 root@localhost ~]#yum -y install nfs-utils autofs
[15:55:27 root@localhost ~]#vi /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc /etc/auto.misc
/- /etc/test.client
........
[15:57:36 root@localhost ~]#vi /etc/test.client
/data/client -fstype=nfs,vers=3 10.0.0.77:/data/test
[15:58:36 root@localhost ~]#systemctl restart autofs
[16:10:31 root@localhost ~]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda2 100G 1.6G 99G 2% /
/dev/sda1 1014M 131M 884M 13% /boot
/dev/sda3 50G 33M 50G 1% /data
tmpfs 98M 0 98M 0% /run/user/0
[16:10:34 root@localhost ~]#cd /data/client/
[16:10:39 root@localhost client]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda2 100G 1.6G 99G 2% /
/dev/sda1 1014M 131M 884M 13% /boot
/dev/sda3 50G 33M 50G 1% /data
tmpfs 98M 0 98M 0% /run/user/0
10.0.0.77:/data/test 50G 33M 50G 1% /data/client