As a long-term website operator dealing with Anqi CMS, I know that the stable operation of the system cannot be separated from meticulous maintenance work.Log file, as a loyal recorder of the system's running status, its importance is self-evident.However, if not properly managed, they may also become potential sources of problems, such as occupying a large amount of disk space, reducing troubleshooting efficiency, and so on.start.shScript generatedcheck.logandrunning.logFiles that record the startup checks and runtime output of AnQiCMS services are crucial for understanding the health of the system. Therefore, regular management and cleaning of them are necessary to ensure the long-term and efficient operation of the system.
Understand the log file of AnQi CMS
First, let us make it clearcheck.logandrunning.logThe specific functions of these two files. According to ourstart.shunderstanding of the script,check.logMainly records the running status and check results of the guardian script.It checks every minute to see if the AnQiCMS main process exists and attempts to restart it if necessary.check.logIt contains a large amount of information about process ID checks, startup attempts, and so on. When the AnQiCMS service stops unexpectedly orstart.shWhen the script does not work as expected, this log file is the primary clue to diagnose the problem.
running.logIt is more core, it is the aggregation of the standard output (stdout) and standard error (stderr) of the AnQiCMS application.This means that all debugging information, error reports, warnings, access records, and other runtime status information generated by the AnQiCMS application will be written to this file.running.logIt is a valuable data source for understanding the internal operation of applications, analyzing user behavior, identifying functional faults and performance bottlenecks.
The importance of log management.
With the continuous growth of the Anqi CMS website content and the increase in user access volume,check.logandrunning.logThe file will expand rapidly.If not effectively managed, they may pose a series of operational challenges.The most direct impact is the consumption of disk space, especially for servers with limited storage resources, the unlimited growth of log files may lead to disk space exhaustion, which may eventually cause service interruption.
Secondly, large log files can also affect performance and maintainability.When we try to open, search, or analyze large log files, the operation speed will decrease significantly, increasing the time cost of troubleshooting.In addition, retaining a large amount of historical logs for a long time may also pose risks in terms of data privacy and compliance, as logs may contain traces of user operations or sensitive data.Therefore, implementing a sound log management strategy is the key to ensuring the health and efficiency of the AnQiCMS environment.
implementing regular log management and cleaning strategies
To effectively manage the security CMS log files, we usually adopt the log rotation (Log Rotation) mechanism. In the Linux server environment,logrotateIt is a powerful and widely used tool that can automate the archiving, compression, and deletion of log files while ensuring that the application continues to write new log files.
To configure AnQiCMSlogrotateThe steps are as follows:
Firstly, we need tologrotatecreate a new configuration file in the configuration directory, for example/etc/logrotate.d/anqicms. Make sure the path matches your AnQiCMS installation directory, usually the AnQiCMS log files are located in/www/wwwroot/anqicms/directory.
configuration fileanqicmsThe content is roughly as follows:
/www/wwwroot/anqicms/check.log /www/wwwroot/anqicms/running.log {
daily # 每天轮转一次
rotate 7 # 保留最近7天的轮转日志文件
compress # 轮转后对旧日志文件进行压缩
delaycompress # 推迟压缩,下一个周期才压缩上一个周期生成的旧日志,通常与compress一起使用
size 10M # 当日志文件达到10MB时也进行轮转,无论是否到期
missingok # 如果日志文件不存在,不报错并跳过
notifempty # 如果日志文件为空,不进行轮转
copytruncate # 最重要的选项:先复制日志文件内容,然后清空原日志文件。
# 这对于AnQiCMS这种持续写入日志的应用程序至关重要,
# 它避免了在轮转过程中需要重启应用程序来重新打开日志文件句柄。
create 0640 www www # 轮转后创建新日志文件,权限为0640,用户和组为www
}
This configuration indicateslogrotateTool: Forcheck.logandrunning.logThese two files, rotate daily, retaining the latest 7 days of log copies. The old log files will be compressed to save space, and throughcopytruncateThe option can safely clear the current log file without interrupting the application and start writing to a new file.size 10MEnsure that even if it's not time for daily rotation, if the log file grows too fast, it will trigger rotation early.
After the configuration is complete,logrotateWill be executed regularly by the system's cron job (usually once a day). No manual restart is required.logrotateService, the new configuration will take effect automatically on the next execution.
**Practice and Precautions
In addition to the above configuration, there are some practices and precautions that can help us better manage AnQiCMS logs:
Log retention policy:A 7-day log retention period is a common starting point, but you should adjust it according to your business needs and legal regulations.For example, it may be necessary to retain logs for a longer period of time to meet audit requirements, even to archive them to long-term storage solutions.
Monitoring and alerts:Regular checkslogrotateThe operation status, ensure that the log rotation is performed normally.At the same time, you can configure the server monitoring system to set threshold alarms for disk space usage rate, so that it can be discovered and handled in time when log files grow abnormally or fail to rotate.
Content review:Although log files are helpful for troubleshooting, they may also contain sensitive information.Regularly review log content to ensure no sensitive data is accidentally exposed.At the same time, set the appropriate file permissions for the log file and restrict unauthorized access.
Backup strategy:For critical logs, consider backing them up to remote storage or off-site servers. Even if the server fails, these historical data can help us with post-event analysis and recovery.
Manual cleaning:In special cases, such as clearing a large amount of old logs in one go orlogrotateIf it is not effective, you may need to perform the cleanup manually. At this point, you can usefindcommand combinationrmDelete logs before a specific date, but be cautious to avoid deleting important data.
For example, manually delete logs from 7 days ago..gzCompress log files:find /www/wwwroot/anqicms/ -name "running.log-*.gz" -mtime +7 -exec rm -f {} \;
find /www/wwwroot/anqicms/ -name "check.log-*.gz" -mtime +7 -exec rm -f {} \;
By taking these meticulous log management measures, we can ensure that the running environment of the AnQiCMS website always remains clean and efficient, providing a solid foundation for high-quality content creation and publication.
Frequently Asked Questions (FAQ)
1.logrotateWhy did the log file not rotate immediately after the configuration was completed?
logrotateThe tool is usually executed daily by the system's cron job.Therefore, after you complete the configuration, you may need to wait until the system-scheduled execution time (such as at midnight every day) to see the actual rotation of the log files.sudo logrotate -f /etc/logrotate.d/anqicmsThe command enforced a single rotation.
2.running.logWhat information is recorded in the file, and how does it help with my daily operations?
running.logRecorded all standard information and error information output by the AnQiCMS application during runtime.This includes but is not limited to: application start and shutdown information, database connection status, API request processing logs, possible error stack traces, performance bottleneck warnings, and other custom debugging outputs.running.logWe can monitor the health status of the application, detect and resolve errors in a timely manner, optimize performance, and even understand the interaction patterns between users and the system.
3.check.logCan the file be completely ignored as it looks like just some watchdog script check information?
check.logAlthough the content may seem repetitive, it recordsstart.shThe script performs health checks and restarts for the main process of AnQiCMS. When the AnQiCMS service stops unexpectedly or cannot restart automatically,check.logit is for you to troubleshootstart.shIs the script working normally, and is it the key evidence of the repeated crash of the AnQiCMS process.Therefore, it should not be completely ignored, especially when encountering unstable service issues, it provides important diagnostic information.