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

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

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

但服務器啓動後不能自動掛載 nas ,用 mount 命令能夠手動掛載:centos

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 命令查看錯誤詳情:ui

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)是這麼寫的:spa

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 ,問題依舊。code

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

# 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 ,結果問題解決了!htm

[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 編寫服務管理腳本

相關文章
相關標籤/搜索