手动搭建一个nfs服务器
开放/nfs/shared目录,供所有用户查阅资料
开放/nfs/upload目录为172.16.12.0/24网段的数据上传目录,并将所有用户及所属的用户组都映射为nfs-upload,其UID与GID均为300
服务端配置:
1.安装nfs
[root@100 ~]# yum -y install nfs-utils
2.关闭防火墙和selinux
[root@100 ~]# systemctl stop firewalld //关闭防火墙
[root@100 ~]# vim /etc/selinux/config //编辑selinux配置文件
SELINUX=enforcing //将此项改为enforcing
[root@100 ~]# systemctl status firewalld //设置防火墙为开机不启动
[root@100 ~]# setenforce 0
3.启动nfs服务和rpcbind
[root@100 ~]# systemctl start nfs-server rpcbind
[root@100 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:139 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:20048 *:*
LISTEN 0 64 *:35890 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 50 *:445 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 128 *:44643 *:*
LISTEN 0 50 :::139 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::20048 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 50 :::445 :::*
4.创建共享目录
[root@100 ~]# mkdir -p /nfs/{shared,upload}
[root@100 ~]# ls /nfs/
shared upload
[root@100 ~]#
5.创建用户和组nfs-upload其uid和gid都为300
[root@100 ~]# useradd -r -u300 nfs-upload
[root@100 ~]# id nfs-upload
uid=300(nfs-upload) gid=300(nfs-upload) 组=300(nfs-upload)
[root@100 ~]#
6.编辑配置文件共享目录
[root@100 ~]# vim /etc/exports
/nfs/shared *(ro)
/nfs/upload 192.168.100.0/24(rw,sync,all_squash,anonuid=300,anongid=300)
[root@100 ~]# exportfs -r
客户端配置
1.安装nfs
[root@96 ~]# yum -y install nfs-utils //安装
[root@96 ~]# systemctl stop firewalld //关闭防火墙
[root@96 ~]# vim /etc/selinux/config //关闭selinux
SELINUX=enforcing
[root@96 ~]# systemctl disable firewalld //禁止开机自启动
[root@96 ~]# setenforce 0
2.使用shoumount命令测试NFS服务器的输出目录状态
[root@96 upload]# showmount -e 192.168.100.100
Export list for 192.168.100.100:
/nfs/shared *
/nfs/upload 192.168.100.0/24
[root@96 upload]#
3.启动服务
[root@96 ~]# systemctl start nfs-server
[root@96 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:47533 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 64 *:43824 *:*
LISTEN 0 128 *:20048 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::20048 :::*
LISTEN 0 128 :::47409 :::*
LISTEN 0 64 :::42356 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 64 :::2049 :::*
4.创建挂载点
[root@96 ~]# mkdir /nfs
5.挂载
[root@96 ~]# mount -t nfs 192.168.100.100:/nfs /nfs
[root@96 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 17G 1.2G 16G 7% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.6M 901M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 1014M 146M 869M 15% /boot
tmpfs 182M 0 182M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
192.168.100.100:/nfs 17G 2.0G 16G 12% /nfs
6.验证
// 将服务端的共享目录设置属主和属组都为nfs-upload
[root@100 nfs]# chown -R nfs-upload.nfs-upload /nfs/
[root@100 nfs]# ll
总用量 0
drwxr-xr-x. 2 nfs-upload nfs-upload 6 7月 2 14:11 shared
drwxr-xr-x. 2 nfs-upload nfs-upload 15 7月 2 15:14 upload
客户端验证:
[root@96 ~]# cd /nfs/
[root@96 nfs]# ls
shared upload
[root@96 nfs]#
[root@96 nfs]# cd shared/
[root@96 shared]# touch abc
touch: 无法创建"abc": 只读文件系统 //share为只读的目录
[root@96 shared]# cd ..
[root@96 nfs]# cd upload/
[root@96 upload]# touch abc //192.168.100.0这个网段对upload这个目录有读写权限
[root@96 upload]# ls
abc
[root@96 upload]#