- web server  log analysis viewer


GoAccess (오픈소스)
https://goaccess.io
https://github.com/allinurl/goaccess

    - 14.5k , v1.5.5 , 2022-02

 

    - 설치

$ sudo apt install goaccess

 

//-------------------------------------
매뉴얼
CUSTOM LOG/DATE FORMAT
https://goaccess.io/man#custom-log
FILE OPTIONS
-  :  로그 파일을 stdin에서 읽기
    - 사용예): # tail -f access.log | goaccess -

 


//-----------------------------------------------------------------------------

* 설정

    - goaccess.conf 파일 수정

 # nginx 로그 포맷

log-format COMBINED

 

 # 로그 포맷 검사 안함
num-tests 0

    - AWS EC2에서 에러 발생 해결
    에러 메시지 : Token '-' doesn't match specifier '%h'
    에러 원인 : 로그에 다음라인이 있어서  
    - - - [26/Mar/2022:14:37:12 +0900] "GET / HTTP/1.1" 404 134 "-" "ELB-HealthChecker/2.0"

 


//-----------------------------------------------------------------------------
< 실행 - 사용예제 >
https://goaccess.io/man#examples

 

$ goaccess /var/log/nginx/access.log --log-format=COMBINED --num-tests=0

    - goaccess.conf에 옵션 설정하면 명령행에서 옵션 필요없음
    - 로그 포맷 지정 : --log-format=COMBINED 
    - 에러 검사 하지 않기 옵션 : --num-tests=0

//-------------------------------------
    - 최근 상태 모니터링
$ tail -f access.log | goaccess -


    - 특정 정보(IP, 브라우저등) 포함한 정보만 모니터링
$ tail -f access.log | grep -i --line-buffered 'firefox' |   goaccess - 


    - 실시간 html 파일로 저장 , 웹서버를 통해 원격으로 실시간 모니터링 가능
# tail -f access.log |  goaccess -o /var/www/html/report.html --real-time-html  -


//-------------------------------------
    - 파일로 내보내기
$ goaccess /var/log/nginx/access.log --log-format=COMBINED --num-tests=0  -o ~/log-1.html -o ~/log-1.json
~/log-1.csv 

 


//-------------------------------------
< 웹소켓을 통한 확인 >

    - WebSocket server 구동
$ tail -f access.log |   goaccess -o ~/report.html --real-time-html  -


    - 웹소켓 클라이언트로 접속

        - 크롬 확장 설치
https://chrome.google.com/webstore/detail/simple-websocket-client/pfdhoblngboilpfeibdedpjgfnlcodoo/related?hl=en

접속 주소  -  ws://서버주소:7890

    - 기본 포트가 7890, --port 명령으로 변경가능
    - 분석 데이터가 JSON 형식으로 수신됨

 

 

//-----------------------------------------------------------------------------
< 최신 버전 설치 방법 >
2022-03 현재 apt 패키지는 v1.3, 현재 최신버전은 v1.5

//-------------------------------------
* libmaxminddb 설치
    - Missing development files for libmaxminddb library. 에러 발생시
$ sudo add-apt-repository ppa:maxmind/ppa
$ sudo apt update
$ sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin

//-------------------------------------
* goaccess 설치
$ wget https://tar.goaccess.io/goaccess-1.5.5.tar.gz
$ tar -xzvf goaccess-1.5.5.tar.gz
$ cd goaccess-1.5.5/
$ ./configure --enable-utf8
$ make
$ sudo make install

    - 다음 에러 발생시 대처 : -bash: /usr/bin/goaccess: No such file or directory
        - $PATH에 경로 설정이 되어있는데도 실행파일을 인식하지 못하는 경우
        - command hash table 리빌드
$ hash -r
$ goaccess --verison


//-----------------------------------------------------------------------------
nginx 로그 - 수상한 접속 검색

$ cat access.log | grep -i "검색어"

    - 검색어
404 622
python-requests

 

 

반응형
Posted by codens