spamassassin

SpamAssassin が何をしてるか - LGTM
とても参考になる

SpamAssassinに同梱されているプラグインの制御ファイルは標準では/etc/mail/spamassassinにインストールされます。制御ファイルのファイル名はプラグインが導入されたバージョン毎に異なり、次のようになっています。

init.pre	3.1.0より前に導入されたプラグイン
v310.pre	3.1.0で導入されたプラグイン
v312.pre	3.1.2で導入されたプラグイン
v320.pre	3.2.0で導入されたプラグイン
v330.pre	3.3.0で導入されたプラグイン
v340.pre	3.4.0で導入されたプラグイン

SpamAssassinの基本設定 – ttkzw's site

メモリ使用量

3.0.0 から spamd が最初に child を prefork するようになったという
説明を読んで、念のために child の同時起動数をデフォルトの 5 から
3 に減らしてはあったのですが、ある時 top で確認したら 1 つの
child が 40% 以上使っていました。これを見て、そりゃぁ 3 つも
起動すればメモリーが枯渇するなぁと思いました。

で、またまた資料を漁って、今は /etc/default/spamassassin
OPTIONS に --max-children=2 と --max-conn-per-child=100 を追加し、
NICE="--nicelevel 19" としてあります。

--max-conn-per-chile のデフォルト値は 200 となっていたので
半分にして spamd child ひとつあたりのメモリー使用量を減らし、
さらに child を 2 つまでとしてトータルでの使用量も制限して
います。

http://lists.debian.or.jp/debian-users/200503/msg00189.html

prefork: server reached --max-children setting, consider raising it

Cause
The --max-children option specifies the maximum number of children to spawn. Spamd will spawn that number of children, then sleep in the background until a child dies, wherein it will go and spawn a new child.
In POA, a value of this options is set to 20, which is suitable for moderate SpamAssassin Server load.

https://cloudblue.freshdesk.com/support/solutions/articles/44001881676-spamassassin-server-log-file-contains-prefork-server-reached-max-children-setting-consider-raisi

-m number , --max-children=number
This option specifies the maximum number of children to spawn. Spamd will spawn that number of children, then sleep in the background until a child dies, wherein it will go and spawn a new child.

Incoming connections can still occur if all of the children are busy, however those connections will be queued waiting for a free child. The minimum value is 1, the default value is 5.

Please note that there is a OS specific maximum of connections that can be queued (Try perl -MSocket -e'print SOMAXCONN' to find this maximum).

Note that if you run too many servers for the amount of free RAM available, you run the danger of hurting performance by causing a high swap load as server processes are swapped in and out continually.

https://spamassassin.apache.org/full/3.4.x/doc/spamd.html

max-children デフォルト 5

負荷を下げる

Shortcircuiting Ruleset

The following is a sample ruleset which uses the SpamAssassin 3.2.0+ feature of short-circuiting, together with existing, reliable, hard-to-forge whitelist/blacklist rules, in order to reduce CPU load. It assumes you have enabled the Shortcircuit plugin in the v320.pre file.

https://wiki.apache.org/spamassassin/ShortcircuitingRuleset

vi v320.pre

loadplugin Mail::SpamAssassin::Plugin::Shortcircuit
(アンコメント)

vi local.cf

shortcircuit USER_IN_WHITELIST       on
(アンコメント)

whitelist_from  *@github.com

X-Spam-Status ヘッダ例

(変更前)

No, score=-101.9 required=5.0 tests=BAYES_00,BODY_SINGLE_WORD, RCVD_IN_DNSWL_NONE,T_RP_MATCHES_RCVD,USER_IN_WHITELIST autolearn=ham autolearn_force=no version=3.4.1

(変更後)

No, score=-100.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, SHORTCIRCUIT,USER_IN_WHITELIST shortcircuit=ham autolearn=disabled version=3.4.1

whitelist

Whitelist and blacklist addresses are file-glob-style patterns, so
friend@somewhere.com, *@isp.com, or *.domain.net will all work.
https://cwiki.apache.org/confluence/display/spamassassin/ManualWhitelist

正規表現ではない

RBL(DNSBL)

またRBLsendmailに直接指定して拒絶しているので、
skip_rbl_checks 1
としてSpamAssassinでは点数としてカウントしないようにしています。この設定をすることにより処理速度が速くなるはずです。
http://www.hart.co.jp/spam/salocal.html

spamass-milter

 -i networks
	      Ignores messages if the originating  IP  is  in  the  network(s)
	      listed.  The message will	be passed through without calling Spa-
	      mAssassin	at all.	 networks is  a	 comma-separated  list,	 where
	      each  element  can  be either an IP address (nnn.nnn.nnn.nnn), a
	      CIDR network (nnn.nnn.nnn.nnn/nn),  or  a	 network/netmask  pair
	      (nnn.nnn.nnn.nnn/nnn.nnn.nnn.nnn).   Multiple  -i	flags will ap-
	      pend to the list.	 For example, if you list  all	your  internal
	      networks,	no outgoing emails will	be filtered.

https://www.freebsd.org/cgi/man.cgi?query=spamass-milter

milterで指定したネットワークのメールを無視する。メールはSpamAssassin(spamd)を呼び出すことなく通過する。
spamdで処理しないので負荷が減る
(trusted_networks + shortcircuit ALL_TRUSTED より負荷が低い)

エラー

spamdが起動しない

spamd[81852]: config: no rules were found! Do you need to run 'sa-update'?
spamd[81850]: child process [81852] exited or timed out without signaling production of a PID file: exit 255 at /usr/local/bin/spamd line 3034.

sa-update で修正

SpamAssassinを3.3.0にアップデートしたらspamdが起動しなくなった - mteramoto's blog

Can't locate Mail/SpamAssassin/CompiledRegexps/body_0.pm

sa-compile で修正

/var/db/spamassassin/