第八周
准备环境:
1.准备客户端环境:
[root@cip ~]# 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
ONBOOT=yes
2.准备router路由器环境:
#首先配置eth0是桥接模式 ip为172.16.17.17,eth1是NAT模式 ip为192.168.16.7
[root@router ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:b5:9d:3d brd ff:ff:ff:ff:ff:ff
inet 172.16.17.17/24 brd 172.16.17.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feb5:9d3d/64 scope link tentative
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:b5:9d:47 brd ff:ff:ff:ff:ff:ff
inet 192.168.16.7/24 brd 192.168.16.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feb5:9d47/64 scope link
valid_lft forever preferred_lft forever
#在eth0上增加个vip 10.0.0.200
[root@router ~]# nmcli connection modify eth1 +ipv4.addresses 10.0.0.200/24 ifname eth1
[root@router ~]# nmcli c reload
[root@router ~]# nmcli c up eth1
#网卡配置
[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
IPADDR=192.168.16.7
PREFIX=24
ONBOOT=yes
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR1=10.0.0.200
PREFIX1=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
[root@router ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:b5:9d:3d brd ff:ff:ff:ff:ff:ff
inet 172.16.17.17/24 brd 172.16.17.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feb5:9d3d/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:b5:9d:47 brd ff:ff:ff:ff:ff:ff
inet 192.168.16.7/24 brd 192.168.16.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feb5:9d47/64 scope link
valid_lft forever preferred_lft forever
[root@router ~]# vim /etc/sysctl.conf
[root@router ~]# sysctl -p
net.ipv4.ip_forward = 1
3.使用脚本配置LVS环境
[root@lvs ~]# yum -y install ipvsadm
[root@lvs network-scripts]# cat lvs.sh
4.准备后端服务器RS1,RS2
#准备RS1
[root@rs1 ~]# yum -y install httpd;systemctl enable --now httpd
[root@rs1 ~]# echo `hostname` > /var/www/html/index.html
[root@rs1 ~]# vim lvs.sh
5.客户端测试
[root@cip ~]#curl 10.0.0.100
rs1
[root@cip ~]#curl 10.0.0.100
rs2
[root@cip ~]#curl 10.0.0.100
rs1
[root@cip ~]#curl 10.0.0.100
rs2
2、CentOS7.6 中 nfs 客户端使用 /etc/fatab 实现开机自动挂载
环境:
10.0.0.7 服务器端
10.0.0.17 客户端
#服务器端配置
#安装包
[root@centos7 ~]#yum -y install nfs-utils
#开机自启
[root@centos7 ~]#systemctl enable --now nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@centos7 ~]#
#创建共享目录
[root@centos7 ~]# mkdir -pv /data/www
mkdir: created directory '/data/www'
[root@centos7 ~]# setfacl -m u:nobody:rwx /data/www
#实现共享
[root@centos7 ~]# vim /etc/exports
/data/www *(rw,all_squash,async)
#重新加载
[root@centos7 ~]#exportfs -r
[root@centos7 ~]# exportfs -v
/data/www <world>(sync,wdelay,hide,no_subtree_check,sec=sys,rw,root_squash,no_all_squash)
#客户端配置
[root@centos17 ~]#yum -y install nfs-utils
[root@centos17 ~]#systemctl enable --now nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@centos17 ~]#showmount -e 10.0.0.7
Export list for 10.0.0.7:
/data/www *
#实现开机自动挂载
[root@backup ~]# cat /etc/fstab
10.0.0.7:/data/www /data/backup nfs _netdev,noexec 0 0
3、CentOS7.6 中 nfs 客户端使用 autofs 实现使用 nfs 时实时挂载
环境:
10.0.0.7 服务器端
10.0.0.17 客户端
#服务器端配置
#安装包
[root@centos7 ~]#yum -y install nfs-utils
#开机自启
[root@centos7 ~]#systemctl enable --now nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@centos7 ~]#
#创建共享目录
[root@centos7 ~]# mkdir -pv /data/www
mkdir: created directory ‘/data/www’
[root@centos7 ~]# setfacl -m u:nobody:rwx /data/www
#实现共享
[root@centos7 ~]# vim /etc/exports
/data/www *(rw,all_squash,async)
#重新加载
[root@centos7 ~]#exportfs -r
[root@centos7 ~]# exportfs -v
/data/www <world>(sync,wdelay,hide,no_subtree_check,sec=sys,rw,root_squash,no_all_squash)
#客户端配置
[root@centos17 ~]#yum -y install nfs-utils
[root@centos17 ~]#systemctl enable --now nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@centos17 ~]#showmount -e 10.0.0.7
Export list for 10.0.0.7:
/data/www *
#相对路径
[root@centos17 ~]#yum -y install autofs
[root@centos17 ~]#vim /etc/auto.master
/data /etc/data.nfs
[root@centos17 ~]#vim /etc/data.nfs
backup 10.0.0.7:/data/www
[root@centos17 ~]#systemctl restart autofs
[root@centos17 ~]#df /data/backup
Filesystem 1K-blocks Used Available Use% Mounted on
10.0.0.7:/data/www 52403200 32896 52370304 1% /data/backup
#绝对路径
[root@centos17 ~]# vim /etc/auto.master
/- /etc/data.backup
[root@centos17 ~]# cat /etc/data.backup
/data/backup -ftype=nfs,vers=3 10.0.0.7:/data/www
[root@centos17 ~]# df /data/backup
Filesystem 1K-blocks Used Available Use% Mounted on
10.0.0.7:/data/www 52403200 32896 52370304 1% /data/backup
[root@centos17 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 485816 0 485816 0% /dev
tmpfs 497856 0 497856 0% /dev/shm
tmpfs 497856 7824 490032 2% /run
tmpfs 497856 0 497856 0% /sys/fs/cgroup
/dev/mapper/centos_centos7-root 104806400 1479884 103326516 2% /
/dev/sda1 1038336 153532 884804 15% /boot
/dev/mapper/centos_centos7-data 52403200 32992 52370208 1% /data
tmpfs 99572 0 99572 0% /run/user/0
10.0.0.7:/data/www 52403200 32896 52370304 1% /data/backup