![除非在 debian 7 中以 root 身份运行,否则无法运行 vnstat](https://linux22.com/image/45830/%E9%99%A4%E9%9D%9E%E5%9C%A8%20debian%207%20%E4%B8%AD%E4%BB%A5%20root%20%E8%BA%AB%E4%BB%BD%E8%BF%90%E8%A1%8C%EF%BC%8C%E5%90%A6%E5%88%99%E6%97%A0%E6%B3%95%E8%BF%90%E8%A1%8C%20vnstat.png)
所以,我需要运行这个命令:
vnstat -tr 2
但作为我刚刚创建的用户,不是作为 root,作为 root 它工作正常,但作为普通用户我得到这个:
Error: Unable to get interface "eth0" statistics.
Error: Interface "eth0" not available, exiting.
在 Debian 6 上没有这个限制,我该如何删除它?听起来像是权限问题。
答案1
在我的服务器上,当我使用参数时vnstat
读取:/proc/net/dev
-tr
iserv ~ # strace -e trace=file vnstat -tr 2
execve("/usr/bin/vnstat", ["vnstat", "-tr", "2"], [/* 46 vars */]) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libm.so.6", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY) = 3
open("/root/.vnstatrc", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/vnstat.conf", O_RDONLY) = 3
open("/proc/net/dev", O_RDONLY) = 3
Sampling eth0 (2 seconds average)...open("/proc/net/dev", O_RDONLY) =12 packets sampled in 2 seconds
Traffic average for eth0
rx 4 kbit/s 4 packets/s
tx 0 kbit/s 1 packets/s
我建议你检查一下你的/proc/net/dev
权限。在 Debian 6.0.7 上,它看起来像这样:
iserv ~ # ll /proc/net/dev
-r--r--r-- 1 root root 0 14. Sep 14:19 /proc/net/dev