NFS配置文件参数

NFS 配置文件各参数详解

执行 man exports 命令,然后切换到文件结尾,可以快速查看如下样例格式:

nfs 共享参数 参数作用
rw* 读写权限
all_squash 无论 NFS 客户端使用什么账户访问,均映射为 NFS 服务器的匿名用户(常用)
sync* 同时将数据写入到内存与硬盘中,保证不丢失数据
async 优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据
anonuid* 配置 all_squash 使用,指定 NFS 的用户 UID,必须存在系统
anongid* 配置 all_squash 使用,指定 NFS 的用户 UID,必须存在系统

1.1 ro 权限修改及测试流程

a. 验证 ro 权限

[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(ro,sync,all_squash)

b. 重载 nfs(exportfs)

[root@nfs ~]# systemctl restart nfs-server

c. 先卸载客户端已挂载好的共享,并重新挂载

[root@web01 ~]# umount /data/
[root@web01 ~]# mount -t nfs 172.16.1.31:/data /data/

d. 测试是否能写数据

[root@web01 ~]# cd /data/
[root@web01 data]# touch file-test #不允许写入数据
touch: cannot touch 'file-test': Read-only file system

1.2 指定执行共享用户的 uid 与 gid

a. 验证 all_squash,anonuid,anongid

[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

b. 需要添加一个 uid 是 666,gid 是 666 的用户

[root@nfs ~]# groupadd -g 666 www
[root@nfs ~]# useradd -u666 -g666 www
[root@nfs ~]# id www
uid=666(www) gid=666(www) 组=666(www)

c. 必须重新授权为 www 用户,否则无法写入文件

[root@nfs ~]# chown -R www.www /data/

d. 重启服务

[root@nfs ~]# systemctl restart nfs-server>
e. 客户端重新挂载
[root@web01 /]# umount /data/
[root@web01 /]# mount -t nfs 172.16.1.31:/data /data/
[root@web01 data]# ll
total 4
-rw-r--r-- 1 666 666 4 Sep 6 03:41 test

f. 测试是否能写入数据

[root@web01 data]# touch tes1
[root@web01 data]# ll
total 4
-rw-r--r-- 1 666 666 0 Sep 7 10:38 tes1
-rw-r--r-- 1 666 666 4 Sep 6 03:41 test

g. 为了防止权限不一致导致权限不足,建议在客户端创建一模一样的用户

[root@web01 ~]# groupadd -g 666 www
[root@web01 ~]# useradd -u666 -g666 www
[root@web01 ~]# id www
uid=666(www) gid=666(www) groups=666(www)

改共享目录的用户用户组

1)nfs01服务端NFS、以及所有客户端都要创建用户:

[root@nfs01 ~]# useradd -u 1111 www
[root@nfs01 ~]# id www

uid=1111(www) gid=1111(www) 组=1111(www)

2)服务端NFS特殊配置

[root@nfs01 ~]# tail -2 /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=1111,anongid=1111)
/data1 10.0.0.0/24(ro)
[root@nfs01 ~]# chown -R www.www /data
[root@nfs01 ~]# ls -ld /data
drwxr-xr-x 2 www www 70 4月 18 10:05 /data

3)服务端NFS重启

[root@nfs01 ~]# systemctl reload nfs

4)每个客户端

mount -t nfs 172.16.1.31:/data /data
[root@web01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
172.16.1.31:/data 19G 1.8G 18G 10% /data
[root@web01 /data]# touch new_web01.txt
[root@web01 /data]# ls -l
总用量 0
-rw-r--r-- 1 www www 0 4月 16 10:24 ddddf
-rw-r--r-- 1 www www 0 4月 16 10:23 dddfff
-rw-r--r-- 1 www www 0 4月 18 11:01 new_web01.txt
-rw-r--r-- 1 www www 0 4月 17 11:59 oldboy.txt
-rw-r--r-- 1 www www 0 4月 17 12:30 oldgirl.txt

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、什么是NFS? 全称 network file system 网络文件系统 通过网络存储和组织文件的一种方法或...
    寻找着光辉阅读 343评论 0 0
  • 为什么fstab无法实现nfs挂载? 回顾:开机启动流程: 1、磁盘先启动/etc/fstab 2、防火墙在前。 ...
    Wave_e430阅读 3,130评论 0 0
  • 一、如何做事超出别人的? 1、提前准备,提前试讲(正式最近的模拟讲课),给别人感觉,不经意的。2、牛逼(提前准备 ...
    Aza_Lxxx阅读 349评论 0 0
  • 为什么fstab无法实现nfs挂载?回顾:开机启动流程:1、磁盘先启动/etc/fstab2、防火墙在前。3、网卡...
    Linux_淡忘阅读 231评论 0 1
  • 大学后,发现坐地铁的频率,远远高于坐公交车。公交车会遭遇堵车,或者急刹车这样的事件,也会因为司机大叔对站点...
    荨梦阅读 279评论 0 2