14.1 NFS介紹
1. NFS是Network File System的縮寫
2. NFS最早由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與并主導開發,最新為4.1版本
3. NFS資料傳輸基于RPC協定,RPC為Remote Procedure Call的簡寫。
4. NFS應用場景是:A,B,C三台機器上需要保證被通路到的檔案是一樣的,A共享資料出來,B和C分别去挂載A共享的資料目錄,進而B和C通路到的資料和A上的一緻
<a href="https://s1.51cto.com/wyfs02/M02/9F/77/wKioL1mdODaCRxDKAACY6CeoO4o883.png" target="_blank"></a>
NFS原理圖:
準備兩個centos 7版本伺服器:hao1服務端 hao2用戶端
1. hao1服務端上安裝:
[root@hao-01 ~]# yum install -y nfs-utils rpcbind
2. 編輯并添加内容:
[root@hao-01 ~]# vim /etc/exports
添加内容:
[ 共享目錄 ip段.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) ]
/home/nfstestdir 192.168.211.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
3. 建立共享目錄:
[root@hao-01 ~]# mkdir /home/nfstestdir
4. 共享目錄設定777權限:
[root@hao-01 ~]# chmod 777 /home/nfstestdir
5. 啟動rpcbind服務:
[root@hao-01 ~]# systemctl start rpcbind
6. 搜尋rpcbind是否啟動?
[root@hao-01 ~]# ps aux |grep rpcbind
[root@hao-01 ~]# netstat -lnpt
[root@hao-01 ~]# systemctl start nfs
9. 搜尋nfs是否啟動?
[root@hao-01 ~]# ps aux |grep nfs
[root@hao-01 ~]# systemctl enable nfs
NFS配置選項:
rw 讀寫
ro 隻讀
sync 同步模式,記憶體資料實時寫入磁盤
async 非同步模式
no_root_squash 用戶端挂載NFS共享目錄後,root使用者不受限制,權限很大
root_squash 與上面選項相對,用戶端上的root使用者收到限制,被限定成某個普通使用者
all_squash 用戶端上所有使用者在使用NFS共享目錄時都被限定為一個普通使用者
anonuid/anongid 和上面幾個選項搭配使用,定義被限定使用者的uid和gid
1. hao2用戶端上安裝:
[root@hao-02 ~]# yum install -y nfs-utils rpcbind
2. 關閉hao1服務端防火牆:
[root@hao-01 ~]# systemctl stop firewalld
[root@hao-01 ~]# getenforce
[root@hao-01 ~]# setenforce 0
3. 關閉hao2用戶端防火牆:
[root@hao-02 ~]# systemctl stop firewalld
[root@hao-02 ~]# getenforce
[root@hao-02 ~]# setenforce 0
4. 通路hao1服務端的ip,檢視服務端共享目錄和ip段:
[root@hao-02 ~]# showmount -e 192.168.211.128
<a href="https://s1.51cto.com/wyfs02/M01/9F/77/wKioL1mdOZiz98pbAAAR6YopE_I671.png" target="_blank"></a>
5. hao2用戶端 nfs挂載:
mount -t nfs 服務端ip:共享目錄 挂載點
mount -t nfs 192.168.211.128:/home/nfstestdir /mnt
6. 檢視挂載:
[root@hao-02 ~]# df -h
<a href="https://s2.51cto.com/wyfs02/M01/00/C7/wKiom1mdOu7QJm0JAAA5XVQqx_8685.png" target="_blank"></a>
7. 挂載點mnt下,建立一個檔案:
[root@hao-02 ~]# touch /mnt/hao.txt
8. hao2用戶端檢視挂載點下hao.txt檔案 屬主 屬組:
[root@hao-02 ~]# ls -l /mnt/hao.txt
<a href="https://s5.51cto.com/wyfs02/M02/9F/77/wKioL1mdOyrgtsBPAAANX9oTqvE836.png" target="_blank"></a>
9. hao2用戶端檢視mysql的id:
[root@hao-02 ~]# id mysql
<a href="https://s2.51cto.com/wyfs02/M02/00/C7/wKiom1mdO1bAHT32AAAJvNRJYsA027.png" target="_blank"></a>
10. hao1服務端檢視共享目錄下的hao.txt檔案 屬主 屬組:
[root@hao-01 ~]# ls -l /home/nfstestdir/hao.txt
<a href="https://s2.51cto.com/wyfs02/M00/9F/77/wKioL1mdO4aiKz15AAAQYZoNjUo067.png" target="_blank"></a>
11. hao1服務端檢視mysql的id:
[root@hao-01 ~]# id mysql
<a href="https://s3.51cto.com/wyfs02/M01/00/C7/wKiom1mdO7XCWiHPAAAJdmDb018802.png" target="_blank"></a>
12. 因為/etc/exports裡設定了anonuid=1000,anongid=1000
是以屬主屬組就顯示的機器對應的1000id的使用者。
本文轉自 主内安詳 51CTO部落格,原文連結:http://blog.51cto.com/zhuneianxiang/1958676,如需轉載請自行聯系原作者