exportfs命令


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 -onolock 192.168.133.130:/tmp /aminglinux
  • touch /aminglinux/test.txt
  • ls -l !$
  • -oremount,nfsvers=3

exportfs命令

  • exportfs命令和nfs-utils這個包一起安裝的
  • 例子:
    • 假設在第一次配置nfs的共享目錄,之后需要新增、更改某些機器或共享的目錄;
    • 首先需要更改配置文件,然后重啟NFS服務,但如果遠程客戶端正在使用NFS服務,正在掛載着,如果你需要先停止nfs服務,那遠程的客戶端就會掛起,就會很大的影響,造成服務異常,進程異常,有很大可能導致系統壞掉
  • nfs服務不能隨便重啟,要重啟,就需要先去服務器上,把掛載的目錄卸載下來
    • 在卸載目錄的時候,若是在當前目錄下去卸載會提示umount.nfs4: /mnt: device is busy
      • 方法一:退出該目錄后,再去卸載
      • 方法二:在目錄下卸載的時候,加 -l 選項,表示 lazy 懶惰的意思
    • 在卸載目錄后,在重啟nfs服務
  • 若是掛載了很多台機器,那么每台機器都需要去卸載,就會很麻煩,降低了工作效率
    • 方法:使用exportfs命令,重新加載下
  • exportfs命令
    • -a 全部掛載或者全部卸載
    • -r 重新掛載
    • -u 卸載某一個目錄
    • -v 顯示共享目錄
  1. 在B機器客戶端,卸載目錄
[root@hf-01 ~]# umount /mnt/ [root@hf-01 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 6.5G 12G 37% / devtmpfs 483M 0 483M 0% /dev tmpfs 493M 0 493M 0% /dev/shm tmpfs 493M 6.7M 486M 2% /run tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/sda1 197M 109M 88M 56% /boot tmpfs 99M 0 99M 0% /run/user/0 [root@hf-01 ~]# 
  1. 然后在A機器服務端,使用exportfs -arv命令
  • exportfs -arv命令,重新使配置文件生效
[root@hanfeng ~]# exportfs -arv exporting 192.168.202.0/24:/home/nfstestdir [root@hanfeng ~]# 
  1. 驗證,在A機器上的/etc/exports配置文件中,在增加一行,把 /tmp 目錄單獨共享給192.168.202.131 這個IP
[root@hanfeng ~]# vim /etc/exports 在配置文件中加入 /tmp 192.168.202.131(rw,sync,no_root_squash) 結果如下 /home/nfstestdir 192.168.202.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) /tmp 192.168.202.131(rw,sync,no_root_squash) 保存退出 
  1. 然后在A機器服務端執行exportfs -arv命令
[root@hanfeng ~]# exportfs -arv exporting 192.168.202.131:/tmp exporting 192.168.202.0/24:/home/nfstestdir [root@hanfeng ~]# 
  1. 在B機器客戶端showmount -e看是否生效——>並沒有重啟nfs服務,就已經生效
[root@hf-01 ~]# showmount -e 192.168.202.130 Export list for 192.168.202.130: /home/nfstestdir 192.168.202.0/24 /tmp 192.168.202.131 [root@hf-01 ~]# 
  1. 在B機器客戶端掛載,將 tmp目錄 掛載到 mnt 目錄下
[root@hf-01 ~]# mount -t nfs 192.168.202.130:/tmp/ /mnt/ [root@hf-01 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 6.5G 12G 37% / devtmpfs 483M 0 483M 0% /dev tmpfs 493M 0 493M 0% /dev/shm tmpfs 493M 6.7M 486M 2% /run tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/sda1 197M 109M 88M 56% /boot tmpfs 99M 0 99M 0% /run/user/0 192.168.202.130:/tmp 18G 3.2G 15G 18% /mnt [root@hf-01 ~]# 
  1. 現在在B機器客戶端,查看到的/mnt/目錄就是192.168.202.130IP下的tmp目錄
[root@hf-01 ~]# ls /mnt/ hanfeng.sock mysql.sock php-fcgi.sock test.com.log [root@hf-01 ~]# 
  1. 再到A機器上查看tmp目錄,會看到兩個目錄下的文件內容會一樣的
[root@hanfeng ~]# ls /tmp/ hanfeng.sock mysql.sock php-fcgi.sock test.com.log [root@hanfeng ~]# 
  1. 這時在B機器客戶端的mnt目錄下創建文件,並查看目錄下的文件,能看到新建的1212.txt文件的屬主和屬組都是root
[root@hf-01 ~]# vim /mnt/1212.txt [root@hf-01 ~]# ls -l /mnt/ 總用量 8 -rw-r--r-- 1 root root 12 117 2018 1212.txt srw-rw-rw- 1 root root 0 117 2018 hanfeng.sock srwxrwxrwx 1 mysql mysql 0 117 2018 mysql.sock srw-rw-rw- 1 root root 0 117 2018 php-fcgi.sock -rw-r--r-- 1 root root 2383 18 19:41 test.com.log [root@hf-01 ~]# 
  1. 這時再到A機器服務端查看tmp目錄,會看到1212.txt文件的屬主和屬組也是root
[root@hanfeng ~]# ls -l /tmp/ 總用量 8 -rw-r--r--. 1 root root 12 117 21:53 1212.txt srw-rw-rw-. 1 root root 0 117 18:44 hanfeng.sock srwxrwxrwx. 1 mysql mysql 0 117 18:44 mysql.sock srw-rw-rw-. 1 root root 0 117 18:44 php-fcgi.sock -rw-r--r--. 1 root root 2383 18 19:41 test.com.log [root@hanfeng ~]# 
  1. 這就是因為在A機器服務端的配置文件中,使用了no_root_squash ,所以root用戶不受約束,在B機器上到掛載點下,到共享目錄下,就可以像在本地磁盤使用root用戶一樣,是不受限制的(通常情況下,不限制root用戶的比較多)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM