找了各种工具,最终还是觉得goaccess不仅图文并茂,而且速度快,每秒8W 的日志记录解析速度,websocket10秒刷新统计数据,站在巨人肩膀上你也会看得更远…先上图: 

具体方案如下步骤: 
一、linux上安装goaccess(版本 1.1.1,一般安装在nginx所在机器上的/opt目录) 
a.先安装依赖包

yum install ncurses-devel
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
tar -zxvf GeoIP.tar.gz
cd GeoIP-1.4.8/
./configure
make && make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

b.安装goaccess 
wget http://tar.goaccess.io/goaccess-1.1.1.tar.gz 
tar -xzvf goaccess-1.1.1.tar.gz 
cd goaccess-1.1.1/ 
./configure –enable-geoip –enable-utf8 
make 
make install

二、校对nginx的配置的日志格式(nginx.conf中log_format 使用以下自定义格式)

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '

                    '$status $body_bytes_sent "$http_referer" '

                    '"$http_user_agent" "$http_x_forwarded_for" '

                    '$connection $upstream_addr '

                    '$upstream_response_time $request_time';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

修改后重启: 
nginx -s stop 
nginx

三、生成配置文件goaccess_log_conf_nginx.conf 
vi /opt/goaccess/goaccess_log_conf_nginx.conf

time-format %T

date-format %d/%b/%Y

log_format %h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %^ %^ %^ %T
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

四、生成统计页面

手工生成当日统计页面:

goaccess -f /opt/nginx/logs/access.log -p /opt/goaccess/goaccess_log_conf_nginx.conf -o /opt/www/day-report.html
  • 1

生成实时统计页面:

nohup goaccess -f /opt/nginx/logs/access.log -p /opt/goaccess/goaccess_log_conf_nginx.conf -o /opt/www/real-time-yong-report.html --real-time-html --ws-url=report.xxx.com &
  • 1
检查是否存在进程:  ps -ef|grep goaccess
  • 1
  • 2

五、开通对外访问地址 
a.安装新的tomcat(假设在/opt/report-tomcat目录) 端口:7891 修改conf/server.xml中的端口,并增加访问目录:

<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="false"> <Context path="/" docBase="/opt/www" />
</Host> 然后增加权限与角色( conf/tomcat-users.xml) : <role rolename="report"/>
<user username="report" password="reportxxx" roles="report"/> 最后在webapps/ROOT/WEB-INFO/web.xml的web-app中增加: <security-constraint>
<web-resource-collection>
<web-resource-name>
Restricted Area
</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection> <auth-constraint>
<role-name>report</role-name>
</auth-constraint>
</security-constraint> <login-config>
<auth-method>BASIC</auth-method>
<realm-name>Authenticate yourself</realm-name>
</login-config> b.确认统计端口:7890、7891对外开放 c.访问页面是否ok
手工生成当日统计页面:http://report.xxx.com:7891/day-report.html
实时统计页面: http://report.xxx.com:7891/real-time-yong-report.html
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

附: 
参考链接: 
各种日志格式转换工具:https://github.com/stockrt/nginx2goaccess 
goaccess官网:https://goaccess.io

 以上是我直接复制的,感谢
https://blog.csdn.net/yown/article/details/56027112

最新文章

  1. Jquery获取select选中的文本与值
  2. C语言pow函数编写
  3. Effective STL(第7条)
  4. 【Windows 10 IoT - 3】Windows 10 RTM安装及新特性(树莓派 Pi2)
  5. 什么办法可以替代distinct
  6. 一、HTML和CSS基础--网页布局--网页简单布局之结构与表现原则
  7. ExpressRoute
  8. [CSS]white-space 属性详解
  9. AngularJS Directive 学习笔记
  10. 关于ocx中遇到的坑
  11. React和动态网站接口的经济学
  12. 【蓝牙数据采集模块】-01-Sensor Controller 功能介绍
  13. GWAS
  14. 搭建rtmp直播流服务之1:使用nginx搭建rtmp直播流服务器(nginx-rtmp模块的安装以及rtmp直播流配置)
  15. 201521123029《java程序设计》第2周学习总结
  16. C#语法——反射,架构师的入门基础。
  17. scrapy formRequest 表单提交
  18. C语言检测指定文件是否存在的代码
  19. 配置NTP网络时间自动校对系统时间和创建备份文件
  20. JPA + SpringData 操作数据库--Helloworld实例

热门文章

  1. ionic3使用cordova创建自定义插件
  2. CLOSE_WAIT状态的原因与解决方法
  3. 经典笔试题型----IT经理(IT Manager)
  4. JAVA性能优化:35个小细节让你提升java代码的运行效率
  5. Java锁----Lock实现原理
  6. python大法好——Python2.x与3​​.x版本区别
  7. leetcode438
  8. canvas 2.0 图片绘制
  9. Mac 笔记本 开发日记
  10. 大端&amp;小端问题