每当消息发送到特定地址时,我都会使用 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
Run Code Online (Sandbox Code Playgroud)
是否有任何选项可以更改以消除从脚本创建的日志文件的文件大小 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
Run Code Online (Sandbox Code Playgroud)
这些可能不相关,但以下是 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"
Run Code Online (Sandbox Code Playgroud)
编辑:
这是 的输出/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>, relay=mail.example.net[192.168.1.11]:25, delay=0.04, delays=0/0/0/0.03, dsn=2.0.0, status=sent (250 ok 1418435980 qp 19356)
Dec 13 10:59:40 mymachine postfix/qmgr[2109]: 3B8FD80196: removed
Run Code Online (Sandbox Code Playgroud)
重要的一行可能是这一行:
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. )
Run Code Online (Sandbox Code Playgroud)
/some/path/to/my/logs/logfile.log
当的文件大小为 50MB(51200000 字节)时,此错误开始发生。
编辑2:
当从命令行调用时(即不从 Postfix 调用),perl 脚本可以正确运行。
这确实是继承自 postfix 的限制。原因是,当您通过将传输定向到管道来写入脚本时,它将被视为邮箱,就像您直接写入文件一样。因此,对后缀传送代理设置的任何限制都将由脚本继承。
我可以想到三种方法来解决这个问题: