GoAccess日志分析工具的配置

GoAccess是一款在web页面展示的日志分析工具,页面十分酷炫
我的配置环境是:OS:CentOS 7 web server:Nginx
配置步骤:
1、关闭防火墙和selinux

[root@www ~]# iptables  -X
[root@www ~]# iptables  -F
[root@www ~]# iptables  -Z
[root@www ~]# systemctl disable firewalld 
[root@www ~]# 
[root@www ~]# setenforce 0  
setenforce: SELinux is disabled
[root@www ~]# 

2、配置阿里源的yum仓库

[root@www yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-03-29 13:17:59--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 116.211.153.233, 116.211.153.231, 116.211.153.232, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|116.211.153.233|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[============================================================================>] 2,523       --.-K/s   in 0s      

2019-03-29 13:17:59 (130 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
[root@www yum.repos.d]# vim CentOS-Base.repo 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/


[root@www yum.repos.d]# yum repolist all 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
jyy                                                                                            | 3.6 kB  00:00:00     
(1/2): jyy/primary_db                                                                          | 2.8 MB  00:00:00     
(2/2): jyy/group_gz                                                                            | 155 kB  00:00:00     
repo id                                repo name                                                       status
base/x86_64                            CentOS-7 - Base - mirrors.aliyun.com                            enabled: 10,019
jyy                                    jyy                                                             enabled:  3,723
repolist: 13,742
[root@www yum.repos.d]# 

3、安装编译GoAccess时所需要的软件包

[root@www goaccess-0.9.8]# yum install gcc gcc-c++ -y 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-36.el7 will be installed
--> Processing Dependency: cpp = 4.8.5-36.el7 for package: gcc-4.8.5-36.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-36.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-36.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-36.el7.x86_64
---> Package gcc-c++.x86_64 0:4.8.5-36.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-36.el7 for package: gcc-c++-4.8.5-36.el7.x86_64
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-36.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-260.el7 will be installed
--> Processing Dependency: glibc-headers = 2.17-260.el7 for package: glibc-devel-2.17-260.el7.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-260.el7.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package libstdc++-devel.x86_64 0:4.8.5-36.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.17-260.el7 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-260.el7.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-260.el7.x86_64
--> Running transaction check
---> Package kernel-headers.x86_64 0:3.10.0-957.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                          Arch                    Version                         Repository             Size
======================================================================================================================
Installing:
 gcc                              x86_64                  4.8.5-36.el7                    base                   16 M
 gcc-c++                          x86_64                  4.8.5-36.el7                    base                  7.2 M
Installing for dependencies:
 cpp                              x86_64                  4.8.5-36.el7                    base                  5.9 M
 glibc-devel                      x86_64                  2.17-260.el7                    base                  1.1 M
 glibc-headers                    x86_64                  2.17-260.el7                    base                  683 k
 kernel-headers                   x86_64                  3.10.0-957.el7                  base                  8.0 M
 libmpc                           x86_64                  1.0.1-3.el7                     base                   51 k
 libstdc++-devel                  x86_64                  4.8.5-36.el7                    base                  1.5 M
 mpfr                             x86_64                  3.1.1-4.el7                     base                  203 k

Transaction Summary
======================================================================================================================
Install  2 Packages (+7 Dependent packages)

Total download size: 41 M
Installed size: 84 M
Downloading packages:
(1/9): cpp-4.8.5-36.el7.x86_64.rpm                                                             | 5.9 MB  00:00:01     
(2/9): gcc-4.8.5-36.el7.x86_64.rpm                                                             |  16 MB  00:00:03     
(3/9): glibc-devel-2.17-260.el7.x86_64.rpm                                                     | 1.1 MB  00:00:00     
(4/9): glibc-headers-2.17-260.el7.x86_64.rpm                                                   | 683 kB  00:00:00     
(5/9): gcc-c++-4.8.5-36.el7.x86_64.rpm                                                         | 7.2 MB  00:00:01     
(6/9): libmpc-1.0.1-3.el7.x86_64.rpm                                                           |  51 kB  00:00:00     
(7/9): libstdc++-devel-4.8.5-36.el7.x86_64.rpm                                                 | 1.5 MB  00:00:00     
(8/9): mpfr-3.1.1-4.el7.x86_64.rpm                                                             | 203 kB  00:00:00     
(9/9): kernel-headers-3.10.0-957.el7.x86_64.rpm                                                | 8.0 MB  00:00:01     
----------------------------------------------------------------------------------------------------------------------
Total                                                                                 8.9 MB/s |  41 MB  00:00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mpfr-3.1.1-4.el7.x86_64                                                                            1/9 
  Installing : libmpc-1.0.1-3.el7.x86_64                                                                          2/9 
  Installing : cpp-4.8.5-36.el7.x86_64                                                                            3/9 
  Installing : libstdc++-devel-4.8.5-36.el7.x86_64                                                                4/9 
  Installing : kernel-headers-3.10.0-957.el7.x86_64                                                               5/9 
  Installing : glibc-headers-2.17-260.el7.x86_64                                                                  6/9 
  Installing : glibc-devel-2.17-260.el7.x86_64                                                                    7/9 
  Installing : gcc-4.8.5-36.el7.x86_64                                                                            8/9 
  Installing : gcc-c++-4.8.5-36.el7.x86_64                                                                        9/9 
  Verifying  : glibc-devel-2.17-260.el7.x86_64                                                                    1/9 
  Verifying  : cpp-4.8.5-36.el7.x86_64                                                                            2/9 
  Verifying  : gcc-4.8.5-36.el7.x86_64                                                                            3/9 
  Verifying  : mpfr-3.1.1-4.el7.x86_64                                                                            4/9 
  Verifying  : kernel-headers-3.10.0-957.el7.x86_64                                                               5/9 
  Verifying  : libmpc-1.0.1-3.el7.x86_64                                                                          6/9 
  Verifying  : gcc-c++-4.8.5-36.el7.x86_64                                                                        7/9 
  Verifying  : glibc-headers-2.17-260.el7.x86_64                                                                  8/9 
  Verifying  : libstdc++-devel-4.8.5-36.el7.x86_64                                                                9/9 

Installed:
  gcc.x86_64 0:4.8.5-36.el7                               gcc-c++.x86_64 0:4.8.5-36.el7                              

Dependency Installed:
  cpp.x86_64 0:4.8.5-36.el7                glibc-devel.x86_64 0:2.17-260.el7   glibc-headers.x86_64 0:2.17-260.el7    
  kernel-headers.x86_64 0:3.10.0-957.el7   libmpc.x86_64 0:1.0.1-3.el7         libstdc++-devel.x86_64 0:4.8.5-36.el7  
  mpfr.x86_64 0:3.1.1-4.el7               

Complete!



[root@www yum.repos.d]# yum install GeoIP GeoIP-devel GeoIP-data - y 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package GeoIP-1.5.0-13.el7.x86_64 already installed and latest version
No package y available.
Resolving Dependencies
--> Running transaction check
---> Package GeoIP-data.noarch 0:1.5.0-13.el7 will be installed
---> Package GeoIP-devel.x86_64 0:1.5.0-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                       Arch                     Version                          Repository              Size
======================================================================================================================
Installing:
 GeoIP-data                    noarch                   1.5.0-13.el7                     base                    25 M
 GeoIP-devel                   x86_64                   1.5.0-13.el7                     base                    14 k

Transaction Summary
======================================================================================================================
Install  2 Packages

Total download size: 25 M
Installed size: 50 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): GeoIP-data-1.5.0-13.el7.noarch.rpm                                                      |  25 MB  00:00:02     
(2/2): GeoIP-devel-1.5.0-13.el7.x86_64.rpm                                                     |  14 kB  00:00:02     
----------------------------------------------------------------------------------------------------------------------
Total                                                                                 7.9 MB/s |  25 MB  00:00:03     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : GeoIP-data-1.5.0-13.el7.noarch                                                                     1/2 
  Installing : GeoIP-devel-1.5.0-13.el7.x86_64                                                                    2/2 
  Verifying  : GeoIP-devel-1.5.0-13.el7.x86_64                                                                    1/2 
  Verifying  : GeoIP-data-1.5.0-13.el7.noarch                                                                     2/2 

Installed:
  GeoIP-data.noarch 0:1.5.0-13.el7                          GeoIP-devel.x86_64 0:1.5.0-13.el7                         

Complete!


[root@www yum.repos.d]# 
[root@www yum.repos.d]# yum install ncurses-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ncurses-devel.x86_64 0:5.9-14.20130511.el7_4 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================
 Package                      Arch                  Version                                 Repository           Size
======================================================================================================================
Installing:
 ncurses-devel                x86_64                5.9-14.20130511.el7_4                   base                712 k

Transaction Summary
======================================================================================================================
Install  1 Package

Total download size: 712 k
Installed size: 2.1 M
Is this ok [y/d/N]: y
Downloading packages:
ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm                                                 | 712 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ncurses-devel-5.9-14.20130511.el7_4.x86_64                                                         1/1 
  Verifying  : ncurses-devel-5.9-14.20130511.el7_4.x86_64                                                         1/1 

Installed:
  ncurses-devel.x86_64 0:5.9-14.20130511.el7_4                                                                        

Complete!
[root@www yum.repos.d]# 

4、下载GoAccess源码包编译安装

[root@www ~]# wget http://tar.goaccess.io/goaccess-0.9.8.tar.gz
--2019-03-29 13:22:20--  http://tar.goaccess.io/goaccess-0.9.8.tar.gz
Resolving tar.goaccess.io (tar.goaccess.io)... 107.170.196.4
Connecting to tar.goaccess.io (tar.goaccess.io)|107.170.196.4|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 277618 (271K) [application/x-gzip]
Saving to: ‘goaccess-0.9.8.tar.gz’

100%[============================================================================>] 277,618      144KB/s   in 1.9s   

2019-03-29 13:22:23 (144 KB/s) - ‘goaccess-0.9.8.tar.gz’ saved [277618/277618]

[root@www ~]# tar xf goaccess-0.9.8.tar.gz 
[root@www ~]# cd goaccess-0.9.8
[root@www goaccess-0.9.8]# ls
aclocal.m4  compile       config.sub    COPYING     INSTALL      Makefile.in  README
AUTHORS     config        configure     depcomp     install-sh   missing      src
ChangeLog   config.guess  configure.ac  goaccess.1  Makefile.am  NEWS         TODO
[root@www goaccess-0.9.8]# ./configure 
......................
Your build configuration:

  Prefix         : /usr/local
  Package        : goaccess
  Version        : 0.9.8
  Storage method : On-memory Hash Database (Default)
  GNU getline    : no
  Compiler flags :  -pthread
  Linker flags   : -lnsl -lncurses -lpthread  
  Bugs           : [email protected]            //看到此内容就是ok的

[root@www goaccess-0.9.8]# make && make install 
....................
 /usr/bin/mkdir -p '/usr/local/bin'
  /usr/bin/install -c goaccess '/usr/local/bin'
 /usr/bin/mkdir -p '/usr/local/etc'
 /usr/bin/install -c -m 644 config/goaccess.conf '/usr/local/etc'
 /usr/bin/mkdir -p '/usr/local/share/man/man1'
 /usr/bin/install -c -m 644 goaccess.1 '/usr/local/share/man/man1'
make[1]: Leaving directory `/root/goaccess-0.9.8'

5、配置goaccess的页面文件

[root@www logs]# goaccess access.log -o ../html/report.html --real-time-html --time-format='%H:%M:S' --date-format='%d/b%Y'  --log-format=COMBINED

//用goaccess命令,指明nginx的access.log日志输出到哪个文件页面中,我这里是输入到nginx的/html页面中的report.html这个页面文件中,后面是用来指明日志的时间格式

WebSocket server ready to accept new client connections


//修改nginx的主配置文件,添加location匹配规则
[root@www goaccess-1.2]# vim /usr/local/nginx/conf/nginx.conf

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /report.html {
                alias  /usr/local/nginx/html/report.html;    //只要是请求report.html页面都做路径别名到/usr/local/nginx/html/report,html这个页面文件中
        }


[root@www goaccess-1.2]# nginx -s reload -c /usr/local/nginx/conf/nginx.conf

6、在浏览器中输入页面查看
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Micky_Yang/article/details/88898352