
我已將 NFS 共用從 Windows 2012 伺服器安裝到我擁有的 Centos7 Web 伺服器。
我希望我的網頁伺服器從 NFS 共用建立和讀取檔案。我之前在 Windows 2008 和 Centos6 上有過類似的解決方案,但在升級伺服器後我遇到了困難。
UID 和 GID 在 W2012 NFS 選項中設定並且是正確的。
[root@centos external]# ll
drwxrwxrwx 2 apache www-data 4096 Sep 17 16:15 NFSShare
[root@centos external]# df -h
windowsserver:/NFSShare 50G 19G 31G 38% /var/www/external/NFSShare
[root@centos external]# getfacl NFSShare/
# file: NFSShare/
# owner: apache
# group: www-data
user::rwx
group::rwx
other::rwx
NFS 共用及其權限與 root 使用者一起使用。
[root@centos NFSShare]# touch test.txt
[root@centos NFSShare]# ll
total 1
-rwxrwxrwx 1 apache www-data 8 Sep 17 16:15 test2.txt
-rw-r--r-- 1 apache www-data 0 Sep 24 11:10 test.txt
但是當我嘗試使用 PHP 從我的網站讀取或寫入時,我得到權限拒絕。
PHP程式碼(嘗試建立資料夾並讀取檔案):
// Try create a folder
mkdir('/var/www/external/NFSShare/123');
// Try to read from file
$file = '/var/www/external/NFSShare/test2.txt';
$homepage = file_get_contents($file);
echo $homepage;
PHP錯誤日誌:
[root@centos external]# tail /var/log/httpd/website-error_log
[Thu Sep 24 10:21:03.632156 2015] [:error] [pid 15286] [client 172.27.xxx.xxx:56198] PHP Warning: mkdir(): Permission denied in /var/www/website/modules/users/view/admin/test.php on line 6
[Thu Sep 24 10:21:03.645438 2015] [:error] [pid 15286] [client 172.27.xxx.xxx:56198] PHP Warning: file_get_contents(/var/www/external/NFSShare/test2.txt): failed to open stream: Permission denied in /var/www/website/modules/users/view/admin/test.php on line 15
如果我嘗試從 ssh 以 apache 使用者身分執行,也會出現相同的問題:
[root@centos NFSShare]# su -s /bin/sh apache -c "touch /var/www/external/NFSShare/test.txt"
touch: cannot touch ‘/var/www/external/NFSShare/test.txt’: Permission denied
目前,我嘗試在 Windows 端授予「所有人」NTFS 權限,在 Centos 伺服器上盡可能授予 CHMOD 0777 權限,並關閉 SELinux - 只是為了排除與此相關的任何問題。
有人知道為什麼 Apache 使用者無法讀取或寫入 NFS 共用嗎?
更新#1:
使用 apache 使用者建立檔案時檢查「tail -f /var/log/audit/audit.log」。當我在 ex 中建立文件時,在日誌中看不到任何差異。 /external 或 /external/NFSShare 中,我的 NFSShare 權限被拒絕。
檢查了“tcpdump -i any dst windowsserver”,在使用 root 使用者建立檔案時收到 NFS 請求,但在使用 apache 使用者嘗試時卻沒有收到任何請求。所以看起來我的 Centos 伺服器在將任何內容傳送到 windows 伺服器之前拒絕了請求。