NFS介紹,服務端安裝配置及配置選項
阿新 • • 發佈:2018-06-22
XP linux netapp ble dma call nts AS touch NFS介紹
- NFS是Network File System的縮寫
- NFS最早由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,最新為4.1版本(2010年)
- NFS數據傳輸基於RPC協議,RPC為Remote Procedure Call的簡寫,(遠程過程調用)為NFS服務提供支持。
- NFS應用場景是:A,B,C三臺機器上需要保證被訪問到的文件是一樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致。用戶在B和C上更新了文件,A上也實時更新。
-
- NFS服務不會監聽端口,通信的過程由rpc服務來監聽端口111實現通信
NFS服務端安裝配置
- NFS服務不會監聽端口,通信的過程由rpc服務來監聽端口111實現通信
- akuilinux01作為服務端,並安裝yum install -y nfs-utils rpcbind
- 在服務端上寫入以下配置
[root@akuilinux01 ~]# vim /etc/exports /home/nfstestdir #共享的目錄 192.168.21.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
- 服務端創建共享目錄
[root@akuilinux01 ~]# mkdir /home/nfstestdir [root@akuilinux01 ~]# chmod 777 /home/nfstestdi
- 服務端啟動服務並開機啟動
[root@akuilinux01 ~]# systemctl start rpcbind [root@akuilinux01 ~]# systemctl start nfs [root@akuilinux01 ~]# systemctl enable rpcbind [root@akuilinux01 ~]# systemctl enable nfs Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@akuilinux01 ~]# ps aux |grep rpc rpc 2376 0.0 0.0 64956 1404 ? Ss 08:51 0:00 /sbin/rpcbind -w rpcuser 2394 0.0 0.0 42376 1760 ? Ss 08:51 0:00 /usr/sbin/rpc.statd root 2401 0.0 0.0 0 0 ? S< 08:51 0:00 [rpciod] root 2411 0.0 0.0 42564 944 ? Ss 08:51 0:00 /usr/sbin/rpc.mountd root 2412 0.0 0.0 43816 544 ? Ss 08:51 0:00 /usr/sbin/rpc.idmapd root 2504 0.0 0.0 112676 976 pts/1 S+ 08:53 0:00 grep --color=auto rpc [root@akuilinux01 ~]# ps aux |grep nfs root 2424 0.0 0.0 0 0 ? S< 08:51 0:00 [nfsd4_callbacks] root 2430 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2431 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2432 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2433 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2434 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2435 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2436 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2437 0.0 0.0 0 0 ? S 08:51 0:00 [nfsd] root 2506 0.0 0.0 112676 980 pts/1 S+ 08:54 0:00 grep --color=auto nfs
NFS配置選項
- rw 讀寫
- ro 只讀
- sync 同步模式,內存數據實時寫入磁盤
- async 非同步模式
- no_root_squash 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大,相當於root在本地磁盤讀寫
- root_squash 與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶
- all_squash 客戶端上所有用戶在使用NFS共享目錄時都被限定為一個普通用戶
- anonuid/anongid 和上面幾個選項搭配使用,定義被限定用戶的uid和gid
- 客戶端操作
- akuilinux02作為客戶端,安裝yum install -y nfs-utils
- showmount -e 192.168.133.130 //該ip為NFS服務端ip,查看是否有權限連接服務端,如果不能連接,查看服務端NFS服務是否啟動,有沒有監聽111端口,檢查服務端和客戶端firewalld和SELinux防火墻是否關閉。
[root@akuilinux02 ~]# showmount -e 192.168.21.128 Export list for 192.168.21.128 /home/nfstestdir 192.168.21.0/24
- 掛載目錄
[root@akuilinux02 ~]# mount -t nfs 192.168.21.128:/home/nfstestdir /mnt [root@akuilinux02 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 1.1G 17G 6% / devtmpfs 907M 0 907M 0% /dev tmpfs 916M 0 916M 0% /dev/shm tmpfs 916M 8.7M 908M 1% /run tmpfs 916M 0 916M 0% /sys/fs/cgroup /dev/sda1 197M 113M 85M 58% /boot tmpfs 184M 0 184M 0% /run/user/0 192.168.21.128:/home/nfstestdir 18G 7.4G 11G 42% /mnt
- 測試
[root@akuilinux02 ~]# touch /mnt/aminglinux.txt [root@akuilinux02 ~]# ls -l /mnt/aminglinux.txt -rw-r--r-- 1 1000 1000 0 6月 22 09:06 /mnt/aminglinux.txt [root@akuilinux01 ~]# ll /home/nfstestdir/ 總用量 0 -rw-r--r-- 1 akui akui 0 6月 22 09:06 aminglinux.txt #因為限定了屬主和屬組所以顯示1000,和akui(01機器的1000為akui)
NFS介紹,服務端安裝配置及配置選項