• NFS是Network File System的縮寫mysql
• NFS最先由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,最新爲4.1版本linux
• NFS數據傳輸基於RPC協議,RPC爲Remote Procedure Call的簡寫。sql
A,B,C三臺機器上須要保證被訪問到的文件是同樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致vim
準備兩臺機器,lem-01(192.168.88.5)做爲服務端,lem-02(192.168.88.10)做爲客戶端。架構
[root@linux-5 ~]# yum install -y nfs-utils rpcbind
[root@linux-10 ~]# yum install -y nfs-utils
其實只要安裝了nfs-utils,就會自動裝上rpcbind包。app
vim /etc/exports //加入以下內容 /home/nfstestdir 192.168.88.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
mkdir /home/nfstestdir chmod 777 /home/nfstestdir
systemctl start nfs
在啓動nfs服務的同時,系統也會自動啓動rpcbind的服務。async
[root@linux-5 ~]# systemctl enable nfs Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
• rw 讀寫測試
• ro 只讀ui
• sync 同步模式,內存數據實時寫入磁盤spa
• async 非同步模式
• no_root_squash 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大
• root_squash 與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶
• all_squash 客戶端上全部用戶在使用NFS共享目錄時都被限定爲一個普通用戶
• anonuid/anongid 和上面幾個選項搭配使用,定義被限定用戶的uid和gid
[root@linux-10 ~]# showmount -e 192.168.88.5 clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
這時服務出現了報錯,因爲NFS服務的特性,須要將客戶端與服務端的防火牆以及SElinux關閉才能夠正常使用。
[root@linux-10 ~]# showmount -e 192.168.88.5 Export list for 192.168.88.5: /home/nfstestdir 192.168.88.0/24
關閉防火牆後能夠正常查看權限,能夠看到遠程服務端192.168.88.5共享的目錄爲/home/nfstestdir,針對192.168.88.0/24IP段開放。
[root@linux-10 ~]# mount -t nfs 192.168.88.5:/home/nfstestdir /mnt
[root@linux-10 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 26G 3.5G 23G 14% / devtmpfs 903M 0 903M 0% /dev tmpfs 912M 0 912M 0% /dev/shm tmpfs 912M 8.6M 904M 1% /run tmpfs 912M 0 912M 0% /sys/fs/cgroup /dev/sda1 197M 113M 85M 58% /boot tmpfs 183M 0 183M 0% /run/user/0 192.168.88.5:/home/nfstestdir 26G 4.3G 22G 17% /mnt
從顯示結果能夠發現已經成功在客戶端掛載了nfs。
在客戶端建立一個文件,並在服務端查詢是否同步。
[root@linux-10 ~]# cd /mnt/ [root@linux-10 mnt]# touch lemtest.txt [root@linux-10 mnt]# ls -l 總用量 0 -rw-r--r--. 1 mysql mysql 0 6月 28 12:56 lemtest.txt
[root@linux-5 ~]# ls -l /home/nfstestdir/ 總用量 0 -rw-r--r--. 1 user1 user1 0 6月 28 12:56 lemtest.txt [root@linux-5 ~]#
從結果能夠看到,文件已成功同步,這裏兩者屬組和屬主不一樣的緣由是在配置服務端時限制了uid和gid的值爲1000,兩臺機器上1000所對應的用戶不一樣,所以屬組和屬主也不相同。