
我正在調試一個問題MoinMoin
CentOS 上拋出權限錯誤,但我無法追蹤有問題的檔案/目錄在哪裡。
我strace -vp <pid>
在apache pid上運行;當我遇到問題時,我看到這個:
epoll_wait(10, {{EPOLLIN, {u32=3487534344, u64=140367313734920}}}, 2, 10000) = 1
accept4(6, {sa_family=AF_INET6, sin6_port=htons(52621), inet_pton
(AF_INET6, "::ffff:105.193.30.91", &sin6_addr), sin6_flowinfo=0,
sin6_scope_id=0}, [28], SOCK_CLOEXEC) = 11
## Later on...
read(7, 0x7fffa658ad7f, 1) = -1 EAGAIN (Resource temporarily
unavailable)
但是,由於 apache 已經在運行,因此我在名為;open()
的檔案中沒有看到對應的內容。7
因此我看到了權限問題,但我仍然不知道哪個文件是問題所在。
我知道我可以嘗試捕獲重生 apache 時打開的所有文件,但我希望有一種方法可以將文件映射7
到真實的文件名...有沒有辦法做到這一點?
編輯1:
使用@lain的指導,我跑了lsof | grep 266474069
,但結果還不清楚...
[root@lnxlmf moin]# ls -la /proc/9707/fd/7
lr-x------. 1 root root 64 Aug 28 15:39 /proc/9707/fd/7 -> pipe:[266474069]
[root@lnxlmf moin]#
[root@lnxlmf moin]# lsof | grep 266474069
httpd 9703 root 7r FIFO 0,8 0t0 266474069 pipe
httpd 9703 root 8w FIFO 0,8 0t0 266474069 pipe
httpd 9705 apache 7r FIFO 0,8 0t0 266474069 pipe
httpd 9705 apache 8w FIFO 0,8 0t0 266474069 pipe
httpd 9706 apache 7r FIFO 0,8 0t0 266474069 pipe
httpd 9706 apache 8w FIFO 0,8 0t0 266474069 pipe
httpd 9707 apache 7r FIFO 0,8 0t0 266474069 pipe
httpd 9707 apache 8w FIFO 0,8 0t0 266474069 pipe
httpd 9733 apache 7r FIFO 0,8 0t0 266474069 pipe
httpd 9733 apache 8w FIFO 0,8 0t0 266474069 pipe
[root@lnxlmf moin]#
我看到這是一個 FIFO 管道,但這對我的系統配置意味著什麼?如何追蹤EAGAIN
問題的根本原因?
編輯2:
感謝@Alan Curry,跑步strace -fp <pid_of_wsgi_proc>
似乎讓我走得更遠...
[pid 9731] stat("/opt/moin/share/moin/wikiconfig.py", {st_mode=S_IFREG|0770, st_size=6463, ...}) = 0
[pid 9731] stat("/opt/moin/share/moin/data/pages", {st_mode=S_IFDIR|0770, st_size=4096, ...}) = 0
[pid 9731] access("/opt/moin/share/moin/data/pages", R_OK|W_OK|X_OK) = -1 EACCES (Permission denied)
然而,apache 和wsgi
運行用戶apache
...
[root@lnxlmf moin]# ps auxw | grep -E "apache|wsgi"
apache 10187 0.0 0.1 373488 5884 ? Sl 17:18 0:00 moin_http_wsgi
apache 10188 0.0 0.1 373488 5884 ? Sl 17:18 0:00 moin_https_wsgi
apache 10189 0.0 0.1 185096 5824 ? S 17:18 0:00 /usr/sbin/httpd
root 10243 0.0 0.0 103240 848 pts/1 S+ 17:21 0:00 grep -E apache|wsgi
[root@lnxlmf moin]#
然而,當我運行以下命令並重新啟動 apache 時,我仍然無法解決問題...
[root@lnxlmf moin]# pwd
/opt/moin/share/moin
[root@lnxlmf moin]# chown -R apache:apache data/
[root@lnxlmf moin]# sudo chmod -R ug+rwx data/
[root@lnxlmf moin]# sudo chmod -R o-rwx data/
我在我的 wiki http 配置中使用它:
<VirtualHost *:443>
ServerName netwiki.foo.com
DocumentRoot /opt/moin/share/moin
WSGIScriptAlias / /opt/moin/share/moin/server/moin.wsgi
WSGIDaemonProcess moin_https display-name=moin_https_wsgi \
user=apache group=apache \
processes=1 threads=10 maximum-requests=1000 umask=0007
WSGIProcessGroup moin_https
WSGIApplicationGroup %{GLOBAL}
# Generate with...
# openssl req -new -x509 -days 365 -nodes -out netwiki.pem -keyout netwiki.key
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/netwiki.pem
SSLCertificateKeyFile /etc/httpd/ssl/netwiki.key
</VirtualHost>
答案1
查看/proc/<PID>/fd
其中應該列出所有已PID
開啟的文件。
在我的 CentOS 系統上 fd 7 是
lrwx------. 1 root root 64 Aug 28 22:01 7 -> socket:[1872522]
然後我可以用netstat -ane | grep 1872522
得到
tcp 0 0 :::443 :::* LISTEN 0 1872522
您可以使用
lsof | grep 266474069
取得有關管道的資訊。
答案2
看看我的小型 VPS,我可以透過以下方式確定 fd 編號:
ll /proc/17684/fd/ |colrm 1 46
0 -> /dev/null
1 -> /dev/null
10 -> /var/www/vhosts/censored.xenuser.org/statistics/logs/error_log
11 -> /var/www/vhosts/censored.de/statistics/logs/error_log
12 -> /var/www/vhosts/censored.org/statistics/logs/error_log
13 -> /var/www/vhosts/xenuser.org/statistics/logs/error_log
14 -> /var/log/apache2/access.log
[依此類推,其中17684是我之前追蹤的進程的PID]
答案3
問題是我SELINUX=enforcing
在/etc/selinux/config
.
我設定後SELINUX=permissive
,SELINUXTYPE=targeted
重新啟動wsgi
就可以正確存取所有檔案。