1. 程式人生 > >nfs下的exportfs命令和nfs客戶端重新掛載

nfs下的exportfs命令和nfs客戶端重新掛載

exportfs nfs remount mount nfs4

工作中,如果使用了nfs服務器,會遇到修改nfs服務器配置的情況,如果想重新讓客戶端加載上修改後的配置,
但是又不能重啟rpcbind服務,我們需要使用export命令了

exportfs命令
常用選項
-a 全部掛載或者全部卸載
-r 重新掛載
-u 卸載某一個目錄
-v 顯示共享目錄
以下操作在服務端上

實驗:兩臺centos7

vim /etc/exports
//增加
/tmp/ 192.168.133.0/24(rw,sync,no_root_squash)
exportfs -arv //不用重啟nfs服務,配置文件就會生效
nfs服務不能隨便重啟,重啟服務會對掛載了nfs的客戶端有影響,
exportfs來自nfs-utils包

作用是修了配置後重載,不用重啟服務。
服務器:

[root@JAMF nfsdir]# vim /etc/exports     
/home/nfsdir 172.16.22.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
/tmp 172.16.22.0/24(rw,sync,no_root_squash)
[root@JAMF nfsdir]# exportfs -arv
exporting 172.16.22.0/24:/tmp
exporting 172.16.22.0/24:/home/nfsdir

客戶端:

[root@zabbix ~]# showmount -e 172.16.22.247                           
Export list for 172.16.22.247:
/tmp         172.16.22.0/24
/home/nfsdir 172.16.22.0/24
[root@zabbix ~]# mkdir /mnt/tmp
[root@zabbix ~]# mount -t nfs -onolock 172.16.22.247:/tmp /mnt/tmp 
-o nolock 了,即在掛載nfs服務時,不加鎖。 在客戶端上執行:
[root@zabbix ~]# touch /mnt/tmp/new.txt
[root@zabbix tmp]# ll /mnt/tmp/new.txt   
-rw-r--r-- 1 root root 0 Mar 16 01:41 /mnt/tmp/new.txt

服務器:

[root@JAMF nfsdir]# ll /tmp/new.txt 
-rw-r--r-- 1 root root 0 Mar 16 01:41 /tmp/new.txt

[root@zabbix mnt]# mount -t nfs -Oremount,nfsvers=3 172.16.22.247:/tmp /mnt/tmp
mount.nfs: /mnt/tmp is busy or already mounted
[root@zabbix mnt]# umount /mnt/tmp/                                            
[root@zabbix mnt]# mount -t nfs -Oremount,nfsvers=3 172.16.22.247:/tmp /mnt/tmp

#NFS客戶端問題:NFS 4版本會有該問題

客戶端文件屬主屬組nobody

客戶端掛載共享目錄後,不管是root用戶還是普通用戶,創建新文件時屬主、屬組為nobody
客戶端掛載時加上 -O nfsvers=3

[root@zabbix mnt]# mount -t nfs -Oremount,nfsvers=3 172.16.22.247:/tmp /mnt/tmp
mount.nfs: /mnt/tmp is busy or already mounted
[root@zabbix mnt]# umount /mnt/tmp/                                            
[root@zabbix mnt]# mount -t nfs -Oremount,nfsvers=3 172.16.22.247:/tmp /mnt/tmp

客戶端和服務端都需要
vim /etc/idmapd.conf //
把“#Domain = local.domain.edu” 改為 “Domain = xxx.com” (這裏的xxx.com,隨意定義吧),然後再重啟rpcidmapd服務
服務器:

[root@JAMF nfsdir]# 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 = jamf.oceanwing.com
[root@JAMF nfsdir]# systemctl restart rpcidmapd
客戶端:

[root@zabbix mnt]# 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 = zabbix.oceanwing.com
[root@zabbix mnt]# systemctl restart rpcidmapd

nfs下的exportfs命令和nfs客戶端重新掛載