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:/tmpexporting 172.16.111.0/24:/home/nfstestdir
客户端测试:
[root@gary ~]# !showmshowmount -e 172.16.111.100Export 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% /devtmpfs ???????????????489M ????0 ?489M ???0% /dev/shmtmpfs ???????????????489M ??19M ?470M ???4% /runtmpfs ???????????????489M ????0 ?489M ???0% /sys/fs/cgroup/dev/sda1 ???????????197M ?109M ??88M ??56% /boottmpfs ????????????????98M ????0 ??98M ???0% /run/user/0172.16.111.100:/tmp ??18G ?6.9G ??11G ??39% /mnt[root@gary ~]# ls /mnt/aming.sock ????php-fcgi.sock ????????????????????????????????????????????????????????????test.com.log-20180108mysql_all.sql ?systemd-private-55f859a1063045b7a4c022e444d06732-vmtoolsd.service-FjZRDv ?test.com.log-20180109mysql.sock ????test.com.log-20180106 ????????????????????????????????????????????????????user.sqlmysql.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.txtsrw-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.sqlsrwxrwxrwx. 1 xietao xietao ??????0 1月 ?12 15:02 mysql.sock-rw-r--r--. 1 root ??root ????30806 1月 ?15 19:31 mysql.sqlsrw-rw-rw-. 1 root ??root ????????0 1月 ?12 09:55 php-fcgi.sockdrwx------. 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.txtsrw-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.sqlsrwxrwxrwx 1 mysql mysql ??????0 1月 ?12 15:02 mysql.sock-rw-r--r-- 1 root ?root ???30806 1月 ?15 19:31 mysql.sqlsrw-rw-rw- 1 root ?root ???????0 1月 ?12 09:55 php-fcgi.sockdrwx------ 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命令、客户端问题介绍
原文地址:http://blog.51cto.com/taoxie/2062010