加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

从后缀启动的脚本增加日志文件的文件大小

发布时间:2020-12-15 21:39:24 所属栏目:大数据 来源:网络整理
导读:每当将消息发送到特定地址时,我都使用Postfix来运行脚本.该脚本是一个Perl脚本,它使用 Log4perl将日志写入文件.日志文件由Log4perl每天轮换. 除了一个小角落外,它运作良好.当日志的文件大小超过50MB时,脚本无法写入日志文件. 在对Postfix进行一些研究之后,看
每当将消息发送到特定地址时,我都使用Postfix来运行脚本.该脚本是一个Perl脚本,它使用 Log4perl将日志写入文件.日志文件由Log4perl每天轮换.

除了一个小角落外,它运作良好.当日志的文件大小超过50MB时,脚本无法写入日志文件.

在对Postfix进行一些研究之后,看起来这可能是Postfix的限制集.以下是postconf输出中可能相关的部分内容.

$postconf | grep size
berkeley_db_create_buffer_size = 16777216
berkeley_db_read_buffer_size = 131072
body_checks_size_limit = 51200
bounce_size_limit = 50000
header_size_limit = 102400
mailbox_size_limit = 51200000
message_size_limit = 10240000
tcp_windowsize = 0

$postconf | grep virtual_mailbox_limit
virtual_mailbox_limit = 51200000

是否有任何选项可以更改以删除从脚本创建的日志文件的文件大小的50MB限制?

以下是完整性的Log4perl设置.

$cat /some/path/to/my/log4perlsettings.cfg
log4perl.logger.mylog = DEBUG,LOGGER
log4perl.appender.LOGGER = Log::Dispatch::FileRotate
log4perl.appender.LOGGER.TZ=PST
log4perl.appender.LOGGER.DatePattern=yyyy-MM-dd
log4perl.appender.LOGGER.filename = /some/path/to/my/logs/logfile.log
log4perl.appender.LOGGER.mode = append
log4perl.appender.LOGGER.max = 30
log4perl.appender.LOGGER.layout = PatternLayout
log4perl.appender.LOGGER.layout.ConversionPattern = [%d] %P %p %r %H %F %L %C - %m%n

这些可能不相关,但这里是Postfix别名设置:

$grep -r myscript /etc/postfix/
/etc/postfix/virtual:myscript@mymachine.example.net        myscript

$grep -r myscript /etc/aliases
myscript:       "|/some/path/to/my/script.pl"

编辑:

这是/ var / log / maillog的输出.这重复了很多次.

Dec 13 10:59:22 mymachine postfix/cleanup[22052]: EB5EA80196: message-id=<20141213015922.EB5EA80196@mymachine.example.net>
Dec 13 10:59:22 mymachine postfix/bounce[22431]: 7C11080190: sender non-delivery notification: EB5EA80196
Dec 13 10:59:22 mymachine postfix/qmgr[2109]: EB5EA80196: from=<>,size=3456,nrcpt=1 (queue active)
Dec 13 10:59:22 mymachine postfix/qmgr[2109]: 7C11080190: removed
Dec 13 10:59:23 mymachine postfix/smtp[22342]: EB5EA80196: to=<root@othermachine.example.net>,relay=mail.example.net[192.168.1.11]:25,delay=0.04,delays=0.01/0/0/0.03,dsn=2.0.0,status=sent (250 ok 1418435963 qp 19340)
Dec 13 10:59:23 mymachine postfix/qmgr[2109]: EB5EA80196: removed
Dec 13 10:59:39 mymachine postfix/smtpd[21267]: connect from unknown[192.168.2.12]
Dec 13 10:59:39 mymachine postfix/smtpd[21267]: CA0AB80190: client=unknown[192.168.2.12]
Dec 13 10:59:39 mymachine postfix/cleanup[21893]: CA0AB80190: message-id=<20141213015939.B625B1228002@othermachine2.example.net>
Dec 13 10:59:39 mymachine postfix/smtpd[21267]: disconnect from unknown[192.168.2.12]
Dec 13 10:59:39 mymachine postfix/qmgr[2109]: CA0AB80190: from=<root@othermachine2.net>,size=712,nrcpt=1 (queue active)
Dec 13 10:59:40 mymachine postfix/local[21269]: CA0AB80190: to=<myscript@mymachine.example.net>,relay=local,delay=0.43,delays=0.02/0/0/0.4,dsn=5.3.0,status=bounced (Command died with status 27: "/some/path/to/my/script.pl". Command output: Cannot write to '/some/path/to/my/logs/logfile.log': File too large at /usr/local/share/perl5/Log/Dispatch/File.pm line 141. )
Dec 13 10:59:40 mymachine postfix/cleanup[22052]: 3B8FD80196: message-id=<20141213015940.3B8FD80196@mymachine.example.net>
Dec 13 10:59:40 mymachine postfix/bounce[22431]: CA0AB80190: sender non-delivery notification: 3B8FD80196
Dec 13 10:59:40 mymachine postfix/qmgr[2109]: 3B8FD80196: from=<>,size=2897,nrcpt=1 (queue active)
Dec 13 10:59:40 mymachine postfix/qmgr[2109]: CA0AB80190: removed
Dec 13 10:59:40 mymachine postfix/smtp[21679]: 3B8FD80196: to=<root@othermachine2.example.net>,delays=0/0/0/0.03,status=sent (250 ok 1418435980 qp 19356)
Dec 13 10:59:40 mymachine postfix/qmgr[2109]: 3B8FD80196: removed

重要的是这一行:

Dec 13 10:59:40 mymachine postfix/local[21269]: CA0AB80190: to=<myscript@mymachine.example.net>,status=bounced (Command died with status 27: "/some/path/to/my/script.pl". Command output: Cannot write to '/some/path/to/my/logs/logfile.log': File too large at /usr/local/share/perl5/Log/Dispatch/File.pm line 141. )

当/some/path/to/my/logs/logfile.log的filesize为50MB(51200000字节)时,会发生此错误.

EDIT2:

从命令行调用时perl脚本正确运行(即不从Postfix调用).

解决方法

这确实是从后缀继承的限制.原因是,当您通过将交付指向管道来写入脚本时,那将被视为邮箱,就像您直接写入文件一样.因此,后缀传递代理上设置的任何限制都将由脚本继承.

我可以想到三种方法来解决这个问题:

>您更改后缀配置中的限制;你已经确定了限制的来源.
>您经常运行logrotate,因此文件不会超过50 MB.
>您更改脚本以使用Log::Dispatch::FileRotate中提供的logrotate函数,以便文件在超过50 MB时自动旋转.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读