实验目标
- 搭建nfs服务器
- 开放/nfs/shared目录,供所有用户查阅资料
- 开放/nfs/upload目录为172.168.161.0/24网段的数据上传目录,并将所有用户及所属的用户组都映射为nfs-upliad,其UID与GID均为300
实验
布置实验所需环境
服务器端
[root@localhost ~]# yum -y install nfs-utils //安装nfs服务
[root@localhost ~]# systemctl start rpcbind nfs-server //开启服务
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:20048 *:*
LISTEN 0 128 *:37014 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 64 *:34210 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::20048 :::*
LISTEN 0 128 :::55284 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 64 :::40960 :::*
LISTEN 0 64 :::2049 :::*
[root@localhost ~]# systemctl status firewalld //查看防火墙是否关闭
[root@localhost ~]# systemctl stop firewalld //关闭防火墙
[root@localhost ~]# setenforce 0 //关闭selinux
客户端
[root@localhost ~]# yum -y install nfs-utils //安装nfs服务,客户端不用开启服务,但是需要安装nfs执行后续命令
[root@localhost ~]# systemctl stop firewalld //同上
[root@localhost ~]# setenforce 0
实验内容
完成实验内容一、二
在服务端创建服务所需目录
[root@localhost ~]# mkdir /nfs
[root@localhost ~]# cd /nfs
[root@localhost nfs]# mkdir shared
[root@localhost nfs]# ls
shared
编辑配置文件 /etc/exports
[root@localhost nfs]# vim /etc/exports
[root@localhost nfs]# exportfs -r //重新读取/etc/exports文件中的设置,并使其立即生效,无需重启服务
[root@localhost nfs]# cat /etc/exports
/nfs/shared *(sync)
客户端验证上述结果
[root@localhost ~]# showmount -e 192.168.161.150 //显示指定的NFS服务器上所有输出的共享目录
Export list for 192.168.161.150:
/nfs/shared *
完成实验内容三
服务器端
[root@localhost nfs]# mkdir upload
[root@localhost nfs]# ls
shared upload
[root@localhost nfs]# groupadd -g 300 nfs-upliad
[root@localhost nfs]# useradd -u 300 -g 300 nfs-upliad
[root@localhost nfs]# tail -5 /etc/passwd
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nfs-upliad:x:300:300::/home/nfs-upliad:/bin/bash
[root@localhost upload]# vim /etc/exports
[root@localhost upload]# cat /etc/exports
/nfs/shared *(sync)
/nfs/upload 192.168.161.0/24(rw,anonuid=300,anongid=300)
[root@localhost upload]# exportfs -r
[root@localhost nfs]# ll
总用量 0
drwxr-xr-x. 2 root root 42 10月 24 18:34 shared
drwxr-xr-x. 2 root root 42 10月 24 19:17 upload
[root@localhost nfs]# chmod 777 upload/
[root@localhost nfs]# chown nfs-upliad.nfs-upliad upload
[root@localhost nfs]# ll
总用量 0
drwxr-xr-x. 2 root root 42 10月 24 18:34 shared
drwxrwxrwx. 3 nfs-upliad nfs-upliad 42 10月 24 19:32 upload
客户端验证
[root@localhost ~]# mount -t nfs 192.168.161.150:/nfs /nfs
[root@localhost ~]# showmount -e 192.168.161.150
Export list for 192.168.161.150:
/nfs/shared *
/nfs/upload 192.168.161.0/24
[root@localhost ~]# cd /nfs
[root@localhost nfs]# ls
shared upload
[root@localhost nfs]# cd upload/
[root@localhost upload]# touch a b c
[root@localhost upload]# mkdir e
[root@localhost upload]# ll
总用量 0
-rw-r--r--. 1 300 300 0 10月 24 2019 a
-rw-r--r--. 1 300 300 0 10月 24 2019 b
-rw-r--r--. 1 300 300 0 10月 24 2019 c
drwxr-xr-x. 2 300 300 6 10月 24 2019 e