|
1:首先安装vnstat:
CentOS使用编译安装:
- wget http://humdi.net/vnstat/vnstat-1.17.tar.gz
- tar xvzf vnstat-1.17.tar.gz
- cd vnstat-1.17/
- ./configure --prefix=/usr --sysconfdir=/etc && make && make install
复制代码
CentOS使用yum安装:
- yum install epel-release -y && yum install -y vnstat
复制代码
Debian/Ubuntu安装:
2:你的网络接口创建一个新的数据库(这里以常用的eth0为例)
- Error: Unable to open database directory "/var/lib/vnstat": No such file or directory
- The vnStat daemon should have created this directory when started.
- Check that it is is configured and running. See also "man vnstatd".
复制代码
那么我们需要先创建数据库目录
系统提示以下即可:
Creating database for interface "eth0"...
Info: -> A new database has been created.
也可以,创建网卡eth0的数据库
更新数据库
查看数据库
3:设置开机自启动:
- service vnstat start
- chkconfig vnstat on
复制代码
无法使用chkconfig的用户
- chmod +x /etc/rc.local
- vi /etc/rc.local
复制代码
加入
如果提示无权限,则给rc.local施加权限:
chmod +x /etc/rc.local
使用:
查看所有流量统计命令:
查看eth0网卡实时流量命令:
查看每小时流量统计命令:
查看每天的流量统计命令:
查看每月的流量统计命令:
查看更多使用帮助:
|
|