小小百科网
标题:
Linux使用vnstat每天统计流量数据
[打印本页]
作者:
xiaoxiao
时间:
2017-7-4 01:24
标题:
Linux使用vnstat每天统计流量数据
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安装:
apt-get install vnstat
复制代码
2:你的网络接口创建一个新的数据库(这里以常用的eth0为例)
vnstat --create -i 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".
复制代码
那么我们需要先创建数据库目录
mkdir /var/lib/vnstat
复制代码
系统提示以下即可:
Creating database for interface "eth0"...
Info: -> A new database has been created.
也可以,创建网卡eth0的数据库
vnstat -u -i eth0
复制代码
更新数据库
vnstat -u
复制代码
查看数据库
vnstat -q
复制代码
3:设置开机自启动:
service vnstat start
chkconfig vnstat on
复制代码
无法使用chkconfig的用户
chmod +x /etc/rc.local
vi /etc/rc.local
复制代码
加入
service vnstat start
复制代码
如果提示无权限,则给rc.local施加权限:
chmod +x /etc/rc.local
使用:
查看所有流量统计命令:
vnstat -l
复制代码
查看eth0网卡实时流量命令:
vnstat -l -i eth0
复制代码
查看每小时流量统计命令:
vnstat -h
复制代码
查看每天的流量统计命令:
vnstat -d
复制代码
查看每月的流量统计命令:
vnstat -m
复制代码
查看更多使用帮助:
vnstat --help
复制代码
欢迎光临 小小百科网 (http://www.aixiaoxiao.cn/)
Powered by Discuz! X3.3