您的位置:首页 > 运维架构 > Nginx

用GoAccess来分析Nginx日志

2015-09-23 17:05 676 查看
首先,需要安装lnmp,已经安装完成,为了测试效果我把我自己的网站放进去可以测试一下。如果不知道怎么安装lnmp的可以参考 用shell脚本一键搭建lnmp环境实战 下面测试一下我搭建的效果




服务已经重启,那就测试一下我的网站能不能正常访问,因为是在本地的虚拟机上搭建的,用域名访问所以需要在hosts文件里定义一下,windows的hosts文件路径是:C:\Windows\System32\drivers\etc linux的hosts文件是/etc/hosts





到此网站已经搭建完成,那么我们就看是安装goaccess
第一步:安装基本软件glib2 glib2-devel ncurses ncurses-devel geoIP geoIP-devel在这里用yum安装的时候不容易找到这两个软件geoIP geoIP-devel,因此需要单独下载安装。
[root@Python ~]# yum -y install glib2 glib2-devel ncurses ncurses-devel
安装Geo-IP和GeoIP
[root@Python ~]# cd /usr/local/src/
[root@Python src]# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz [root@Python src]# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz[/code]两个文件的下载路径 安装GeoIP库
[root@Python src]# tar -zxf GeoIP-1.4.6.tar.gz
[root@Python src]# cd GeoIP-1.4.6
[root@Python GeoIP-1.4.6]# ./configure
[root@Python GeoIP-1.4.6]# make & make install
[root@Python GeoIP-1.4.6]# cd ..
[root@Python src]# mv GeoIP.dat.gz /usr/local/share/GeoIP/
第二步:安装GoAccess
[root@Python src]# wget http://jaist.dl.sourceforge.net/project/goaccess/0.6.1/goaccess-0.6.1.tar.gz [root@Python src]# tar -zxf goaccess-0.6.1.tar.gz
[root@Python src]# cd goaccess-0.6.1[root@Python goaccess-0.6.1]# ./configure –enable-geoip –enable-f8 [root@Python goaccess-0.6.1]# make && make install
安装完成。
第三步:设置goaccess,实时动态显示。
[root@Python ~]# /usr/local/bin/goaccess -f /home/wwwlogs/access.log




回车,可以实时看到nginx日志的实时信息。




可以看到网站的文件路径




可以看到浏览痕迹。
如果需要看某一天的日志可以使用,例如2015年十月一号

sed -n ‘/01/Dec/2015/,$ p’ access.log | goaccess -s -b
一个时间段用
sed -n ‘/1/Nov/2015/,/5/Dec/2015/ p’ access.log | goaccess -s -b
通过调用本地的GoAccess来分析服务器上的日志
ssh user@server ‘cat /var/log/nginx/access.log’ | goaccess -s -a -b
第四步:GoAccess生成文件
goaccess -f /www/wwwlogs/nginx.log  -a > report.html
上个导出后的图


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息