安装yum
[root@localhost ~]# yum install -y nfs-utils
修改配置文件
[root@localhost ~]# vim /etc/exports
在vim中写入
/home/nfstestdir 172.16.1.0/16(rw,sync,all_squash,anonuid=1000,anongid=1000)
编辑并启动nfs
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# mkdir /home/nfstestdir
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl enable nfs
客户端挂载nfs
[root@a yum.repos.d]# showmount -e 172.16.1.196
Export list for 172.16.1.196:
/home/nfstestdir 172.16.1.0/16
挂载
[root@a ~]# mount -t nfs 172.16.1.196:/home/nfstestdir /mnt/
[root@a ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 18G 1.2G 16G 8% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 13M 476M 3% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 488M 93M 360M 21% /boot
tmpfs 98M 0 98M 0% /run/user/0
172.16.1.196:/home/nfstestdir 18G 1.3G 15G 8% /mnt
创建测试文件
[root@a ~]# cd /mnt/
[root@a mnt]# touch txt.txt
touch: 无法创建"txt.txt": 权限不够
在服务器上设置
[root@localhost ~]# chmod 777 /home/nfstesdir/
[root@localhost ~]#
在客户端上创建测试文件
[root@a ~]# cd /mnt/
[root@a mnt]# touch txt.txt
[root@a mnt]# ls -l
总用量 0
-rw-r--r--. 1 1000 1000 0 4月 24 11:20 txt.txt
在服务器上修改配置文件
[root@localhost ~]# vim /etc/exports
多加一行
/tmp/172.16.1.0/16(rw,sync,no_root_squash)
在执行exportfs -arv命令
[root@localhost ~]# exportfs -arv
exportfs: No options for /tmp/172.16.1.0/16(rw,sync,no_root_squash) : suggest (sync) to avoid warning
exporting 172.16.1.0/16:/home/nfstestdir
exporting :/tmp/172.16.1.0/16(rw,sync,no_root_squash)
exportfs: Failed to stat /tmp/172.16.1.0/16(rw,sync,no_root_squash): No such file or directory
[root@localhost ~]#
在客户端上
[root@a mnt]# mount -t nfs -o nolock 172.16.1.196:/tmp/ /wl/
[root@a mnt]#