Postfix 設定 · 5 min read · Jan 12, 2026

Postfix、Courier、MySQL、SquirrelMailを使用した仮想ユーザーとドメイン (Debian Squeeze) - ページ 3

9 amavisd-new、SpamAssassin、ClamAVのインストール

amavisd-new、spamassassin、clamavをインストールするには、次のコマンドを実行します:

apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax

その後、amavisd-newを構成する必要があります。構成は、/etc/amavis/conf.dディレクトリにあるさまざまなファイルに分かれています。それぞれを確認して、構成に慣れてください。ほとんどの設定は問題ありませんが、3つのファイルを修正する必要があります:

最初に、/etc/amavis/conf.d/15-content_filter_modeでClamAVとSpamAssassinを有効にするために、@bypass_virus_checks_mapsと@bypass_spam_checks_mapsの行のコメントを解除します:

vi /etc/amavis/conf.d/15-content_filter_mode

ファイルは次のようになります:

| use strict; # このファイルを修正して、spamassassinによるSPAMチェックを再度有効にすることができます # およびウイルス対策チェックを再度有効にします。 # # デフォルトのウイルス対策チェックモード # 注意してください、ウイルス対策チェックはデフォルトで無効になっています。 # 有効にしたい場合は、次の行のコメントを解除してください: @bypass_virus_checks_maps = ( \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re); # # デフォルトのSPAMチェックモード # 注意してください、スパム対策チェックはデフォルトで無効になっています。 # 有効にしたい場合は、次の行のコメントを解除してください: @bypass_spam_checks_maps = ( \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re); 1; # 定義された戻り値を保証する |

次に、/etc/amavis/conf.d/20-debian_defaultsでスパム設定とスパム/ウイルスメールのアクションを確認する必要があります。デフォルト設定が問題ない場合は、何も変更する必要はありません。ファイルには多くの説明が含まれているため、ここで設定を説明する必要はありません:

vi /etc/amavis/conf.d/20-debian_defaults

| [...] $QUARANTINEDIR = "$MYHOME/virusmails"; $quarantine_subdir_levels = 1; # クアランティンディレクトリのハッシュ化を有効にする $log_recip_templ = undef; # 受取人レベル-0のログエントリを無効にする $DO_SYSLOG = 1; # syslogd経由でログを記録する(推奨) $syslog_ident = 'amavis'; # syslog識別タグ、すべてのメッセージに前置きされる $syslog_facility = 'mail'; $syslog_priority = 'debug'; # デバッグ出力を削除するにはinfoに切り替えるなど $enable_db = 1; # BerkeleyDB/libdbの使用を有効にする(SNMPおよびナニー) $enable_global_cache = 1; # $enable_db=1の場合、libdbベースのキャッシュの使用を有効にする $inet_socket_port = 10024; # デフォルトのリスニングソケット $sa_spam_subject_tag = '*SPAM* '; $sa_tag_level_deflt = 2.0; # そのレベル以上でスパム情報ヘッダーを追加する $sa_tag2_level_deflt = 6.31; # そのレベルで'spam detected'ヘッダーを追加する $sa_kill_level_deflt = 6.31; # スパム回避アクションをトリガーする $sa_dsn_cutoff_level = 10; # DSNが送信されないスパムレベル [...] $final_virus_destiny = D_DISCARD; # (データは失われません、ウイルスクアランティンを参照) $final_banned_destiny = D_BOUNCE; # フロントエンドMTAの場合はD_REJECT $final_spam_destiny = D_BOUNCE; $final_bad_header_destiny = D_PASS; # 偽陽性の可能性がある(スパム用) [...] |

最後に、/etc/amavis/conf.d/50-userを編集し、中央に$pax=’pax’;の行を追加します:

vi /etc/amavis/conf.d/50-user

| use strict; # # ここに構成ディレクティブを配置します。これにより、以前のファイルのものが上書きされます。 # # このファイルで使用できるディレクティブのドキュメントと例については、/usr/share/doc/amavisd-new/を参照してください # $pax='pax'; #------------ この行の下の何も変更しないでください ------------- 1; # 定義された戻り値を保証する |

その後、clamavユーザーをamavisグループに追加し、amavisd-newとClamAVを再起動するために、次のコマンドを実行します:

adduser clamav amavis  
 /etc/init.d/amavis restart  
 /etc/init.d/clamav-daemon restart  
 /etc/init.d/clamav-freshclam restart

これで、Postfixを構成して、受信メールをamavisd-newを通してパイプする必要があります:

postconf -e 'content_filter = amavis:[127.0.0.1]:10024'  
 postconf -e 'receive_override_options = no_address_mappings'

その後、次の行を/etc/postfix/master.cfに追加します:

vi /etc/postfix/master.cf

| [...] amavis unix - - - - 2 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes 127.0.0.1:10025 inet n - - - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks -o smtpd_bind_address=127.0.0.1 |

次に、Postfixを再起動します:

/etc/init.d/postfix restart

次に実行します

netstat -tap

そして、Postfix(master)がポート25(smtp)と10025でリッスンしており、amavisd-newがポート10024でリッスンしているのが表示されるはずです:

root@server1:/etc/courier# netstat -tap  
 アクティブなインターネット接続(サーバーと確立された)  
 プロトコル 受信キュー 送信キュー ローカルアドレス 外部アドレス 状態 PID/プログラム名  
 tcp 0 0 *:sunrpc *:* LISTEN 605/portmap  
 tcp 0 0 *:ssh *:* LISTEN 1110/sshd  
 tcp 0 0 *:55384 *:* LISTEN 617/rpc.statd  
 tcp 0 0 *:smtp *:* LISTEN 23615/master  
 tcp 0 0 localhost.localdo:10024 *:* LISTEN 22454/amavisd (mast  
 tcp 0 0 localhost.localdo:10025 *:* LISTEN 23615/master  
 tcp 0 0 localhost.localdo:mysql *:* LISTEN 3838/mysqld  
 tcp 0 52 server1.example.com:ssh 192.168.0.199:3809 ESTABLISHED 1136/0  
 tcp6 0 0 [::]:pop3 [::]:* LISTEN 19519/couriertcpd  
 tcp6 0 0 [::]:imap2 [::]:* LISTEN 19476/couriertcpd  
 tcp6 0 0 [::]:www [::]:* LISTEN 4429/apache2  
 tcp6 0 0 [::]:ssh [::]:* LISTEN 1110/sshd  
 tcp6 0 0 [::]:imaps [::]:* LISTEN 19503/couriertcpd  
 tcp6 0 0 [::]:pop3s [::]:* LISTEN 19536/couriertcpd  
 root@server1:/etc/courier#
 

10 Razor、Pyzor、DCCのインストールとSpamAssassinの構成

Razor、Pyzor、DCCは、共同フィルタリングネットワークを使用するスパムフィルターです。RazorとPyzorをインストールするには、次のコマンドを実行します。

apt-get install razor pyzor

DCCはDebian Squeezeリポジトリには存在しないため、次のようにインストールします:

cd /tmp  
 wget http://www.dcc-servers.net/dcc/source/dcc-dccproc.tar.Z  
 tar xzvf dcc-dccproc.tar.Z  
 cd dcc-dccproc-1.3.138  
 ./configure --with-uid=amavis  
 make  
 make install  
 chown -R amavis:amavis /var/dcc  
 ln -s /var/dcc/libexec/dccifd /usr/local/bin/dccifd

次に、SpamAssassinにこれら3つのプログラムを使用するように指示する必要があります。/etc/spamassassin/local.cfを編集し、次の行を追加します:

vi /etc/spamassassin/local.cf

| [...] #dcc use_dcc 1 dcc_path /usr/local/bin/dccproc #pyzor use_pyzor 1 pyzor_path /usr/bin/pyzor #razor use_razor2 1 razor_config /etc/razor/razor-agent.conf #bayes use_bayes 1 use_bayes_rules 1 bayes_auto_learn 1 |

次に、SpamAssassinでDCCプラグインを有効にする必要があります。/etc/spamassassin/v310.preを開き、loadplugin Mail::SpamAssassin::Plugin::DCCの行のコメントを解除します:

vi /etc/spamassassin/v310.pre

| [...] # DCC - DCCメッセージチェックを実行します。 # # DCCはここでは無効になっています。オープンソースではありません。DCCのライセンスの詳細については、 # を参照してください。 # loadplugin Mail::SpamAssassin::Plugin::DCC [...] |

SpamAssassinの構成を確認するには、次のコマンドを実行します:

spamassassin --lint

エラーが表示されないはずです。

その後、amavisd-newを再起動します:

/etc/init.d/amavis restart

次に、次のようにSpamAssassinのルールセットを更新します:

sa-update --no-gpg

(次に、cronジョブを作成します。デフォルトでは、crontab -eコマンドはDebian Squeezeでnanoエディタを起動します。viに慣れている場合は、次のように変更することができます:

update-alternatives --config editor

お気に入りのエディタを選択します: root@server1:/tmp/dcc-dccproc-1.3.138# update-alternatives –config editor
代替エディタの選択肢は3つあります(/usr/bin/editorを提供)。

選択 パス 優先度 ステータス

  • 0 /bin/nano 40 auto mode
    1 /bin/nano 40 manual mode
    2 /usr/bin/vim.nox 40 manual mode
    3 /usr/bin/vim.tiny 10 manual mode

現在の選択を保持するにはEnterを押すか[*]、選択番号を入力します: <– 2
update-alternatives: /usr/bin/vim.noxを使用して/usr/bin/editor(エディタ)を手動モードで提供します。
root@server1:/tmp/dcc-dccproc-1.3.138#

ルールセットが定期的に更新されるようにcronジョブを作成します。次のコマンドを実行します:

crontab -e

cronジョブエディタを開き、次のcronジョブを作成します:

| 23 4 */2 * * /usr/bin/sa-update --no-gpg &> /dev/null |

これにより、ルールセットが2日ごとに午前4時23分に更新されます。

11 クォータ超過通知

すべてのメールアカウントがクォータを超えた場合に通知を受け取りたい場合は、/usr/local/sbin/quota_notifyというファイルを作成します:

cd /usr/local/sbin/  
 vi quota_notify

| #!/usr/bin/perl -w # 著者 <[email protected]> # # このスクリプトは、postfixのmain.cfファイルにvirtual_mailbox_baseが定義されていることを前提としています。このディレクトリには、仮想ユーザーのメールディレクトリを含むディレクトリが含まれていると仮定します。 # 例えば: # # -----------/ # | # | # home/vmail/domains/ # | | # | | # example.com/ foo.com/ # | # | # ----------------- # | | | # | | | # user1/ user2/ user3/ # | # | # maildirsize # use strict; my $POSTFIX_CF = "/etc/postfix/main.cf"; my $MAILPROG = "/usr/sbin/sendmail -t"; my $WARNPERCENT = 80; my @POSTMASTERS = ('[email protected]'); my $CONAME = 'My Company'; my $COADDR = '[email protected]'; my $SUADDR = '[email protected]'; my $MAIL_REPORT = 1; my $MAIL_WARNING = 1; #get virtual mailbox base from postfix config open(PCF, "< $POSTFIX_CF") or die $!; my $mboxBase; while () { next unless /virtual_mailbox_base\s*=\s*(.*)\s*/; $mboxBase = $1; } close(PCF); #assume one level of subdirectories for domain names my @domains; opendir(DIR, $mboxBase) or die $!; while (defined(my $name = readdir(DIR))) { next if $name =~ /^\.\.? ; #skip '.' and '..' next unless (-d "$mboxBase/$name"); push(@domains, $name); } closedir(DIR); #iterate through domains for username/maildirsize files my @users; chdir($mboxBase); foreach my $domain (@domains) { opendir(DIR, $domain) or die $!; while (defined(my $name = readdir(DIR))) { next if $name =~ /^\.\.? ; #skip '.' and '..' next unless (-d "$domain/$name"); push(@users, {"$name\@$domain" => "$mboxBase/$domain/$name"}); } } closedir(DIR); #get user quotas and percent used my (%lusers, $report); foreach my $href (@users) { foreach my $user (keys %$href) { my $quotafile = "$href->{$user}/maildirsize"; next unless (-f $quotafile); open(QF, "< $quotafile") or die $!; my ($firstln, $quota, $used); while () { my $line = $_; if (! $firstln) { $firstln = 1; die "Error: corrupt quotafile $quotafile" unless ($line =~ /^(\\d+)S/); $quota = $1; last if (! $quota); next; } die "Error: corrupt quotafile $quotafile" unless ($line =~ /\s*(-?\d+)/); $used += $1; } close(QF); next if (! $used); my $percent = int($used / $quota * 100); $lusers{$user} = $percent unless not $percent; } } #send a report to the postmasters if ($MAIL_REPORT) { open(MAIL, "| $MAILPROG"); select(MAIL); map {print "To: $_\n"} @POSTMASTERS; print "From: $COADDR\n"; print "Subject: Daily Quota Report.\n"; print "DAILY QUOTA REPORT:\n\n"; print "----------------------------------------------\n"; print "| % USAGE | ACCOUNT NAME |\n"; print "----------------------------------------------\n"; foreach my $luser ( sort { $lusers{$b} <=> $lusers{$a} } keys %lusers ) { printf("| %3d | %32s |\n", $lusers{$luser}, $luser); print "---------------------------------------------\n"; } print "\n--\n"; print "$CONAME\n"; close(MAIL); } #email a warning to people over quota if ($MAIL_WARNING) { foreach my $luser (keys (%lusers)) { next unless $lusers{$luser} >= $WARNPERCENT; # skip those under quota open(MAIL, "| $MAILPROG"); select(MAIL); print "To: $luser\n"; map {print "BCC: $_\n"} @POSTMASTERS; print "From: $SUADDR\n"; print "Subject: WARNING: Your mailbox is $lusers{$luser}% full.\n"; print "Reply-to: $SUADDR\n"; print "Your mailbox: $luser is $lusers{$luser}% full.\n\n"; print "Once your e-mail box has exceeded your monthly storage quota\n"; print "your monthly billing will be automatically adjusted.\n"; print "Please consider deleting e-mail and emptying your trash folder to clear some space.\n\n"; print "Contact <$SUADDR> for further assistance.\n\n"; print "Thank You.\n\n"; print "--\n"; print "$CONAME\n"; close(MAIL); } } |

ファイルの先頭の変数を調整することを確認してください(特に[email protected]のメールアドレス)。

ファイルを実行可能にする必要があります:

chmod 755 quota_notify

次のコマンドを実行して、スクリプトのcronジョブを作成します:

| 0 0 * * * /usr/local/sbin/quota_notify &> /dev/null |

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。