背景:
子服務器想做一個備份服務器 但是之前有很多文件是上傳到本地的,于是服務要從本地讀取文件
但是在不在同一臺服務器中,讀取就會有問題,想 實現在兩者之間創建一個共享文件夾
一?NFS掛載步驟:
在主服務器(NFS服務端)上:
# 安裝NFS服務
yum install nfs-utils# 創建共享目錄
mkdir -p /home/writer/uplod/bidding# 配置共享目錄,編輯/etc/exports文件
echo "/home/writer/uplod/bidding 子服務器IP(rw,sync,no_root_squash)" >> /etc/exports# 啟動NFS服務
systemctl start nfs-server
systemctl enable nfs-server# 使配置生效
exportfs -r
在子服務器(NFS客戶端)上:
# 安裝NFS客戶端
yum install nfs-utils# 創建掛載點
mkdir -p /home/writer/uplod/bidding# 掛載共享目錄
mount 主服務器IP:/home/writer/uplod/bidding /home/writer/uplod/bidding# 設置開機自動掛載,編輯/etc/fstab
echo "主服務器IP:/home/writer/uplod/bidding /home/writer/uplod/bidding nfs defaults 0 0" >> /etc/fstab
?查看nfs服務狀態
systemctl status nfs-server
?
?但是出現超時現象 一直掛載不上去
2. 檢查 NFS 服務狀態:
?
# 在主服務器上
systemctl status rpcbind
systemctl status nfs-server# 確保這些服務都在運行
systemctl start rpcbind
systemctl start nfs-server
3. 驗證 NFS 導出配置:
?
# 查看導出列表
exportfs -v# 重新導出
exportfs -r
4.檢查端口
?
在子服務器上驗證 NFS 掛載是否成功:
1. 檢查掛載狀態:
?
df -h | grep biddingTemp
2. 嘗試在掛載目錄創建測試文件:
?
echo "test" > /home/writer/uplod/biddingTemp/test.txt
3. 檢查文件權限:
ls -l /home/writer/uplod/biddingTemp/
4. 如果能看到主服務器上的文件(如圖中的 test.txt 和 X330震五路社區蘇冰...),說明掛載成功。
如果還沒掛載,先執行掛載命令:
mount 主服務器IP:/home/writer/uplod/biddingTemp /home/writer/uplod/biddingTemp
這樣就能驗證 NFS 共享是否正常工作。