阿里雲 centos 服務器無法自動掛載 nas 的問題


阿里雲服務器 centos 7.3 ,開始是通過 fstab 配置的自動掛載:

xxx.cn-hangzhou.nas.aliyuncs.com:/  /nas  nfs4  auto  0  0

但服務器啟動后不能自動掛載 nas ,用 mount 命令可以手動掛載:

mount -t nfs4 xxx.cn-hangzhou.nas.aliyuncs.com:/  /nas

在 /var/log/boot.log 中發現了對應的錯誤日志:

[FAILED] Failed to mount /nas.
See 'systemctl status nas.mount' for details.

systemctl status nas.mount 命令查看錯誤詳情:

ount.nfs4: Failed to resolve server xxx.cn-hangzhou.nas.aliyuncs.com: Name or service not known

原來是在啟動過程中解析 nas 的主機名失敗。

於是改用 systemd 掛載 nas ,systemd unit 配置(/etc/systemd/system/nas.mount)是這么寫的:

Description=mount aliyun nas
Requires=network.target

[Mount]
What=xxx.cn-hangzhou.nas.aliyuncs.com:/
Where=/nas
Type=nfs4

[Install]
WantedBy=multi-user.target

啟用 systemd 配置后,重啟服務器依然無法自動掛載。

systemctl enable nas.mount

將 Requires=network.target 改為 Requires=network-online.target ,問題依舊。

后來查看 systemd 的 multi-user.target.wants 發現了幾個 cloud 開頭的 service

# ls /etc/systemd/system/multi-user.target.wants/ | grep cloud
cloud-config.service
cloud-final.service
cloud-init-local.service
cloud-init.service
cloud-init-upgrade.service

估計是阿里雲添加的一些 service ,試了試在 Requires 中 添加 cloud-final.target ,結果問題解決了!

[Unit]
Description=mount aliyun nas
Requires=cloud-final.target

[Mount]
What=xxx.cn-hangzhou.nas.aliyuncs.com:/
Where=/nas
Type=nfs4

[Install]
WantedBy=multi-user.target

估計是 dns 解析依賴阿里雲的某些 service 。 

 

* 參考資料:systemd 編寫服務管理腳本


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM