必備條件:服務器和客戶端都要安裝nfs-utils、rpcbind。
1. 查看是否安裝nfs-utils、rpcbind
rpm -q rpcbind nfs-utils
2. 安裝nfs-utils、rpcbind
yum install -y rpcbind nfs-utils
3. 設置共享目錄
vim /etc/exports
**配置參數介紹 **
客戶機地址可以是主機名、ip地址、網段地址、允許使用"*"、"?"通配符
“rw”表示允許讀寫,"ro"表示爲只讀;
"sync"表示同步寫入到內存與硬盤中
"no_root\_squash"表示當客戶機以root身份訪問時賦予本地root權限,默認是"root_squash"
"root_squash"表示客戶機用root用戶訪問更改共享目錄時,將root用戶映射成匿名用戶。
4. 啓動NFS服務程序
systemctl start rpcbind.service #開啓rpcbind
systemctl start nfs #開啓nfs
systemctl enable rpcbind.service #將rpcbind設爲自啓動
systemctl enable nfs #將nfs設爲自啓動
5.客戶端配置
5.1 檢查或操作上述1、2、4步驟
5.2 查看服務器共享目錄
showmount -e [ip地址]
5.3 掛載目錄
mount -t nfs 192.168.0.168:/home/file/ /home/file
5.4 設置自動掛載
vim /etc/rc.local #將5.3所述命令保存至此文件