2018-3-26 14周1次課 NFS服務端安裝、配置
·NFS是Network File System的縮寫
·NFS最早由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,最新為4.1版本
·NFS數據傳輸基於RPC協議,RPC為Remote Procedure Call的簡寫。
·NFS應用場景是:A,B,C三臺機器上需要保證被訪問到的文件是一樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致
(A/B/C三臺主機數據一致,僅僅將A上數據拷貝到B/C上的話,B/C上數據無法實現和A的實時同步)
rpcbind服務產生的RPC協議進行通信(rpcbind服務默認監聽111端口),NFS服務會在RPC註冊一個端口,並告知RPC,PRC通過和用戶PRC數據傳輸,告訴用戶主機端口號,用戶主機通過端口號訪問
NFS服務需要借助RPC協議實現通信。
14.2 NFS服務端安裝配置
·服務端安裝nfs-utils和rpcbind
[root@localhost ~]# yum install -y nfs-utils rpcbind
(過程省略)
·客戶端安裝nfs-utils
(過程省略,其實只要安裝了nfs-utils,就會自動裝上rpcbind包)
·服務端上編輯 vim /etc/exports
寫入/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
[root@localhost ~]# vim /etc/exports
·創建/ home/nfstestdir 目錄,更改777權限
[root@localhost ~]# mkdir /home/nfstestdir [root@localhost ~]# chmod 777 /home/nfstestdir [root@localhost ~]# netstat -lntp
[root@localhost ~]# ps aux |grep rpc root 395 0.0 0.0 0 0 ? S< 22:29 0:00 [rpciod] root 1200 0.0 0.0 112676 984 pts/0 R+ 22:32 0:00 grep --color=auto rpc [root@localhost ~]# systemctl start rpcbind [root@localhost ~]# systemctl start nfs [root@localhost ~]# ps aux |grep nfs
[root@localhost ~]# ps aux |grep rpc
(啟動nfs服務的時候,會自動啟動rpc相關服務)
·設置開機啟動:
[root@localhost ~]# systemctl enable rpcbind [root@localhost ~]# systemctl enable nfs Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
14.3 NFS配置選項
·服務端上NFS配置選項:
rw //讀寫
ro //只讀
sync //同步模式,內存數據實時寫入磁盤
async //非同步模式
no_root_squash //客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大
root_squash //與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶
all_squash //客戶端上所有用戶在使用NFS共享目錄時都被限定為一個普通用戶
anonuid/anongid //和上面幾個選項搭配使用,定義被限定用戶的uid和gid
showmount -e 查看對某臺做了nfs服務的機器,有沒有權限
mount -t 指定類型
[root@localhost ~]# showmount -e 192.168.65.128 Export list for 192.168.65.128: /home/nfstestdir 192.168.65.0/24
·掛載:mount -t 類型 遠程ip:共享目錄 掛載點
[root@localhost ~]# mount -t nfs 192.168.65.128:/home/nfstestdir /mnt root@localhost ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 3.8G 15G 21% / devtmpfs 479M 0 479M 0% /dev tmpfs 489M 0 489M 0% /dev/shm tmpfs 489M 6.7M 482M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup 192.168.65.128:/home/nfstestdir 18G 3.8G 15G 21% /mnt /dev/sda1 197M 97M 100M 50% /boot tmpfs 98M 0 98M 0% /run/user/0 [root@localhost ~]# touch /mnt/20180320.txt [root@localhost ~]# ll /mnt/20180320.txt -rw-r--r-- 1 mysql mysql 0 3月 20 21:27 /mnt/20180320.txt
客戶端上創建一個新文件20180320.txt,再去服務端共享目錄查看
[root@localhost ~]# ll /home/nfstestdir/ 總用量 0 -rw-r--r-- 1 mysql mysql 0 3月 20 21:27 20180320.txt [root@localhost ~]# id mysql uid=1000(mysql) gid=1000(mysql) 組=1000(mysql)
(在NFS配置選項設置了anonuid和anongid為1000,所以一旦掛載了nfs共享目錄,無論客戶端上用什麽用戶去創建文件,在服務端上都顯示為uid為1000,gid為1000,也就是mysql)
2018-3-26 14周1次課 NFS服務端安裝、配置