SpamAssassin

 Clam AntiVirusとSpamAssassin   clamdを停止clamd.amavisdを起動


SpamAssassin・amavisd-newインストール
EPELリポジトリ がインストール済みであること

[root@falcon21 ~]# yum -y install spamassassin amavisd-new


SpamAssassin起動
[root@falcon21 ~]# /etc/rc.d/init.d/spamassassin start
spamd を起動中:
[root@falcon21 ~]# chkconfig spamassassin on



SpamAssassinの設定
SpamAssassin設定ファイル最新化スクリプト作成

[root@falcon21 ~]# vi spamassassin-update
#!/bin/bash

# SpamAssassin設定ファイル最新版ダウンロード
cd /etc/mail/spamassassin
wget -qN http://www.flcl.org/~yoh/user_prefs

# 設定ファイル更新時のみSpamAssassin再起動
diff user_prefs user_prefs.org > /dev/null 2>&1
if [ $? -ne 0 ]; then
    cp user_prefs local.cf

    # スパム判断したメールを添付形式にしないように設定
    echo "report_safe 0" >> local.cf

    # スパム判断したメールの件名に「***SPAM***」を付加するように設定※受信メールサーバーがPOPの場合のみ
    echo "rewrite_header Subject ***SPAM***" >> local.cf

    # SpamAssassin再起動
    if [ -f /etc/rc.d/init.d/spamassassin ]; then
        /etc/rc.d/init.d/spamassassin restart > /dev/null
    else
        systemctl restart spamassassin > /dev/null
    fi
fi
cp user_prefs user_prefs.org

--------------------
実行権限付加
[root@falcon21 ~]# chmod +x spamassassin-update

スクリプト実行
[root@falcon21 ~]# ./spamassassin-update

cron設定
[root@falcon21 ~]# mv spamassassin-update /etc/cron.daily/

[root@falcon21 ~]# vi /etc/cron.d/sa-update
10 4 * * * root /usr/share/spamassassin/sa-update.cron 2>&1 | tee -a /var/log/sa-update.log

 

clamdを停止clamd.amavisdを起動

[root@falcon21 ~]# /etc/rc.d/init.d/clamd stop
Stopping Clam AntiVirus Daemon: [ OK ]
[root@falcon21 ~]# /etc/rc.d/init.d/clamd.amavisd start
clamd.amavisd を起動中: [ OK ]
[root@falcon21 ~]# chkconfig clamd off
[root@falcon21 ~]# chkconfig clamd.amavisd on

amavisd-new設定

[root@falcon21 ~]# vi /etc/amavisd/amavisd.conf
13 @bypass_spam_checks_maps = (1); # controls running of anti-spam code
20 $mydomain = 'falcon21.space'; # a convenient default for other settings

52 @mynetworks = qw( 127.0.0.0/24 [::1] [FE80::]/10 [FEC0::]/10
53 192.168.1/24 192.168.0.0/24 );

119 $virus_admin = "virusalert\@falcon21.space";
120 #$virus_admin = undef; # notifications recip.

161 $final_bad_header_destiny = D_PASS;
384 \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamd.amavisd/clamd.sock"],

[root@falcon21 ~]# echo virusalert:root >> /etc/aliases
[root@falcon21 ~]# newaliases
postalias: warning: /etc/aliases.db: duplicate entry: "virusalert"

メールユーザvirusalertを追加
[root@falcon21 ~]# useradd -s /sbin/nologin virusalert

再度
[root@falcon21 ~]# echo virusalert:root >> /etc/aliases
[root@falcon21 ~]# newaliases

------------
amavisd-new起動
[root@falcon21 ~]# /etc/rc.d/init.d/amavisd start
ERROR: MISSING REQUIRED BASIC MODULES:
MIME::Head
MIME::Body
MIME::Entity
MIME::Parser
MIME::Decoder
MIME::Decoder::Base64
MIME::Decoder::Binary
MIME::Decoder::QuotedPrint
MIME::Decoder::NBit
MIME::Decoder::UU
MIME::Decoder::Gzip64
BEGIN failed--compilation aborted at /usr/sbin/amavisd line 249.
[失敗]



-------
[root@falcon21 ~]# perl -MCPAN -e shell

cpan[1]> install File::Temp


Result: PASS
DAGOLDEN/File-Temp-0.2304.tar.gz
/usr/bin/make test -- OK
Warning (usually harmless): 'YAML' not installed, will not store persistent state
Running make install
Prepending /root/.cpan/build/File-Temp-0.2304/blib/arch /root/.cpan/build/File-Temp-0.2304/blib/lib to PERL5LIB for 'install'
Installing /usr/local/share/perl5/File/Temp.pm
Installing /usr/local/share/man/man3/File::Temp.3pm

Appending installation info to /usr/lib/perl5/perllocal.pod

DAGOLDEN/File-Temp-0.2304.tar.gz
/usr/bin/make install -- OK
Warning (usually harmless): 'YAML' not installed, will not store persistent state

[root@falcon21 ~]# perl -MCPAN -e shell

cpan[1]> install YAML

Installing /usr/local/share/perl5/YAML.pod
Installing /usr/local/share/perl5/YAML.pm
Installing /usr/local/share/perl5/YAML/Tag.pm
Installing /usr/local/share/perl5/YAML/Mo.pm
Installing /usr/local/share/perl5/YAML/Dumper.pod
Installing /usr/local/share/perl5/YAML/Types.pm
Installing /usr/local/share/perl5/YAML/Error.pod
Installing /usr/local/share/perl5/YAML/Node.pod
Installing /usr/local/share/perl5/YAML/Any.pod
Installing /usr/local/share/perl5/YAML/Marshall.pm
Installing /usr/local/share/perl5/YAML/Tag.pod
Installing /usr/local/share/perl5/YAML/Node.pm
Installing /usr/local/share/perl5/YAML/Dumper.pm
Installing /usr/local/share/perl5/YAML/Error.pm
Installing /usr/local/share/perl5/YAML/Loader.pod
Installing /usr/local/share/perl5/YAML/Marshall.pod
Installing /usr/local/share/perl5/YAML/Any.pm
Installing /usr/local/share/perl5/YAML/Loader.pm
Installing /usr/local/share/perl5/YAML/Types.pod
Installing /usr/local/share/perl5/YAML/Dumper/Base.pod
Installing /usr/local/share/perl5/YAML/Dumper/Base.pm
Installing /usr/local/share/perl5/YAML/Loader/Base.pod
Installing /usr/local/share/perl5/YAML/Loader/Base.pm
Installing /usr/local/share/man/man3/YAML::Error.3pm
Installing /usr/local/share/man/man3/YAML::Tag.3pm
Installing /usr/local/share/man/man3/YAML::Dumper.3pm
Installing /usr/local/share/man/man3/YAML.3pm
Installing /usr/local/share/man/man3/YAML::Any.3pm
Installing /usr/local/share/man/man3/YAML::Node.3pm
Installing /usr/local/share/man/man3/YAML::Dumper::Base.3pm
Installing /usr/local/share/man/man3/YAML::Types.3pm
Installing /usr/local/share/man/man3/YAML::Loader::Base.3pm
Installing /usr/local/share/man/man3/YAML::Loader.3pm
Installing /usr/local/share/man/man3/YAML::Marshall.3pm
Appending installation info to /usr/lib/perl5/perllocal.pod
INGY/YAML-1.23.tar.gz
/usr/bin/make install -- OK
CPAN: YAML loaded ok (v1.23)

amavisd-new 再起動
[root@falcon21 ~]# /etc/rc.d/init.d/amavisd start
amavisd を起動中: [ OK ]

[root@falcon21 ~]# chkconfig amavisd on

 

Procmail設定
[root@falcon21 ~]# vi /etc/procmailrc
SHELL=/bin/bash
PATH=/usr/bin:/bin
DROPPRIVS=yes
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/
SPAM=$MAILDIR/.Spam/
LOGFILE=$HOME/.procmail.log # ログ出力先
VERBOSE=ON # 詳細ログ出力

# SpamAssassinによるスパムチェック
:0fw
|/usr/bin/spamc

# SpamAssassinにより判定されたSpam-Levelが一定値(ここでは20)以上の場合は削除
# ※必要なメールが削除されてしまう可能性があることに留意すること
:0
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
/dev/null


[root@falcon21 ~]# vi /etc/logrotate.d/procmail
/home/*/.procmail.log {
missingok
nocreate
notifempty
}

Postfix設定
[root@falcon21 ~]# vi /etc/postfix/main.cf
448 #mailbox_command = /some/where/procmail -a "$EXTENSION"
449 mailbox_command = /usr/bin/procmail


[root@falcon21 ~]# vi /etc/postfix/master.cf
最終行に追加
147 127.0.0.1:10025 inet n - n - - smtpd
148 -o content_filter=
149 -o local_recipient_maps=
150 -o relay_recipient_maps=
151 -o smtpd_restriction_classes=
152 -o smtpd_client_restrictions=
153 -o smtpd_helo_restrictions=
154 -o smtpd_sender_restrictions=
155 -o smtpd_recipient_restrictions=permit_mynetworks,reject
156 -o mynetworks=127.0.0.0/8
157 -o strict_rfc821_envelopes=yes
158 -o smtpd_error_sleep_time=0
159 -o smtpd_soft_error_limit=1001
160 -o smtpd_hard_error_limit=1000


Postfix再起動
[root@falcon21 ~]# /etc/rc.d/init.d/postfix restart
postfix を停止中: [ OK ]
postfix を起動中: [ OK ]


空メール送信テスト

メールログ(/var/log/maillog)をチェック

[root@falcon21 ~]# tail -10 /var/log/maillog
May 18 11:18:22 falcon21 postfix/smtpd[24000]: connect from localhost.localdomain[127.0.0.1]
May 18 11:18:22 falcon21 postfix/smtpd[24000]: 6ED9711EE0A: client=localhost.localdomain[127.0.0.1]
May 18 11:18:22 falcon21 postfix/cleanup[23997]: 6ED9711EE0A: message-id=<20170518021822.43CB611EE0C@mail.falcon21.space>
May 18 11:18:22 falcon21 postfix/qmgr[22280]: 6ED9711EE0A: from=<root@falcon21.space>, size=637, nrcpt=1 (queue active)
May 18 11:18:22 falcon21 postfix/smtpd[24000]: disconnect from localhost.localdomain[127.0.0.1]
May 18 11:18:22 falcon21 postfix/smtp[23999]: 43CB611EE0C: to=<hayato@falcon21.space>, orig_to=<hayato>, relay=127.0.0.1[127.0.0.1]:10025, delay=0.27, delays=0.11/0.02/0.1/0.05, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 6ED9711EE0A)
May 18 11:18:22 falcon21 postfix/qmgr[22280]: 43CB611EE0C: removed
May 18 11:18:22 falcon21 local[24003]: fatal: execvp /usr/bin/procmai: No such file or directory
May 18 11:18:22 falcon21 postfix/local[24002]: 6ED9711EE0A: to=<hayato@falcon21.space>, relay=local, delay=0.13, delays=0.04/0.02/0/0.07, dsn=4.3.0, status=deferred (temporary failure. Command output: local: fatal: execvp /usr/bin/procmai: No such file or directory )
May 18 11:19:07 falcon21 dovecot: imap-login: Login: user=<hayato>, method=PLAIN, rip=192.168.2.1, lip=192.168.2.103, mpid=24033

 
投票数:3 平均点:10.00

 
Back to Top