Installation GoAccess On Ubuntu / Debain

2019年5月20日

Installation

Installing GoAccess is pretty easy. Just download, extract and compile it with:

  1. $ wget https://tar.goaccess.io/goaccess-1.3.tar.gz
  2. $ tar -xzvf goaccess-1.3.tar.gz
  3. $ cd goaccess-1.3/
  4. $ ./configure --enable-utf8 --enable-geoip=legacy
  5. $ make
  6. # make install

Note: The only dependency is ncurses.
Info: If outputting real-time HTML, ensure port 7890 is opened. See more details.
Configure Options

Multiple options can be used to configure GoAccess. For a complete up- to-date list of configure options, run ./configure --help

  1. --enable-debug Compile with debugging symbols and turn off compiler optimizations.
  2. --enable-utf8 Compile with wide character support. Ncursesw is required.
  3. --enable-geoip=<legacy|mmdb> Compile with GeoLocation support. MaxMind's GeoIP is required. legacy will utilize the original GeoIP databases. mmdb will utilize the enhanced GeoIP2 databases.
  4. --enable-tcb=<memhash|btree> Compile with Tokyo Cabinet storage support. memhash will utilize Tokyo Cabinet's in-memory hash database. btree will utilize Tokyo Cabinet's on-disk B+ Tree database.
  5. --disable-zlib Disable zlib compression on B+ Tree database.
  6. --disable-bzip Disable bzip2 compression on B+ Tree database.
  7. --with-getline Dynamically expands line buffer in order to parse full line requests instead of using a fixed size buffer of 4096.
  8. --with-openssl Compile GoAccess with OpenSSL support for its WebSocket server. Note: Support for libssl1.1 has been added upstream.

Distributions

It is easiest to install GoAccess on Linux using the preferred package manager of your Linux distribution. Please note that not all distributions will have the lastest version of GoAccess available
Debian/Ubuntu

# apt-get install goaccess

Note: This may not always give you the latest stable version. To make sure that you're running the latest stable version of GoAccess see option below.
Official GoAccess' Debian/Ubuntu Repository

  1. $ echo "deb http://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/goaccess.list
  2. $ wget -O - https://deb.goaccess.io/gnugpg.key | sudo apt-key add -
  3. $ sudo apt-get update
  4. $ sudo apt-get install goaccess

Notes

For on-disk support (Trusty+ or Wheezy+), run: sudo apt-get install goaccess-tcb.
.deb packages in the official repo are available through https as well. You may need to install apt-transport-https.

二、校对nginx和goaccess日志格式

a、配置nginx.conf中log_format中的日志格式(改完记得重启nginx服务),如:
复制代码

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';

b、使用nginx2goaccess.sh脚本将nginx日志格式格式化为goaccess能识别的日志格式,nginx2goaccess.sh脚本内容在  https://www.cnblogs.com/erbiao/p/9221543.html

1、保存下来

2、使用如下方式获取日志格式:

sh nginx2goaccess.sh ''            #log_format为你nginx.conf中配置的日志格式

如:

sh nginx2goaccess.sh '$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'

3、会得到三个格式:

time-format %T
date-format %d/%b/%Y
log_format %h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %^ %^ %^ %T

三、生成统计页面。上面三行分别是时间、日期、日志格式,将三行输出保存到任意文件,然后就可以开始生成html可视化文件

./goaccess -f nginx_access.log -p /opt/goaccess/nginxlog.conf -o day-report.html

html可视化文件的实时更新方法(未测试)

nohup ./goaccess -f access.log -p /opt/goaccess/nginxlog.conf -o day-report.html --real-time-html --ws-url=report.xxx.com &

选项解释

  1. -f 指定nginx日志文件
  2. -p 指定日志格式文件
  3. -o 输出到指定html文件
  4. --real-time-html 实时刷新
  5. --ws-url 绑定一个域名

参考:https://www.cnblogs.com/erbiao/p/9221671.html
https://goaccess.io/download
https://goaccess.io/man

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注