環(huán)境
centos7
安裝 nfs 相關(guān)軟件包:
yum install nfs-utils rpcbind -y
修改nfs配置文件,nfs的默認(rèn)配置文件是 /etc/exports
vim /etc/exports
/root/nfs *(rw,sync,no_root_squash)
說明如下:
/root/nfs 為NFS共享目錄絕對(duì)路徑
* 指定哪些用戶可以訪問:
這里 * 表明所有可以ping同該主機(jī)的用戶都可以訪問
192.168.1.* 指定網(wǎng)段,在該網(wǎng)段中的用戶可以訪問
192.168.1.100 只有該主機(jī)可以訪問
(rw,sync,no_root_squash) 參數(shù):
rw read-write 讀寫
ro read-only 只讀
sync 請(qǐng)求或?qū)懭霐?shù)據(jù)時(shí),數(shù)據(jù)同步寫入到NFS server的硬盤后才返回。數(shù)據(jù)安全,但性能降低了
async 優(yōu)先將數(shù)據(jù)保存到內(nèi)存,硬盤有空檔時(shí)再寫入硬盤,效率更高,但可能造成數(shù)據(jù)丟失。
root_squash 當(dāng)NFS 客戶端使用root 用戶訪問時(shí),映射為NFS 服務(wù)端的匿名用戶
no_root_squash 當(dāng)NFS 客戶端使用root 用戶訪問時(shí),映射為NFS 服務(wù)端的root 用戶
all_squash 不論NFS 客戶端使用任何帳戶,均映射為NFS 服務(wù)端的匿名用戶
啟動(dòng)
systemctl start rpcbind.service
systemctl start nfs-server.service
客戶端掛載
yum install nfs-utils rpcbind -y
mount ip:/root/nfs nfs/
## 無需啟動(dòng)rpcbind.service 和 nfs-server.service