NFS服务配置:
服务端: 10.0.0.31 172.16.1.31
客户端: 10.0.0.7 172.16.1.7
服务端配置:
1)安装服务
[root@nfs ~]# yum -y install nfs-utils
2)配置服务
[root@nfs ~]# vim /etc/exports
[root@nfs ~]# cat /etc/exports
/data *(rw,sync,all_squash)
3)根据服务配置创建必要的信息数据
[root@nfs ~]# mkdir /data
[root@nfs ~]# ll -d /data
drwxr-xr-x 2 root root 6 Jun 9 10:06 /data
4)启动并加入开机自动运行
[root@nfs ~]# systemctl start nfs
[root@nfs ~]# systemctl enable nfs
5)通过nfs特有的配置文件查看配置是否正确
检查/var/lib/nfs/etab 如果有内容说明配置正确
如果为空则配置有问题
[root@nfs ~]# cat /var/lib/nfs/etab
/data *(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,all_squash)
客户端: 10.0.0.7
1)客户端需要安装nfs-utils 不需要启动
[root@web01 ~]# yum -y install nfs-utils
2)通过shoumount命令查看服务端共享的目录
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data *
3)挂载31的/data目录到本地的/mnt临时挂载点
[root@web01 ~]# mount -t nfs 172.16.1.31:/data /mnt
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 1.7G 19G 9% /
devtmpfs 514M 0 514M 0% /dev
tmpfs 525M 0 525M 0% /dev/shm
tmpfs 525M 8.2M 517M 2% /run
tmpfs 525M 0 525M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 105M 0 105M 0% /run/user/0
172.16.1.31:/data 20G 1.7G 19G 9% /mnt
4) 使用 因为默认NFS客户连接NFS时所有的用户被压缩为NFS的匿名用户 nfsnobody uid65534
将共享的/data目录属主属组修改为nfsnobody
服务端: 10.0.0.31
[root@nfs ~]# chown nfsnobody.nfsnobody /data
[root@nfs ~]# ll -d /data
drwxr-xr-x 2 nfsnobody nfsnobody 19 Jun 9 10:23 /data
5) 客户端测试
[root@web01 ~]# touch /mnt/oldboy.txt
6) 卸载
[root@web01 ~]# umount /mnt
强制卸载
[root@web01 ~]# umount -f /mnt
7)加入开机挂载
vim /etc/rc.local
mount -t nfs 172.16.1.31:/data /mnt