Unix/Solaris10

Spam Assassin 설치법 정리

ForceCore 2008. 10. 15. 14:49
Spam Assassin을 받는다.
Spam Assassin의 설치 명령어 자체는 간단하다.
$ perlgcc Makefile.PL
$ make
$ make test (optional)
# make install
하지만 도중에 필요한 모듈이 많이 있다.
그 모듈들을 다 설치할 때 까지는 perlgcc Makefile.PL을 계속 하게 된다.

펄모듈들인데, 되도록이면, 다 설치하는 편이 좋다.
그래야지 SpamAssassin의 기능을 모두 사용할 수 있게 되고
그러면 더욱 강력한 스팸필터가 될 수 있기 때문이다.

여기에 그 기록이 적혀 있다.
모듈 설치는 귀찮은데 다 가능하긴 하다.
perl Makefile.PL이 아니라 perlgcc Makefile.pl을 해야 한다는 것을 명심한다면...

CPAN을 통해 하는 방법도 있다.
위의 고생을 하는 것이 CPAN의 빌드가 잘 동작하지 않기 때문인데,
길들인 CPAN을 가지면 편하지...a
아직 완전히 검증된 것은 아니지만
(모듈 몇 개만 설치해본 수준이다.) 되는 듯 해서 올린 글이다.

perlgcc Makefile.PL단계가 끝나면, make install까지는 그냥 문제 없이 잘 된다.

Postfix와 어떻게 연결하는지가 문제가 된다.
가장 쉬운방법은...

procmail을 설치한다.
아니면 솔라리스에 이미 있을 수도 있다.

postfix의 main.cf를 수정한다.
mailbox_command = /usr/local/bin/procmail
물론, procmail의 위치에 따라 다르다. /opt/sfw/bin/procmail 에 이미 있는 경우도 있다.

설치한 procmail의 위치에 따라 procmailrc를 적당한 위치에 만들자.
필자의 경우는 /usr/local/etc/procmailrc 혹은, /opt/sfw/etc/procmailrc 이었다.
(둘 다 봤다 -_-;;)
/etc/procmailrc 라는 소프트링크도 만들어 두었다.

procmailrc의 내용은 이렇게 한다.
PATH=/usr/bin:/usr/local/bin:/bin:/usr/perl5/5.8.4/bin:/opt/sfw/bin
SHELL=/bin/sh

# SpamAssassin sample procmailrc
#
# Pipe the mail through spamassassin (replace 'spamassassin' with 'spamc'
# if you use the spamc/spamd combination)
#
# The condition line ensures that only messages smaller than 250 kB
# (250 * 1024 = 256000 bytes) are processed by SpamAssassin. Most spam
# isn't bigger than a few k and working with big messages can bring
# SpamAssassin to its knees.
#
# The lock file ensures that only 1 spamassassin invocation happens
# at 1 time, to keep the load down.
#
# ! ? test -f $HOME/.disable_spam_assassin disables spam filtering optinally, userwise.
:0fw: spamassassin.lock
* < 256000
* ! ? test -f $HOME/.disable_spam_assassin
| spamassassin

# Mails with a score of 15 or higher are almost certainly spam (with 0.05%
# false positives according to rules/STATISTICS.txt). Let's put them in a
# different mbox. (This one is optional.)
:0:
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
almost-certainly-spam

# All mail tagged as spam (eg. with a score higher than the set threshold)
# is moved to "probably-spam".
:0:
* ^X-Spam-Status: Yes
probably-spam

# Work around procmail bug: any output on stderr will cause the "F" in "From"
# to be dropped.  This will re-add it.
:0
* ^^rom[ ]
{
  LOG="*** Dropped F off From_ header! Fixing up. "

  :0 fhw
  | sed -e '1s/^/F/'
}
* ! ? test -f $HOME/.disable_spam_assassin
이 줄은 눈여겨 보아야 한다.
각 유저가 홈디렉토리에 .disable_spam_assasin이라는 파일을 가지고 있으면 (빈파일이든 뭔가 있는 파일이든 상관 없고 존재하기만 하면 된다.) 그 사람은 스팸필터를 사용하지 않는 유저가 된다 -_-;

끝... 이 아니구나.
거의 잘 동작하지만, spam의 threshold를 변경하고 싶을 수도 있다.
/usr/perl5/5.8.4/etc/mail/spamassassin/local.cf 에서 변경할 수 있다.
필자는 /etc/postfix/spamassassin이라는 소프트링크를 만들어 두었다.

스팸 80%를 걸러낸 procmailrc 레시피
이런 것도 있다. pdf로도 덤프함.
나중에 해보고 싶으면 위 설정도 적용해 보세요...a