如何使用外部 shell 脚本定义 apache 的 logrotation 文件名
我有 apache 在不同的服务器上运行,我想每天将日志文件同步回集中式服务器。我可以使用日志轮换创建一天的日志文件,并将其放在一个可以 rsync 到中央服务器的目录中。但是,有没有办法将日志文件名设置为可以从外部文件读取的名称?
该文档说我可以执行以下操作, CustomLog "|/usr/sbin/rotatelogs -f /var/log/httpd/log 86400" common
我有一个外部配置文件,其中有一个指定字段,我可以从命令行解析该字段以获取其值,有什么方法可以让我可以在定义文件名时添加它。我很想知道这个指定是否可以作为环境变量传递给 apache 并在 apache 的配置中使用它。这可能吗?
再次感谢大家!
I have apache running on different servers, I would like to rsync log files back to a centralised server on a daily basis. I can use log rotate to create log file for a day and put it in a directory that gets rsync'd to the central server. However is there any way to set the log filename with a designation that could be read from an external file?
The documentation says I can do the following,
CustomLog "|/usr/sbin/rotatelogs -f /var/log/httpd/log 86400" common
I have an external config file which has a designation field which I can parse from command line to get its value, is there any way I can add it when file name gets defined. I'm curious to know if this designation can be passed to apache as an environment variable and use that in apache's config. Is this possible?
Many Thanks again guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以通过配置 Apache 和 logrotate 来做到这一点。 Logrotate 由 /etc/logrotate.d/ 目录中的脚本配置。例如,我的默认 apache logrotate 配置文件是:
/etc/logrotate.d/httpd
检查 logrotate 手册页中的 postrotate 命令。在 postrotate 阶段,您可以重命名日志文件并将其放置在 rsync 可以拾取的位置。
I think you can do this by configuring Apache and logrotate. Logrotate is configured by scripts in the /etc/logrotate.d/ directory. For example, my default apache logrotate config file is:
/etc/logrotate.d/httpd
Check the logrotate man pages for the postrotate command. During the postrotate phase you could rename the log file and place it somewhere to be picked up by rsync.