搭建环境
服务器地址为192.168.93.130/24,客户端地址为192.168.93.129/24
1.开放/nfs/shared目录,供所有用户查阅资料
(1)关闭防火墙
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# vim /etc/selinux/config
[root@server ~]# getenforce
Enforcing
(2)安装nfs服务
[root@server ~]# yum -y install nfs-utils
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 1:nfs-utils-1.3.0-0.48.el7.x86_64 已安装并且是最新版本
无须任何处理
(3)启动nfs服务 和 rpcbind
[root@server ~]# systemctl start rpcbind nfs-server
[root@server ~]# 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 128 *:57232 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 50 *:445 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 64 *:34821 *:*
LISTEN 0 50 :::139 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::20048 :::*
LISTEN 0 64 :::36148 :::*
LISTEN 0 128 :::39380 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 50 :::445 :::*
LISTEN 0 64 :::2049 :::*
(4)创建/nfs/shared共享目录
[root@server ~]# mkdir /nfs
[root@server ~]# cd /nfs
[root@server nfs]# ls
[root@server nfs]# mkdir /shared
[root@server nfs]# ls
shared
(5)修改/etc/exports文件
[root@server ~]# vim /etc/exports
[root@server ~]# cat /etc/exports
/nfs/shared *(ro,sync)
(6)重启nfs
[root@server ~]# systemctl restart nfs-server rpcbind
(1)关闭防火墙
[root@jxy ~]# systemctl stop firewalld
[root@jxy ~]# systemctl disable firewalld
[root@jxy ~]# vim /etc/selinux/config
[root@jxy ~]# getenforce
Enforcing
(2)搭建nfs服务
[root@jxy ~]# yum -y install nfs-utils
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 1:nfs-utils-1.3.0-0.48.el7.x86_64 已安装并且是最新版本
无须任何处理
(3)启动,查看nfs服务
[root@jxy ~]# systemctl start rpcbind nfs-server
[root@jxy ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:139 *:*
LISTEN 0 64 *:35661 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:20048 *:*
LISTEN 0 128 *:55761 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 50 *:445 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 50 :::139 :::*
LISTEN 0 128 :::45422 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::20048 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 50 :::445 :::*
LISTEN 0 64 :::2049 :::*
LISTEN 0 64 :::40258 :::*
(4)验证nfs服务端的共享目录
[root@jxy ~]# showmount -e 192.168.93.130
Export list for 192.168.93.130:
/nfs/shared 192.168.93.130
(5)创建和挂载共享目录站点
[root@jxy ~]# mkdir /gege
[root@jxy ~]# mount -t nfs 192.168.93.130:/nfs/shared /gege
[root@jxy /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 17G 1.7G 16G 10% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.7M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sr0 3.8G 3.8G 0 100% /mnt
/dev/sda1 1014M 143M 872M 15% /boot
tmpfs 183M 0 183M 0% /run/user/0
192.168.93.130:/jiangxiuying 17G 1.7G 16G 10% /nfs
(6)在服务端创建文件或者目录
[root@server ~]# cd /nfs/shared/
[root@server shared]# touch 111
[root@server shared]# ls
111
[root@server shared]# mkdir 222
[root@server shared]# ls
111 222
(7)在客户端查看
[root@jxy ~]# cd /nfs/shared/
[root@jxy shared]# ls
111 222
2.开放/nfs/upload目录为172.16.12.0/24网段的数据上传目录,并将所有用户及所属的用户组都映射为nfs-upload,其UID与GID均为300
(1)创建/nfs/upload目录
[root@server ~]# cd /nfs
[root@server nfs]# ls
shared
[root@server nfs]# mkdir upload
[root@server nfs]# ls
shared upload
(2)创建用户nfs-upload,UID和GID为300
[root@server ~]# useradd -r -u 300 nfs-upload
[root@server ~]# id nfs-upload
uid=300(nfs-upload) gid=300(nfs-upload) 组=300(nfs-upload)
(3)修改/nfs/exports文件
[root@server ~]# cat /etc/exports
/nfs/upload 192.168.93.0/24(rw,anonuid=300,anongid=300,sync)
(4)重启NFS
[root@server ~]# systemctl restart nfs-server rpcbind
(5)查看NFS服务器的共享目录
[root@jxy ~]# showmount -e 192.168.93.130
Export list for 192.168.93.130:
/nfs/upload 192.168.93.0/24
(6)挂载共享目录
[root@jxy ~]# mount -t nfs 192.168.93.130:/nfs/upload/ /jxy
[root@jxy ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 17G 1.7G 16G 10% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.7M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sr0 3.8G 3.8G 0 100% /mnt
/dev/sda1 1014M 143M 872M 15% /boot
tmpfs 183M 0 183M 0% /run/user/0
192.168.93.130:/jiangxiuying 17G 1.7G 16G 10% /nfs
192.168.93.130:/jiangxiuying/upload 17G 1.7G 16G 10% /jxy
(7)在客户端创建文件和删除文件
[root@jxy ~]# cd /jxy
[root@jxy jxy]# ls
[root@jxy jxy]# touch 123
[root@jxy jxy]# ls
123
[root@jxy jxy]# mkdir 456
[root@jxy jxy]# ls
123 456
[root@jxy jxy]# rm -rf 123
[root@jxy jxy]# ls
456