NFS 配置文件各參數(shù)詳解
執(zhí)行 man exports 命令元践,然后切換到文件結(jié)尾再芋,可以快速查看如下樣例格式:
nfs 共享參數(shù) | 參數(shù)作用 |
---|---|
rw* | 讀寫權(quán)限 |
all_squash | 無論 NFS 客戶端使用什么賬戶訪問懊缺,均映射為 NFS 服務(wù)器的匿名用戶(常用) |
sync* | 同時(shí)將數(shù)據(jù)寫入到內(nèi)存與硬盤中袱巨,保證不丟失數(shù)據(jù) |
async | 優(yōu)先將數(shù)據(jù)保存到內(nèi)存铁坎,然后再寫入硬盤;這樣效率更高箫爷,但可能會(huì)丟失數(shù)據(jù) |
anonuid* | 配置 all_squash 使用,指定 NFS 的用戶 UID,必須存在系統(tǒng) |
anongid* | 配置 all_squash 使用,指定 NFS 的用戶 UID,必須存在系統(tǒng) |
1.1 ro 權(quán)限修改及測試流程
a. 驗(yàn)證 ro 權(quán)限
[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. 測試是否能寫數(shù)據(jù)
[root@web01 ~]# cd /data/
[root@web01 data]# touch file-test #不允許寫入數(shù)據(jù)
touch: cannot touch 'file-test': Read-only file system
1.2 指定執(zhí)行共享用戶的 uid 與 gid
a. 驗(yàn)證 all_squash,anonuid,anongid
[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
b. 需要添加一個(gè) 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. 必須重新授權(quán)為 www 用戶虎锚,否則無法寫入文件
[root@nfs ~]# chown -R www.www /data/
d. 重啟服務(wù)
[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. 測試是否能寫入數(shù)據(jù)
[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. 為了防止權(quán)限不一致導(dǎo)致權(quán)限不足硫痰,建議在客戶端創(chuàng)建一模一樣的用戶
[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服務(wù)端NFS、以及所有客戶端都要?jiǎng)?chuàng)建用戶:
[root@nfs01 ~]# useradd -u 1111 www
[root@nfs01 ~]# id www
uid=1111(www) gid=1111(www) 組=1111(www)
2)服務(wù)端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)服務(wù)端NFS重啟
[root@nfs01 ~]# systemctl reload nfs
4)每個(gè)客戶端
mount -t nfs 172.16.1.31:/data /data
[root@web01 ~]# df -h
文件系統(tǒng) 容量 已用 可用 已用% 掛載點(diǎn)
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