NFS的exportfs命令、客户端问题介绍

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服务

转载于:https://blog.51cto.com/taoxie/2062010

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值