## complie-on-debian10 ```bash sed -i "s|deb.debian.org|mirrors.huaweicloud.com|g" /etc/apt/sources.list && \ sed -i "s|security.debian.org|mirrors.huaweicloud.com|g" /etc/apt/sources.list && \ apt-get clean && \ apt-get update && \ apt-get -y upgrade && \ apt-get install \ locales \ ca-certificates \ curl \ wget \ vim \ psmisc \ procps \ autoconf \ gcc \ make \ tcl \ gettext \ difference \ iproute2 \ tree \ p7zip-full \ libssl-dev \ zlib1g-dev \ libncursesw5-dev \ libgeoip-dev \ libmaxminddb-dev \ pkg-config \ -yq mkdir -p goaccess curl -fksSL https://tar.goaccess.io/goaccess-1.4.3.tar.gz | tar -xvz --strip-components 1 -C goaccess cd goaccess CFLAGS+="-O3" ./configure \ --enable-utf8 \ --enable-geoip=mmdb \ --with-getline \ --with-openssl ## static 编译 CFLAGS+="-O3 -static" LIBS="$(pkg-config --static --libs openssl ncursesw)" ./configure \ --enable-utf8 \ --enable-geoip=mmdb \ --with-getline \ --with-openssl make make install ``` ```bash Your build configuration: Prefix : /usr/local Package : goaccess Version : 1.4.3 Compiler flags : -pthread Linker flags : -lnsl -lncursesw -lmaxminddb -lcrypto -lssl -lpthread UTF-8 support : yes Dynamic buffer : yes Geolocation : GeoIP2 Storage method : In-Memory with On-Disk Persistent Storage TLS/SSL : yes Bugs : hello@goaccess.io ``` ## complie-on-cenntos7 ```bash cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \ sed -i "s@#baseurl@baseurl@g" /etc/yum.repos.d/CentOS-Base.repo && \ sed -i "s@mirrorlist=http@#mirrorlist=http@g" /etc/yum.repos.d/CentOS-Base.repo && \ sed -i "s@baseurl=.*/centos@baseurl=https://mirrors.huaweicloud.com/centos@g" /etc/yum.repos.d/CentOS-Base.repo && \ yum clean all && \ yum makecache && \ yum update -y && \ yum install -y \ net-tools \ gcc \ gcc-c++ \ cmake \ make \ automake \ autoconf \ libtool \ readline-devel \ openssl-devel \ zlib-devel \ curl \ psmisc \ ncurses-devel \ geoip-devel \ libmaxminddb-devel mkdir -p goaccess curl -fksSL https://tar.goaccess.io/goaccess-1.4.3.tar.gz | tar -xvz --strip-components 1 -C goaccess cd goaccess CFLAGS+="-O3" ./configure \ --enable-utf8 \ --enable-geoip=mmdb \ --with-getline \ --with-openssl make make install whereis goaccess goaccess: /usr/local/bin/goaccess /usr/local/etc/goaccess ``` 安装完后/usr/local/bin/goaccess和/usr/local/etc/goaccess/goaccess.conf为主要文件 ## errors ```bash ## 错误1 checking for SSL_CTX_new in -lssl... no configure: error: ssl library missing ## 解决办法 CFLAGS+="-O3 -static" LIBS="$(pkg-config --static --libs openssl)" ``` ```bash ## 错误2 checking for mvaddwstr in -lncursesw... no configure: error: *** Missing development libraries for ncursesw ## 解决办法 CFLAGS+="-O3 -static" LIBS="$(pkg-config --static --libs openssl ncursesw)" ``` ```bash ## 错误3 gcc: error: unrecognized command line option '-V' gcc: fatal error: no input files gcc: error: unrecognized command line option '-qversion' gcc: fatal error: no input files collect2: error: ld returned 1 exit status configure:3440: error: in `/goaccess': configure:3442: error: C compiler cannot create executables /usr/bin/ld: cannot find -lssl /usr/bin/ld: cannot find -lcrypto /usr/bin/ld: cannot find -ldl /usr/bin/ld: cannot find -lncursesw /usr/bin/ld: cannot find -ltinfo /usr/bin/ld: cannot find -ldl /usr/bin/ld: cannot find -lc gcc --version gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -lssl -lcrypto -ldl -pthread -lncursesw -ltinfo -ldl -lssl -lgssapi_krb5 -lkrb5 -lcom_err -lk5crypto -lcrypto -ldl -lz -lncursesw -ltinfo ## 解决办法 yum install openssl-static ncurses-static zlib-static glibc-static libstdc++-static ``` ```bash ## 错误3 /usr/bin/ld: cannot find -lintl fatal error: CoreFoundation/CFLocale.h: No such file or directory ## 解决办法 ## 没有找到解决办法 ## https://stackoverflow.com/questions/64481053/gettext-wont-build-libintl-so ``` ## use 默认的nginx日志格式 ```bash log_format combined '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"'; ``` ```bash /usr/local/bin/goaccess --log-file /tmp/access.log --log-format COMBINED LANG='zh_CN.UTF-8' goaccess --log-file /tmp/access.log --log-format COMBINED -o /usr/share/nginx/html/site/report.html --real-time-html cat access.log | docker run -p 7890:7890 --rm -i -e LANG='zh_CN.UTF-8' allinurl/goaccess:1.4.3 --log-format COMBINED --date-format='%d/%b/%Y' --time-format='%H:%M:%S' -a -o html --real-time-html - > /usr/share/nginx/html/site/report.html ``` ## json ```bash log_format api escape=json '{' '"remote_addr":"$remote_addr",' '"X-Forwarded-For":"$http_X_Forwarded_For",' '"remote_user":"$remote_user",' '"time_local":"$time_local",' '"method":"$request_method",' '"uri":"$uri",' '"server_protocol":"$server_protocol",' '"request_body":"$request_body",' '"status":"$status",' '"body_bytes_sent":"$body_bytes_sent",' '"http_referer":"$http_referer",' '"user_agent":"$http_user_agent",' '"upstream_response_time":"$upstream_response_time"' '}'; ``` ```bash time-format %H:%M:%S # 定义时分秒格式 通过%t调用 date-format %d/%b/%Y # 定义日期格式 通过%d调用 log-format %^:"%h",%^:%^,%^:%^,%^:"%d:%t %^",%^:"%m",%^:"%U",%^:"%H",%^:%^,%^:"%s",%^:%^,%^:"%R",%^:"%u",%^:%^ ## 参考 https://www.rootop.org/pages/4742.html ``` ## ref * https://github.com/allinurl/goaccess/blob/master/Dockerfile * https://github.com/allinurl/goaccess * https://goaccess.io/man#custom-log * https://github.com/gsquire/topngx