GoAccess安装
编译安装
yum install geoip-devel openssl-devel libmaxminddb-devel ncurses-devel bzip2-devel tokyocabinet-devel
cd /usr/local/src
wget https://tar.goaccess.io/goaccess-1.3.tar.gz
tar -xzvf goaccess-1.3.tar.gz
cd goaccess-1.2/
./configure --enable-utf8 --enable-geoip=legacy --with-openssl --enable-tcb=memhash --with-getline
make
make install
注意: 仅仅需要依赖 ncurses 模块。
提示:如果需要使用实时 HTML 报告, 请确保开放 7890 端口。
验证安装是否成功:goaccess --v
# goaccess --v
GoAccess - 1.3.
For more details visit: http://goaccess.io
Copyright (C) 2009-2016 by Gerardo Orellana
Build configure arguments:
--enable-utf8
--enable-geoip=mmdb
--enable-tcb=memhash
--with-getline
--with-openssl
或者最简单的使用yum方式安装:yum install goaccess,不过不是最新版的
编译选项
GoAccess 拥有多个配置选项。获取完整的最新配置选项列表,请运行:./configure --help
--enable-debug使用调试标志编译且关闭编译器优化。
--enable-utf8宽字符支持。依赖 Ncursesw 模块。
--enable-geoip=<legacy|mmdb>地理位置支持。依赖 MaxMind GeoIP 模块。
legacy将使用原始 GeoIP 数据库。mmdb将使用增强版 GeoIP2 数据库。--enable-tcb=<memhash|btree>Tokyo Cabinet 存储支持。
memhash将使用 Tokyo Cabinet 的内存哈希数据库。btree将使用 Tokyo Cabinet 的磁盘 B+Tree 数据库。--disable-zlib禁止在 B+Tree 数据库上使用 zlib 压缩。
--disable-bzip禁止在 B+Tree 数据库上使用 bzip2 压缩。
--with-getline使用动态扩展行缓冲区用来解析完整的行请求,否则将使用固定大小(4096)的缓冲区。
--with-openssl使 GoAccess 与其 WebSocket 服务器之间的通信能够支持 OpenSSL。
安装好后配置文件路径:/usr/local/etc/goaccess.conf
相关发行版安装包
GoAccess 使用纯C编写,仅依赖 ncurses 模块。 但是如果通过源码来构建 GoAccess,不同发行版还是有一些区别,下表列出了一些发行版的可选依赖模块。
| Distro | NCurses | GeoIP (optional) | Tokyo Cabinet (optional) | OpenSSL (optional) |
|---|---|---|---|---|
| Ubuntu/Debian | libncursesw5-dev | libgeoip-dev | libtokyocabinet-dev | libssl-dev |
| Fedora/RHEL/CentOS | ncurses-devel | geoip-devel | tokyocabinet-devel | openssl-devel |
| Arch Linux | ncurses | geoip | compile from source | openssl |
| Gentoo | sys-libs/ncurses | dev-libs/geoip | dev-db/tokyocabinet | dev-libs/openssl |
| Slackware | ncurses | GeoIP | tokyocabinet | openssl |
注意: 通过源码构建 GoAccess 您可能需要一些编译/构建工具比如 gcc, make, base-devel, build-essential, "Development Tools" 等等。
GoAccess配置
在配置文件最后一行加入下面代码,配置文件路径:/usr/local/etc/goaccess.conf
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
date-format %d/%b/%Y
time-format %H:%M:%S
1、中文展示
如果你的系统默认设置时英文显示,想要以中文显示日志报表,就需要进行字符设置
临时设置为中文的命令:
# LANG="zh_CN.UTF-8"
# goaccess -p /usr/local/etc/goaccess/goaccess.conf -f /var/log/nginx/access.log -o /usr/share/nginx/html/report.html
2、配置nginx中日志log_format中的日志格式
该功能是识别nginx日志中关于时间的格式,生成goaccess可以识别的时间格式,然后把这个时间格式配置到Goaccess配置文件中。若是nginx的access日志是格式使用默认的设置,则这一步不用配置
改完记得reload配置
2.1 获取nginx.conf中log_format配置
2.2 获取nginx2goaccess脚本,可以将日志格式转换为goaccess能识别的日志格式,脚本地址:https://github.com/stockrt/nginx2goaccess/blob/master/nginx2goaccess.sh
#!/bin/bash
#
# Convert from this:
# http://nginx.org/en/docs/http/ngx_http_log_module.html
# To this:
# https://goaccess.io/man
#
# Conversion table:
# $time_local %d:%t %^
# $host %v
# $http_host %v
# $remote_addr %h
# $request_time %T
# $request_method %m
# $request_uri %U
# $server_protocol %H
# $request %r
# $status %s
# $body_bytes_sent %b
# $bytes_sent %b
# $http_referer %R
# $http_user_agent %u
#
# Samples:
#
# log_format combined '$remote_addr - $remote_user [$time_local] '
# '"$request" $status $body_bytes_sent '
# '"$http_referer" "$http_user_agent"';
# ./nginx2goaccess.sh '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'
#
# log_format compression '$remote_addr - $remote_user [$time_local] '
# '"$request" $status $bytes_sent '
# '"$http_referer" "$http_user_agent" "$gzip_ratio"';
# ./nginx2goaccess.sh '$remote_addr - $remote_user [$time_local] "$request" $status $bytes_sent "$http_referer" "$http_user_agent" "$gzip_ratio"'
#
# log_format main
# '$remote_addr\t$time_local\t$host\t$request\t$http_referer\t$http_x_mobile_group\t'
# 'Local:\t$status\t$body_bytes_sent\t$request_time\t'
# 'Proxy:\t$upstream_cache_status\t$upstream_status\t$upstream_response_length\t$upstream_response_time\t'
# 'Agent:\t$http_user_agent\t'
# 'Fwd:\t$http_x_forwarded_for';
# ./nginx2goaccess.sh '$remote_addr\t$time_local\t$host\t$request\t$http_referer\t$http_x_mobile_group\tLocal:\t$status\t$body_bytes_sent\t$request_time\tProxy:\t$upstream_cache_status\t$upstream_status\t$upstream_response_length\t$upstream_response_time\tAgent:\t$http_user_agent\tFwd:\t$http_x_forwarded_for'
#
# log_format main
# '${time_local}\t${remote_addr}\t${host}\t${request_method}\t${request_uri}\t${server_protocol}\t'
# '${http_referer}\t${http_x_mobile_group}\t'
# 'Local:\t${status}\t*${connection}\t${body_bytes_sent}\t${request_time}\t'
# 'Proxy:\t${upstream_status}\t${upstream_cache_status}\t'
# '${upstream_response_length}\t${upstream_response_time}\t${uri}${log_args}\t'
# 'Agent:\t${http_user_agent}\t'
# 'Fwd:\t${http_x_forwarded_for}';
# ./nginx2goaccess.sh '${time_local}\t${remote_addr}\t${host}\t${request_method}\t${request_uri}\t${server_protocol}\t${http_referer}\t${http_x_mobile_group}\tLocal:\t${status}\t*${connection}\t${body_bytes_sent}\t${request_time}\tProxy:\t${upstream_status}\t${upstream_cache_status}\t${upstream_response_length}\t${upstream_response_time}\t${uri}${log_args}\tAgent:\t${http_user_agent}\tFwd:\t${http_x_forwarded_for}'
#
# Author: Rogério Carvalho Schneider <stockrt@gmail.com>
# Params
log_format="$1"
# Usage
if [[ -z "$log_format" ]]; then
echo "Usage: $0 '<log_format>'"
exit 1
fi
# Variables map
conversion_table="time_local,%d:%t_%^
host,%v
http_host,%v
remote_addr,%h
request_time,%T
request_method,%m
request_uri,%U
server_protocol,%H
request,%r
status,%s
body_bytes_sent,%b
bytes_sent,%b
http_referer,%R
http_user_agent,%u"
# Conversion
for item in $conversion_table; do
nginx_var=${item%%,*}
goaccess_var=${item##*,}
goaccess_var=${goaccess_var//_/ }
log_format=${log_format//\$\{$nginx_var\}/$goaccess_var}
log_format=${log_format//\$$nginx_var/$goaccess_var}
done
log_format=$(echo "$log_format" | sed 's/${[a-z_]*}/%^/g')
log_format=$(echo "$log_format" | sed 's/$[a-z_]*/%^/g')
# Config output
echo "
- Generated goaccess config:
time-format %T
date-format %d/%b/%Y
log_format $log_format
"
# EOF
# sh nginx2goaccess.sh '$remote_addr $http_x_forwarded_for [$time_local] $host "$request_uri" $status "$http_referer" "$http_user_agent"'
- Generated goaccess config:
time-format %T
date-format %d/%b/%Y
log_format %h %^ [%d:%t %^] %v "%U" %s "%R" "%u"
2.3 将转换后的内容加入到配置/usr/local/etc/goaccess.conf
3.添加定时任务,每隔30分钟执行一次
# vim /opt/goaccess_nginx_log.sh
#!/bin/env /bash
LANG="zh_CN.UTF-8"
/usr/local/bin/goaccess -p /usr/local/etc/goaccess/goaccess.conf -f /var/log/nginx/access.log -o /usr/share/nginx/html/report.html
# chmod a+x /opt/goaccess_nginx_log.sh
# crontab -e
# 每隔1分钟生成一次html文件
*/1 * * * * /usr/bin/bash /opt/goaccess_nginx_log.sh
4.配置一个Nginx虚拟主机,将root指向/usr/share/nginx/html/,这样可以通过域名去访问html页面
1.虚拟主机,在原有的配置加一个location
location / {
root /usr/share/nginx/html/;
index report.html;
}
5.完善的地方
- nginx的access日志每天轮询,每天生成report页面
后期考虑到每天都要对nginx的access日志进行切割,可以使用脚本的形式每天根据切割后的日志文件生成响应的report页面,然后使用浏览器访问的时候根据日期进行选择
进一步完善/opt/goaccess_nginx_log.sh脚本即可,使用此脚本获取nginx日志分割的信息,定期删除日志等
- 忽略自身查看页面的访问要如何做?
- 显示来源IP所在地区?
GoAccess安装的更多相关文章
- GoAccess安装和使用介绍
使用文档参考地址:https://my.oschina.net/mrco/blog/181737https://www.fanhaobai.com/2017/06/go-access.html goa ...
- GoAccess安装及分析nginx实时日志
GoAccess是一个基于终端的快速日志分析器.其核心思想是实时快速分析和查看Web服务器统计信息,而无需使用您的浏览器(如果您希望通过SSH快速分析访问日志,或者只是喜欢在终端中工作),终端输出是默 ...
- Nginx GoAccess安装与配置
1.下载并安装Geoip $ wget https://github.com/maxmind/geoip-api-c/releases/download/v1.6.12/GeoIP-1.6.12.ta ...
- goaccess 安装
今天尝试搭建goaccess,用于分析access.log文件,但安装并不顺利,小记一下自己遇到的问题及解决方法 系统环境:CentOS release 6.9 一.参照官网教程进行搭建 $ wget ...
- goaccess安装和使用
安装依赖 $ sudo apt-get install libncursesw5-dev $ wget https://github.com/maxmind/geoip-api-c/releases/ ...
- 第一篇:实时网络日志分析器和交互式查看器--GoAccess安装
介绍 GoAccess是一个开源的实时网络日志分析器和交互式查看器,可以在* nix 系统或通过浏览器的终端中运行. 它为需要动态可视化服务器报告的系统管理员提供快速且有价值的HTTP统计信息. 特征 ...
- 安装部署 Goaccess
CentOS 7安装 Goaccess 安装依赖 # yum install ncurses-devel geoip-devel libmaxminddb-devel tokyocabinet-dev ...
- centos7 源码安装goaccess
1. 使用yum安装在不同服务器上可能失败, 推荐使用源码安装goaccess # 安装依赖 yum install -y ncurses-devel GeoIP-devel.x86_64 tokyo ...
- GoAccess日志分析工具使用文档
----Sevck 2016/3/4 17:24:13 #1软件说明: GoAccess是一款开源.实时,运行在命令行终端下的web日志分析工具.该工具提供快速.多样的HTTP状态统计,可以令管理员不 ...
随机推荐
- error while loading shared libraries: libXXXX.so: cannot open shared object file: No such file or directory
出现这个问题的原因是运行程序缺少依赖库,或者运行程序的依赖库缺少依赖库,可能你的本地目录下面就有这个库文件,但是linux搜索路劲不会从当前路径下去搜索:这种情况可能出现在切换环境上,可能你在一个li ...
- xcode6 如何编译64位iOS应用
原文:http://mobile.51cto.com/hot-412500.htm 随着iPhone5S的推出,大家开始关心5S上所使用的64位CPU A7. 除了关心A7的性能以外,大家还会关心一个 ...
- VMWare workstation12配置CentOS6.5虚拟机NAT网络以及虚拟机静态IP
1.右键网络连接—>打开网络和共享中心—>更改适配器设置—>找到网络适配器VMware Virtual Ethernet Adapter for VMnet8—>如下图所示修改 ...
- linux IP 网关配置
1. 关闭selinux 与防火墙 在虚拟机装好之后之后,先关闭selinux与防火墙 关闭selinx,重启生效 vim /etc/selinux/config 修改 SELINUX=disable ...
- dubbo的实现原理
dubbo的介绍 dubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的RPC实现服务的输出和输入功能,可以和Spring框架无缝集成. dubbo框架是基于Spring容器运 ...
- SLC-Microsoft:Microsoft Lifecycle Policy
ylbtech-SLC-Microsoft:Microsoft Lifecycle Policy Microsoft Lifecycle Policy The Microsoft Lifecycle ...
- 数据库开源框架之litepal
主页: [https://github.com/LitePalFramework/LitePal](https://github.com/LitePalFramework/LitePal) 中文文档地 ...
- Tooltip 文字提示
常用于展示鼠标 hover 时的提示信息. 基础用法 在这里我们提供 9 种不同方向的展示方式,可以通过以下完整示例来理解,选择你要的效果. 使用content属性来决定hover时的提示信息.由pl ...
- JMeter4.0以上 分布式测试报错 "server failed start Listen failed on port"
使用JMeter4.0做分布式测试的是否,我的电脑作为肉鸡(执行机),双击jmeter-server.bat后显示失败 Found ApacheJMeter_core.jarUsing local p ...
- Strange Java syntax (for me at least)--怪异的Java语法
I've more over 4 years working with Java and today I've seen some piece of code that I thought at fi ...