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

How to solve the rotate problem of squid log

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

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to solve the squid log rotate problem, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Squid keeps logging, and if cache is very busy, these log files may become very large after a period of time. Some operating systems even limit the maximum size of a file (for example, 2G). If a file is written beyond this size, an error will be reported. In order to keep the log files easy to manage and to make Squid work properly, you must rotate the logs regularly.

Squid has a built-in feature for rotating logs. You can call it through the squid-k rotate command, and then tell Squid how many old copies to keep for each log file. For example, if you set it to 7, there will be eight versions of each log file: 1 current, and 7 old.

The old log file is renamed with a digital extension. For example, when performing a rotation, Squid renames log.6 to log.7, then log.5 to log.6, and so on. The current log becomes log.0, and Squid creates a new empty file named log.

After starting squid, each time squid-k rotate is executed, Squid rotates the following files: cache.log, access.log, store.log, useragent.log (if activated), and referer.log (if activated). Squid also creates the latest version of the swap.state file. Note, however, that swap.state does not rotate in the form of digital extensions.

Squid does not rotate the log on its own, and the best way is to execute it automatically in crontab. For example:

0 * / usr/local/squid/sbin/squid-k rotate complement: 0 * * 1 / usr/local/squid/sbin/squid-f / usr/local/squid/etc/squid.conf.external-k rotate > / dev/null 2 > & 100 * * 1 / usr/local/squid/sbin/squid-f / usr/local/squid/etc/squid.conf.internal-k rotate > / dev/null 2 > & 100 * * 1 / usr/local/squid/ Sbin/squid-f / usr/local/squid/etc/squid.conf.reverse-k rotate > / dev/null 2 > & 1

If you want to write your own script to manage log files, Squid provides a useful mode by simply setting the logfile_rotate instruction to 0. This way, when you run the squid-k rotate command, Squid simply closes the current log file and opens the new one. This is useful if the operating system allows renaming of files opened by other processes. The following shell script describes an idea:

#! / bin/shset-eyesterday_secs= `perl-e'print time-43200``date-r $yesterday_secs +% Y% m% d`cd / usr/local/squid/var/logs# rename the current log file without interrupting the logging processmv access.log access.log.$yesterday_date# tell Squid to close the current logs and open new ones/usr/local/squid/sbin/squid-k rotate# give Squid some time to finish writing swap.state filessleep 60mv access.log.$yesterday_date / archive/location/ gzip-9 / Archive/location/access.log.$yesterday_date the above is the log of squid. How to solve the rotate problem? Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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