1. 程式人生 > >NFS的exportfs命令、客戶端問題介紹

NFS的exportfs命令、客戶端問題介紹

1.10 gary 容量 普通用戶 group soc export sys show

exportfs命令
exportfs命令常用選項為-a、-r、-u和-v,各選項含義如下:
  • -a:表示全部掛載或者全部卸載
  • -r:表示重新掛載
  • -u:表示卸載某一個目錄
  • -v:表示顯示共享目錄
1.修改配置文件

服務端配置:

[root@gary-tao ~]# vim /etc/exports

增加一行配置如下:

/tmp/ 172.16.111.0/24(rw,sync,no_root_squash)

[root@gary-tao ~]# exportfs -arv  //不用重啟nfs服務,配置文件就會生效
exporting 172.16.111.0/24:/tmp
exporting 172.16.111.0/24:/home/nfstestdir

客戶端測試:

[root@gary ~]# !showm
showmount -e 172.16.111.100
Export list for 172.16.111.100:
/tmp             172.16.111.0/24
/home/nfstestdir 172.16.111.0/24
試例說明:
//客戶端操作

[root@gary ~]# mount -t nfs 172.16.111.100:/tmp/ /mnt/
[root@gary ~]# df -h
文件系統             容量  已用  可用 已用% 掛載點
/dev/sda3             18G  1.1G   17G    7% /
devtmpfs             479M     0  479M    0% /dev
tmpfs                489M     0  489M    0% /dev/shm
tmpfs                489M   19M  470M    4% /run
tmpfs                489M     0  489M    0% /sys/fs/cgroup
/dev/sda1            197M  109M   88M   56% /boot
tmpfs                 98M     0   98M    0% /run/user/0
172.16.111.100:/tmp   18G  6.9G   11G   39% /mnt
[root@gary ~]# ls /mnt/
aming.sock     php-fcgi.sock                                                             test.com.log-20180108
mysql_all.sql  systemd-private-55f859a1063045b7a4c022e444d06732-vmtoolsd.service-FjZRDv  test.com.log-20180109
mysql.sock     test.com.log-20180106                                                     user.sql
mysql.sql      test.com.log-20180107
[root@gary ~]# vi /mnt/123.txt
[root@gary ~]# ls -l /mnt/123.txt 
-rw-r--r--. 1 root root 19 1月  16 15:00 /mnt/123.txt
[root@gary ~]# ls -l /mnt/    //客戶端查看
總用量 1324
-rw-r--r--. 1 root   root        19 1月  16 15:00 123.txt
srw-rw-rw-. 1 root   root         0 1月  12 09:55 aming.sock
-rw-r--r--. 1 root   root   1304811 1月  15 19:27 mysql_all.sql
srwxrwxrwx. 1 xietao xietao       0 1月  12 15:02 mysql.sock
-rw-r--r--. 1 root   root     30806 1月  15 19:31 mysql.sql
srw-rw-rw-. 1 root   root         0 1月  12 09:55 php-fcgi.sock
drwx------. 3 root   root        17 1月  12 09:55 systemd-private-55f859a1063045b7a4c022e444d06732-vmtoolsd.service-FjZRDv
-rw-r--r--. 1 root   root         0 1月   6 00:00 test.com.log-20180106
-rw-r--r--. 1 root   root         0 1月   7 00:00 test.com.log-20180107
-rw-r--r--. 1 root   root         0 1月   8 00:00 test.com.log-20180108
-rw-r--r--. 1 root   root      1158 1月   9 21:10 test.com.log-20180109
-rw-r--r--. 1 root   root      6528 1月  15 19:23 user.sql

//服務端查看
[root@gary-tao ~]# ls -l /tmp/    
總用量 1324
-rw-r--r-- 1 root  root       19 1月  16 15:00 123.txt
srw-rw-rw- 1 root  root        0 1月  12 09:55 aming.sock
-rw-r--r-- 1 root  root  1304811 1月  15 19:27 mysql_all.sql
srwxrwxrwx 1 mysql mysql       0 1月  12 15:02 mysql.sock
-rw-r--r-- 1 root  root    30806 1月  15 19:31 mysql.sql
srw-rw-rw- 1 root  root        0 1月  12 09:55 php-fcgi.sock
drwx------ 3 root  root       17 1月  12 09:55 systemd-private-55f859a1063045b7a4c022e444d06732-vmtoolsd.service-FjZRDv
-rw-r--r-- 1 root  root        0 1月   6 00:00 test.com.log-20180106
-rw-r--r-- 1 root  root        0 1月   7 00:00 test.com.log-20180107
-rw-r--r-- 1 root  root        0 1月   8 00:00 test.com.log-20180108
-rw-r--r-- 1 root  root     1158 1月   9 21:10 test.com.log-20180109
-rw-r--r-- 1 root  root     6528 1月  15 19:23 user.sql
總結說明:這裏在客戶端建立的文件在客戶端與服務端上查看都是root,這是因為我們在配置文件裏配置了no_root_squash,不限制root。所以當我們在掛載點上使用就文件時它就不限制root用戶,也就是說使用root用戶創建文件時,跟在服務端本機上創建的一樣。

NFS客戶端問題

  • NFS 4版本會有該問題
  • 客戶端掛載共享目錄後,不管是root用戶還是普通用戶,創建新文件時屬主、屬組為nobody,客戶端掛載時加上 -o nfsvers=3

執行命令:

[root@gary-tao ~]# mount -t nfs -oremount,nfsvers=3 192.168.118.133:/tmp/ /mnt/
  • 客戶端和服務端都需要
    vim /etc/idmapd.conf //把“#Domain = local.domain.edu” 改為 “Domain = xxx.com” (這裏的xxx.com,隨意定義吧),然後再重啟rpcidmapd服務

NFS的exportfs命令、客戶端問題介紹