34:メールサーバーの設定:targreyを使用しspamを防止

参考URL:http://www.kinryokai.net/modules/news/article.php?storyid=162
http://centossrv.com/postfix-targrey.shtml
現時点(2014-06-12)ではpostfixとpostgreyのバージョンは参考URLの前者と同じです。

# postconf|grep mail_version
mail_version = 2.6.6
# postgrey –version
postgrey 1.34

2014年9月8日にやっと本運用になりました。今の所不具合はありませんが、何かありましたらここで発表します。
sleepパッチをあてたpostfix(遅延応答したら即座にSMTPプロセスを終了) (rpm):ここをクリック
targreyパッチをあてたpostgrey (rpm): ここをクリック
ここからは、上の二つのファイルをrootにダウンロードした前提で進めます。
まずはpostfixのインストール
# rpm -Uvh –force /ダウンロードしたdirectory/postfix-2.6.6-2.2.el6_1.x86_64.rpm
インストールの確認
# rpm -qa|grep postfix
postfix-2.6.6-2.2.el6_1.x86_64 と表示されればOK
次にpostgreyですがその前に必要なパッケージのインストール
# yum -y install postgrey && rpm -e postgrey
「注:2014-08-02:今日テストしたらエラーが出た。本来はEPELのミラーに在る筈だが、無くなっているみたい。私の場合はEPELのミラーはftp,iij.ad.jpに設定されているが、ここには無くなっている。試しにftp,riken.jpもチェックしたがやはり無い。でも本家のhttp://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/postgrey.htmlには置いてある。どうなっているんだ!!ともかくこれは付随してインストールが必要なパッケージのためのコマンドなので、無視して直接次に進んでもよい。但し環境によっては、必要なパッケージをインストールしろと言われるかも?必要なのは色々な下記のperlのパッケージなど」
これは perl-BerkeleyDB perl-IO-Multiplex perl-Net-DNS perl-Net-Server をインストールするため
# wget apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/perl-Parse-Syslog-1.10-1.el6.rf.noarch.rpm
# rpm -ivh perl-Parse-Syslog-1.10-1.el6.rf.noarch.rpm
でpostgreyのインストール
# rpm -Uvh /ダウンロードしたdirectory/postgrey-1.34-1.rf.noarch.rpm
/etc/postfix/main.cfの設定

smtpd_recipient_restrictions = 
    permit_mynetworks,
    permit_sasl_authenticated,
    permit_auth_destination,
    reject_unauth_destination,
--追加(ここから)--
    check_recipient_access hash:$config_directory/whitelist_recipient
    check_client_access    hash:$config_directory/whitelist_client
    check_client_access    regexp:$config_directory/permit_client_nots25r
    check_policy_service   inet:60000
    permit

smtpd_data_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    reject_unauth_destination
    check_recipient_access hash:$config_directory/whitelist_recipient
    check_client_access    hash:$config_directory/whitelist_client
    check_client_access    regexp:$config_directory/permit_client_nots25r
    check_policy_service   inet:60000
    permit
--追加(ここまで)--

taRgrey用Postfix設定ファイルダウンロード
# wget http://k2net.hakuba.jp/spam/postfix.conf.2.tar.gz
解凍
# tar zxvf postfix.conf.2.tar.gz
各ファイルをコピー
# cp postfix.conf.2/whitelist_recipient /etc/postfix/
# cp postfix.conf.2/whitelist_client /etc/postfix/
# cp postfix.conf.2/permit_client_nots25r /etc/postfix/
# rm -fr postfix.conf.2/
# rm -f postfix.conf.2.tar.gz
whitelist_recipientのDB化
# postmap /etc/postfix/whitelist_recipient
whitelist_clientのDB化
# postmap /etc/postfix/whitelist_client
/etc/rc.d/init.d/postgreyの設定

#OPTIONS="--unix=$SOCKET" ←コメントアウト
OPTIONS="--dbdir=$DBPATH --inet=127.0.0.1:60000 --tarpit=125 --targrey --retry-count=2 --delay=3600" ←追記

postgreyの起動、postfix再起動など
# service postgrey start
# chkconfig postgrey on
# service postfix restart
その後メールのテストをする
postfixにパッチを当てているため、自動アップデートを無効にする。
# yum -y install yum-versionlock
# sed -i ‘s/enabled = 0/enabled = 1/g’ /etc/yum/pluginconf.d/versionlock.conf
# touch /etc/yum/pluginconf.d/versionlock.list
# rpm -q postfix >> /etc/yum/pluginconf.d/versionlock.list
# rpm -q postgrey >> /etc/yum/pluginconf.d/versionlock.list
postfixのアップデートがあったらメールで知らせてくれるスクリプトの作成。もっともソースもアップデートされていなけば出来ないが
# gedit /etc/cron.daily/yum-check-update

#!/bin/bash

# versionlockパッケージアップデートチェックスクリプト

YUMTMP=$(mktemp)
for pkg in `cat /etc/yum/pluginconf.d/versionlock.list`
do
    chkname="$chkname `rpm -qi $pkg|grep Name|awk '{print $3}'`"
done
yum --noplugins check-update $chkname > $YUMTMP
[ $? -eq 100 ] && cat $YUMTMP
rm -f $YUMTMP

# chmod +x /etc/cron.daily/yum-check-update
アップデート検知時はroot宛にメール通知されるので、最新版で再インストールする

フジマル について

1947年生れ、東京電機大学二部電気通信工学科卒、最後はスリランカ航空で営業だったのですが2018年に㈱インパック・ジャパンに再就職。趣味:登山、スキー、車いじり、コンピューター
カテゴリー: 省エネサーバー製作(CentOS 6) パーマリンク

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください