Centralized log storage for Squid Proxy or how we wrapped the logs in the database
Hi% username%,
Today I would like to tell you about the rather trivial task of collecting logs from decentralized Squid proxy servers and the pitfalls we faced.
What we have: ')
Squid-hq
Squid-br1
Squid-br2
Squid-br3
Squid-br4
Squid-db
As can be seen from the list, there are 5 squid proxy servers in different remote offices, and 1 database for collecting logs. All OS CentOS 7.3, squid proxy from 3.3.8 to 3.5.26, Squid-db - with installed mariadb 5.6
Create a database, import the schema and create a user:
mysql -p create database squid_log; CREATE USER 'squid'@'%' IDENTIFIED BY '<squid-passwd>'; GRANT ALL PRIVILEGES ON squid_log.* TO 'squid'@'<Squid-hq-ip>'; GRANT ALL PRIVILEGES ON squid_log.* TO 'squid'@'<Squid-br1-ip>'; GRANT ALL PRIVILEGES ON squid_log.* TO 'squid'@'<Squid-br2-ip>'; GRANT ALL PRIVILEGES ON squid_log.* TO 'squid'@'<Squid-br3-ip>'; GRANT ALL PRIVILEGES ON squid_log.* TO 'squid'@'<Squid-br4-ip>'; exit
cat log_mysql_daemon-table.sql log_mysql_daemon-views.sql | mysql -p squid_log
Parse: acl dontLog http_status 403 407 is an optional string, removes errors from the log going to the database associated with the eror codes 403, 407. The base will grow in geometric progression and will not carry any value for reporting
logformat squid_mysql% ts.% 03tu% 6tr%> a% Ss% 03Hs% <st% rm% ru% un% Sh% <A% mt squid-hq - set the format to the log, one of the important conditions for multiple squid servers is the last value with the name of the server from which logs come. In the original scripts, there is no functionality, so we wind up this line and the script itself as follows:
in /usr/libexec/squid/log_mysql_daemon.pl we add squid-server to the column setup
# fields that we should have in the database table # this list depends on the log format configuration my @required_fields = qw( id time_since_epoch response_time client_src_ip_addr squid_request_status http_status_code reply_size request_method request_url username squid_hier_status server_ip_addr mime_type squid_server );
access_log /var/log/squid/access.log squid - We leave local logs for debugs and cases of problems with the database, they have rotations enabled, so they won’t be superfluous
access_log daemon: /etc/squid/log_mysql_daemon.conf squid_mysql! dontLog - the actual line itself to the configuration of the daemon. Please note that ! DontLog cancels logging 403,407 only for the database, so in the case of debugging you can easily use local logs
logfile_daemon /usr/libexec/squid/log_mysql_daemon.pl - path to the pearl-barley daemon
Rereading squid proxy configs
squid reconfigure squid -k reconfigure
and we get the desired result:
Available tables and views:
Conclusion:
As you can see, the data are now centrally located in the database and easily accessible for processing. Next, we plan to write a frontend for filtering and exporting data (reporting). In general, the article was written and compiled from various sources, unfortunately I could not find everything together anywhere, so I consider it advisable to leave it here.
Would you be interested in reading the continuation of a series of articles about the Squid Proxy?