Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deploy Goaccess server independently to analyze logs in real time

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

For a cleanliness addicted to the operation and maintenance staff, one machine with more than one application is unacceptable. Therefore, when deploying goaccess, it is bound to be independent of the application server that needs to analyze the logs. The websocket configuration of goaccess is the easiest to confuse students who have just come into contact with goaccess.

1. Understand goaccess's websocket

Goaccess's websocket needs to add the real-time-html attribute to the configuration file or the command line to create the websocket at the same time as the report is generated.

Profile excerpt:

# goaccess.conflog-file / goaccess/logs/access.logoutput / goaccess/index.htmlreal-time-html truews-url wss://www.mynginxsrv.com/wss/

Terminal executes commands:

# goaccess-p goaccess.conf # WebSocket server is ready to receive connections from customers

Well, if you visit your ws-url excitedly at this time, you will not be able to access it. This is because ws or wss is * * embedded in the html file * *. When the server data changes, * * will actively push to the browser * *. That is, we actually need to access the html file (that is, the report file) first, and after establishing a connection with websocket, the goaccess server will actively push the real-time analysis content to the browser.

In general, in order to save IP resources, it is LVS → Nginx → Backend. Then for goaccess, it is the application server of Backend, and the https connection is also handled by Nginx. So when configuring ws-url, what you need to specify is the listener host name of the Nginx. The default port for goaccess ws-url is 7890, which is also written in the report. So we have only two options, one is to expose port 7890 of LVS or Nginx, and the other is to modify the goaccess port. After modifying the port of goaccess, the port of the local websocket of the goaccess server will also be changed. This is a place that is easy to step on.

II. Nginx configuration and goaccess configuration

OK, after we have a general understanding of the mechanism of goaccess, let's talk about how to operate the configuration.

1. Configuration of nginx server

Nginx profile excerpt:

Http {server {# charset utf-8; listen 443 http2 ssl; server_name www.mynginxsrv.com; # is configured as the location where the report files are stored. You can also handle it through nfs sharing without expanding location / nginx/nginx_status.html {alias / opt/nginx/www/index_template.html here. } # the following is the websocket configuration information. Simply modify the proxy_pass corresponding information to your own goaccess server information to location / wss/ {proxy_pass http://192.168.1.2:443; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr. Proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";}}

Extend:

Considering the websocket characteristics of goaccess, we can build a false log content, and then use goaccess to generate html files, which can be directly stored in the nginx server for easy management.

# this is the fake nginx log information I built by myself Can be used to build the build template 222.222.222.222-- [01/Dec/2010:00:00:34 + 0800] "GET / HTTP/2.0" 10.0.0.1 GET 80 7164 "https://www.baidu.com/"" chrome "-" 0.338 "# corresponding to log_format:log_format% h -% ^ [% dvv% t% ^]"% r "% ^% s% b "" R "" u "" ^ "" T "

2. Complete goaccess configuration file

You need to pay attention to opening the port in the configuration file or turning off the firewall, otherwise you will find a 502 error when browsing

Time-format% Tdate-format% d/%b/%Ylog_format% h -% ^ [% dvv% t% ^] "% r"% ^% s% b "% R"% u "% ^"% ^ "% T" log-file / goaccess/logs/access.logoutput / goaccess/report/index_nginx.htmlreal-time-html truews-url wss://www.mynginxsrv.com/wss/daemonize trueport 443

Finally, show the effect picture:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report