學校 Server 之間的備份都是利用 NFS 搭配 autofs 服務,再使用 cron 及備份的 Script 來做備份,重新安裝 Server後,發現 autofs 無法自動掛載 NFS 目錄,所以備份無法成功。
後來發現應該也是 SELinux 所造成的問題
# ls -lZ /etc/auto.*
-rw-r–r–. root root unconfined_u:object_r:admin_home_t:s0 /etc/auto.bs
-rw-r–r–. root root system_u:object_r:etc_t:s0 /etc/auto.master
-rw-r–r–. root root system_u:object_r:etc_t:s0 /etc/auto.misc
-rwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc/auto.net*
-rwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc/auto.smb*
auto.bs 是我從備份的設定檔複製過去的,所以權限不同[@more@]解決方式:
1. 關閉 SELinux,感覺 SELinux 有點像是 Windows 上的 使用者帳戶控制(UAC),強調會比較安全,但卻造成使用者操作上的不便。不過在這裡並不關閉 SELinux,而是改用第二種方法。
2. 更改權限
# chcon -u system_u -t etc_t /etc/auto.bs
再檢查一下權限
# ls -lZ /etc/auto.*
-rw-r–r–. root root system_u:object_r:etc_t:s0 /etc/auto.bs
-rw-r–r–. root root system_u:object_r:etc_t:s0 /etc/auto.master
-rw-r–r–. root root system_u:object_r:etc_t:s0 /etc/auto.misc
-rwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc/auto.net*
-rwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc/auto.smb*
重新啟動 autofs 服務
# /etc/init.d/autofs restart
正在停止 automount: [ 確定 ]
正在啟動 automount: [ 確定 ]
這時候就正常了!
後記:
關於 SELinux 所造成的困擾,最簡單的解決方式,就是不要直接從別的目錄複製舊的設定檔來想要直接覆蓋,而是先編輯新的設定檔,再把舊資料讀入,就會沒有問題了!
以 Apache Web Server 為例
# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.$(date +%F)
# vim /etc/httpd/conf/httpd.conf
:r /root/bak/httpd.conf
# chcon -u system_u -t httpd_config_t /etc/httpd/httpd.conf*