xiaoxiao 发表于 2017-7-4 01:24:37

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




页: [1]
查看完整版本: Linux使用vnstat每天统计流量数据