14.4 exportfs命令
经常使用选项 -a 所有挂载或者所有卸载 -r 从新挂载 -u 卸载某一个目录 -v 显示共享目录 如下操做在服务端上 vim /etc/exports //增长 /tmp/ 192.168.133.0/24(rw,sync,no_root_squash) exportfs -arv //不用重启nfs服务,配置文件就会生效
如下操做在客户端 mkdir /aminglinux mount -t nfs -o nolock 192.168.133.130:/tmp /aminglinux //-o nolock是不加锁,nfs经常使用; touch /aminglinux/test.txt ls -l !$ -oremount,nfsvers=3
若是直接重启NFS服务端的话,无论理客户端的挂载状况,那么客户端颇有可能产生d进程,没法杀死处理的进程;这里咱们就借助exportfs命令!linux
一、NFS服务端配置:
[root@DasonCheng ~]# echo '/tmp/ 192.168.60.12(rw,sync,no_root_squash)' >> /etc/exports [root@DasonCheng ~]# cat /etc/exports /home/nfstestdir 192.168.60.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) /tmp/ 192.168.60.12(rw,sync,no_root_squash) [root@DasonCheng ~]# exportfs -arv //从新挂载,并显示共享目录;这样就不用重启nfs服务; exporting 192.168.60.12:/tmp exporting 192.168.60.0/24:/home/nfstestdir
二、NFS客户端配置:
[root@aming2 ~]# showmount -e 192.168.60.11 //exportfs以后,就有了/tmp Export list for 192.168.60.11: /home/nfstestdir 192.168.60.0/24 /tmp 192.168.60.12 [root@aming2 ~]# mkdir /aming [root@aming2 ~]# mount -t nfs -o nolock 192.168.60.11:/tmp/ /aming [root@aming2 ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 192.168.60.11:/home/nfstestdir 19G 7.0G 12G 38% /mnt 192.168.60.11:/tmp 19G 7.0G 12G 38% /aming [root@aming2 ~]# echo 'testtestfile' >/aming/test.txt [root@aming2 ~]# ll /aming/ -rw-r--r--. 1 root root 13 8月 24 23:30 test.txt //新建立的文件是root,这就是no_root_squash的做用,至关于root最高权限在本地文件
14.5 NFS客户端问题
客户端文件属主属组nobody NFS 4版本会有该问题 客户端挂载共享目录后,无论是root用户仍是普通用户,建立新文件时属主、属组为nobody 客户端挂载时加上 -o nfsvers=3 客户端和服务端都须要 vim /etc/idmapd.conf // 把“#Domain = local.domain.edu” 改成 “Domain = xxx.com” (这里的xxx.com,随意定义吧),而后再重启rpcidmapd服务
- 法1:
[root@aming2 ~]# mount -t nfs -o nolock -o nfsvers=3 192.168.60.11:/tmp /aming //这样挂载;-o nfsvers=3 [root@aming2 ~]# mount -t nfs -oremount,nfsvers=3 192.168.60.11:/tmp /aming //或者remount从新挂载也行;
- 法2:
客户端和服务端都须要 vim /etc/idmapd.conf //把“#Domain = local.domain.edu” 改成 “Domain = xxx.com” (这里的xxx.com,随意定义吧) [root@DasonCheng ~]# vim /etc/idmapd.conf //服务端和客户端都须要编辑; [General] #Verbosity = 0 # The following should be set to the local NFSv4 domain name # The default is the host's DNS domain name. Domain = aaa.com //自定义一个域名,随机; [root@DasonCheng ~]# systemctl restart rpcidmapd //重启rpcidmapd或者rpcbind服务都行;