投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2016年2月28日日曜日

富士通(fujitsu) ESPRIMO D552/KX FMVD13027P Windows 7 pro / 8.1 pro モデルの LANドライバ

・LANドライバ

LinuxライブDVDを起動して、次の様にしてNICを認識させることで型を調べた。
(こういう場合、Linuxは偉い!と思う。)

# dmesg | grep eth0

その結果、次の型番であることがわかった。
RTL8168g / RTL8111g

realtekのウェブページ(下記)で、 上記型番でキーワード検索をかけたところ、
ドライバを見つけることができた。

http://www.realtek.com.tw/downloads/

一つのファイルに、以下のデバイスすべてのドライバが含まれているようだ。
RTL8111B/RTL8168B/RTL8111/RTL8168RTL8111C/RTL8111CP/RTL8111D(L)RTL8168C/RTL8111DP/RTL8111ERTL8168E/RTL8111F/RTL8411RTL8111G/RTL8111GUS/RTL8411B(N)RTL8118AS
ドライバ以外にも、診断プログラムなどが置かれていた。
使用するOSのバージョンによって、ファイルが異なるので間違えないようにする。

私は、Windows 7 pro 64bit で使いたかったので、下記のファイルを選んだ。
Win7 and Server 2008 R2 Auto Installation Program (SID:1813565)
ダウンロード後、
Windows 7 pro 64bit において、解凍後にフォルダ内の実行形式のファイルを実行するだけで、
自動的にドライバを適用された。

ネットワーク通信ができるようになった。



 ・ディスプレイドライバ

Intel(R) HD Graphics 4400である。
Windowsのデバイスマネージャーから、オンラインで取得し、自動的にインストールできた。

あるいは、
富士通サイトの下記のページから、ESPRIMO D552/KX を検索して、
一覧からディスプレイドライバを見つけることができた。

http://www.fmworld.net/biz/fmv/support/download/index_desktop.html
もしくは、
http://azby.fmworld.net/app/customer/driversearch/pc/drvindex?mode=1

こちらもでも、インストールでき、適用できた。




<参考>
・Linuxで使っているNICのドライバやバージョンを調べる方法いろいろ
< http://d.hatena.ne.jp/rx7/20140121/p1 > 2016年2月27日

2016年2月22日月曜日

【Clamav-milter 0.99 3.el6】Clamav-milterの複数のインスタンス化(複数のソケットを作成する)【Linux CentOS 6.7 64bit】

「互いに異なる設定が反映され独立したClamav-milterの複数のインスタンスとそのソケットを同一マシン上で同時に扱えるようにする」


CentOS6.7において、epelリポジトリからyumでインストールされる clamav-milterは、
そのままでは、一つのインスタンスしか起動しなかった。

一つのインスタンスは、一つの設定内容のみ反映していて、
当然、窓口となるソケットファイルも一つしか生成されない。

しかし、同一マシン上で、複数のPostfixインスタンスが存在していて
それぞれのPostfixインスタンスが、clamav-milterに異なる挙動を望みたい場合には、
それぞれに対し、異なる設定が反映されたclamav-milterのインスタンスとソケットが必要になる。

そのため、互いに独立した設定ファイルを反映させた複数のclamav-milterを実体化する必要があった。
いわば、clamav-milterの、multiple instances を実現することである。


以下では、私の考えた方法とその具体的な手順について記載している。



■Clamav-milterのインストール

まずは、次のページの方法で、基本となるclamav-milterをインストールした。
http://akira-arets.blogspot.jp/2016/02/fetchmail-postfix-clamav-milter.html



■「複数インスタンス」設定のためのポイントを確認

冒頭で述べた環境において、clamav-milterを「複数インスタンス」に対応させるために、
clamav-milterの、上記の起動スクリプトと設定ファイル(2種類)を修正することになる。


設定は次に挙げることがポイントになっている。


・各インスタンスごとに、独自のpidを管理する。
・各インスタンスごとに、起動スクリプトを用意する。
・各インスタンスごとに、それぞれ独自の設定ファイルを用意する。
・各インスタンスごとに、異なるソケットファイルを結びつける。



<以下では、2つのインスタンスを動作させることを目的とする。>

■初期状態の clamav-milter の起動スクリプトが動作しないように設定

複数のインスタンスを動作させるので、初期の起動スクリプトは使用しない。
初期の起動スクリプトは、複数インスタンスに対応していないためだ。
(以降の手順では、複数のインスタンスに対応した起動スクリプトや設定ファイルを、インスタンスごとに作成する。)


サービスが動作中の場合、停止しておく。
# service stop clamav-milter

初期状態では次の様に、clamav-milter の起動スクリプトが登録されている。
# chkconfig --list | grep clam
clamav-milter   0:off   1:off   2:off   3:off   4:off   5:off   6:off
clamd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
このclamav-milter の起動スクリプトが動作しないように設定した。
# chkconfig --del clamav-milter

設定を確認した。
# chkconfig --list | grep clam
clamd           0:off   1:off   2:on    3:on    4:on    5:on    6:off



■clamav-milterの設定ファイルを用意

/etc/clamav-milter.conf は、clamav-milter の挙動を設定するファイルである。


○起動するインスタンスごとに、設定ファイルをコピーして増やしておく。

まずは、バックアップを取っておく。
# cp /etc/clamav-milter.conf /etc/clamav-milter.conf.orig_ver0.99-3.el6


必要なインスタンス数の分だけ、設定ファイルを用意する。

オリジナルのものを雛型としてコピーして使う。

その際、各インスタンスの振る舞いに相応しい名前として作成する。
(この名称は、以降の設定でも、インスタンスを区別するために使用する。)

例えば、
bounceメールを返す方を、clamav-milter_local とし、
bounceメールを返さない方を、clamav-milter_global としている。
(以降では、ウイルス発見時にもbounceメールを返さないインスタンスとして、clamav-milter_global を設定していく。)

# cp /etc/clamav-milter.conf.orig_ver0.99-3.el6 /etc/clamav-milter_local.conf
# cp /etc/clamav-milter.conf.orig_ver0.99-3.el6 /etc/clamav-milter_global.conf


この段階で、次の二つの原型ファイルが存在することになる。
# ls /etc/clamav-milter_*.conf
/etc/clamav-milter_global.conf
/etc/clamav-milter_local.conf


○各インスタンス用の設定ファイルを修正する。

設定項目の意味や考え方は、次のページを参照
http://akira-arets.blogspot.jp/2016/02/fetchmail-postfix-clamav-milter.html

ここでは、複数インスタンスの動作を目的とした部分に限って設定例を挙げている。

(1つ目)
# vi /etc/clamav-milter_local.conf

(次の項目を見つけて変更する。他は必要に応じて変更する。)
MilterSocket /var/run/clamav/clamav-milter_local.sock
PidFile /var/run/clamav/clamav-milter_local.pid
OnInfected Reject
RejectMsg "REJECT - AntiVirus detected: %v"
AddHeader Add
LogFile /tmp/clamav-milter_local.log

(2つ目)
# vi /etc/clamav-milter_global.conf

(次の項目を見つけて変更する。他は必要に応じて変更する。)
MilterSocket /var/run/clamav/clamav-milter_global.sock
PidFile /var/run/clamav/clamav-milter_global.pid
OnInfected Quarantine
AddHeader Add
LogFile /tmp/clamav-milter_global.log



■clamav-milterの起動”パラメーター”ファイルを用意

clamav-milterバイナリが、起動スクリプトにより呼び出されるときに、
このファイルで指定されたパラメーターが引数として指定される。
ここに、各インスタンスに反映させるべき「設定ファイル(上記で作成したもの)」を明示する。

同様に、インスタンスごとに、用意する。


○まずはバックアップを取り、必要なインスタンス数の分だけ、設定ファイルを用意する。

# cp /etc/sysconfig/clamav-milter /etc/sysconfig/clamav-milter.orig_ver0.99-3.el6

# cp /etc/sysconfig/clamav-milter.orig_ver0.99-3.el6 /etc/sysconfig/clamav-milter_local
# cp /etc/sysconfig/clamav-milter.orig_ver0.99-3.el6 /etc/sysconfig/clamav-milter_global


○内容を表示した。

# cat /etc/sysconfig/clamav-milter.orig_ver0.99-3.el6
### Simple config file for clamav-milter, you should
### read the documentation and tweak it as you wish.

CLAMAV_FLAGS=""


○内容を修正した。

(1つ目)
# vi /etc/sysconfig/clamav-milter_local
(こちらは、デフォルトで、/etc/clamav-milter.conf が使用されるので、明示しなくてもよい。)
CLAMAV_FLAGS="--config-file /etc/clamav-milter_local.conf"
(2つ目)
# vi /etc/sysconfig/clamav-milter_global
CLAMAV_FLAGS="--config-file /etc/clamav-milter_global.conf"



■起動スクリプト(複数インスタンス対応)の追加と修正

インスタンスごとに、独自の起動スクリプトを用意する。

<手順>
・オリジナルからコピーをとって修正し、複数インスタンス対応の「起動スクリプトの基本形」を作成する。
・この「起動スクリプトの基本形」を完成させた後、インスタンスごとに起動スクリプトとしてコピーし修正を行う。(インスタンスごとに必要)


○オリジナルの起動スクリプトからコピーを取った。

# cp /etc/init.d/clamav-milter /etc/init.d/clamav-milter--for-multiple.orig_ver0.99-3.el6


○「複数インスタンス起動スクリプトの雛形」にするために修正した。

留意したこと:

・追加した変数(INSTANCESUF)に、インスタンス名のサフィックス(アンダーバー以降の文字列)を設定するだけで、
個別のインスタンス用の起動スクリプトが出来上がるようにした。

・インスタンスを区別するが、バイナリファイルは共通のもの(usr/sbin/clamav-milter)を使う。

また、修正の目的は、主に次の3つである。
・PIDファイルを使って、プロセスを区別すること。(stop、statusに影響)
・インスタンスごとに、独自の設定ファイルを読み込ませて反映させること。
・プロセスごとに、ロックファイルを用意すること。 (condrestartに影響)

以下のように、色付き、アンダーラインで示される個所に注意して、修正し雛形を完成させる。

# vi /etc/init.d/clamav-milter--for-multiple.orig_ver0.99-3.el6


#!/bin/sh
#
# Startup script for the Clamav Milter Daemon ()
#
# chkconfig: - 77 23
# description: clamav-milter is a daemon which hooks into sendmail \
#              and routes email messages to clamav.
# processname: clamav-milter
# pidfile: /var/run/clamav/clamav-milter_().pid
# config: /etc/sysconfig/clamav-milter_()

INSTANCESUF=

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

[ -x /usr/sbin/clamav-milter ] || exit 0

# Local clamav-milter_() config
CLAMAV_FLAGS=
test -f /etc/sysconfig/clamav-milter_${INSTANCESUF} && . /etc/sysconfig/clamav-milter_${INSTANCESUF}

# See how we were called.
case "$1" in
  start)
        echo -n "Starting Clamav Milter Daemon( ${INSTANCESUF} ): "
        daemon clamav-milter $CLAMAV_FLAGS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/clamav-milter_${INSTANCESUF}

        #下2行はオリジナルの起動スクリプトにはそもそも存在しない。
        #Postfixからこのソケットにアクセスできるようにするためのもの。(次のページを参照)
        #http://akira-arets.blogspot.jp/2016/02/fetchmail-postfix-clamav-milter.html

        [ $RETVAL -eq 0 ] && chown postfix:postfix /var/run/clamav/clamav-milter_${INSTANCESUF}.sock
        [ $RETVAL -eq 0 ] && chmod 0660 /var/run/clamav/clamav-milter_${INSTANCESUF}.sock
        ;;
  stop)
        echo -n "Stopping Clamav Milter Daemon( ${INSTANCESUF} ): "
        killproc -p /var/run/clamav/clamav-milter_${INSTANCESUF}.pid
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/clamav-milter_${INSTANCESUF}
        ;;
  status)
        status  -p /var/run/clamav/clamav-milter_${INSTANCESUF}.pid
        RETVAL=$?
        ;;
  restart|reload)
        $0 stop
        $0 start
        RETVAL=$?
        ;;
  condrestart)
        [ -e /var/lock/subsys/clamav-milter_${INSTANCESUF} ] && $0 restart
        RETVAL=$?
        ;;
  *)
        echo "Usage: clamav-milter( ${INSTANCESUF} ) {start|stop|status|restart|reload|condrestart}"
        exit 1
esac


exit $RETVAL


○必要なインスタンス数の分だけ、「起動スクリプトの基本形」を雛型としてコピーした。

# cp /etc/init.d/clamav-milter--for-multiple.orig_ver0.99-3.el6 /etc/init.d/clamav-milter_local
# cp /etc/init.d/clamav-milter--for-multiple.orig_ver0.99-3.el6 /etc/init.d/clamav-milter_global


○インスタンスごとの起動ファイルを完成させた。

(1つ目)
# vi /etc/init.d/clamav-milter_local

(下記のように、変数定義部分を修正)
INSTANCESUF=local

 実行権限を与えた
# chmod +x /etc/init.d/clamav-milter_local



(2つ目)
# vi /etc/init.d/clamav-milter_global

(下記のように、変数定義部分を修正)
INSTANCESUF=global

実行権限を与えた
# chmod +x /etc/init.d/clamav-milter_global




■追加・修正した起動スクリプトをシステムに登録

serviceコマンドからそれぞれのインスタンスを扱える(start stop restart status condrestart)ように、
システム起動時に各インスタンスが実体化されるように、設定した。


○serviceの登録を行った。

# chkconfig --add /etc/init.d/clamav-milter_local
# chkconfig --add /etc/init.d/clamav-milter_global



(登録を削除した。オリジナルのものは複数インスタンス用ではないので用いるべきでない。)
# chkconfig --del /etc/init.d/clamav-milter



○システム起動時に、自動起動させるための設定を行った。


# chkconfig clamav-milter_local on
# chkconfig clamav-milter_global on




○登録状況を確認した。
 
# chkconfig --list | grep clamav-milter
clamav-milter_global    0:off   1:off   2:on    3:on    4:on    5:on    6:off
clamav-milter_local     0:off   1:off   2:on    3:on    4:on    5:on    6:off



■動作確認

○サービスの起動と状態確認を行った。

(1つ目)
# service clamav-milter_local start
Starting Clamav Milter Daemon( local ):                             [  OK  ]
# service clamav-milter_local status
 (pid  22467) is running...
 # ps -A | grep 22467
22467 ?        00:00:00 clamav-milter


(2つ目)
# service clamav-milter_global start
Starting Clamav Milter Daemon( global ):                  [  OK  ]
# service clamav-milter_global status
 (pid  22488) is running...
# ps -A | grep 22488
22488 ?        00:00:00 clamav-milter


○ソケットやpidファイルが生成されているか確認した。

# ls -al /var/run/clamav/
total 20
drwxr-xr-x   2 clam    clam    4096 Feb 25 14:48 .
drwxr-xr-x. 13 root    root    4096 Feb 25 10:52 ..
-rw-rw-r--   1 clam    clam       5 Feb 25 12:58 clamav-milter_global.pidsrw-rw----   1 postfix postfix    0 Feb 25 12:58 clamav-milter_global.sock-rw-rw-r--   1 clam    clam       6 Feb 25 14:48 clamav-milter_local.pidsrw-rw----   1 postfix postfix    0 Feb 25 14:48 clamav-milter_local.sock-rw-rw-r--   1 clam    clam       5 Feb 25 10:57 clamd.pid
srw-rw-rw-   1 clam    clam       0 Feb 25 10:57 clamd.sock
clamav-milterの異なるインスタンス由来のソケットファイルが作成されていることがわかる。
Postfixなどには、clamav-milterのこれらのソケットへアクセスするように設定する。


○サービスの終了・再起動の動作を確認した。

<テスト1 start stop>

----------ともに動作している状態である。
# service clamav-milter_local status
 (pid  22467) is running...
# service clamav-milter_global status
 (pid  22488) is running...
このとき、一方のインスタンスを終了させる。
# service clamav-milter_global stop
Stopping Clamav Milter Daemon( global ):                  [  OK  ]
# ps -A | grep 22488
(結果が返らないことから、global の方は終了したことがわかる。)

このとき、他方のインスタンスを確認する。
# service clamav-milter_local status
 (pid  22467) is running...
# ps -A | grep 22467
(他方のプロセスは影響を受けていないことがわかる。)
22467 ?        00:00:00 clamav-milter

こちらも終了させる。
# service clamav-milter_local stop
Stopping Clamav Milter Daemon( local ):                             [  OK  ]
# ps -A | grep 22467
(結果が返らないことから、こちらも終了したことがわかる。)


<テスト2: condrestart>

----------ともに終了状態にある。

# service clamav-milter_local condrestart
# service clamav-milter_global condrestart
(いずれも、結果が返らないので、正常な動作である。)


ともに動作状態に切り替えた。
# service clamav-milter_local start
Starting Clamav Milter Daemon( local ):                             [  OK  ]
# service clamav-milter_global start
Starting Clamav Milter Daemon( global ):                  [  OK  ]
----------ともに動作している状態である。

# service clamav-milter_local condrestart
Stopping Clamav Milter Daemon( local ):                             [  OK  ]
Starting Clamav Milter Daemon( local ):                             [  OK  ]
# service clamav-milter_global condrestart
Stopping Clamav Milter Daemon( global ):                  [  OK  ]
Starting Clamav Milter Daemon( global ):                  [  OK  ]


―以上で完了―




<おまけ: 今回のスクリプトの修正についてのメモ>

○起動スクリプトに通っているパスについて

daemon clamav-milter $CLAMAV_FLAGS 部分の clamav-milter へは、パスが通っている。

# less /etc/init.d/functions
(略)
# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH
(略)

○起動スクリプトと、functionsスクリプト内の、ファンクションについて

service clamav-milter stop (あるいは restart) コマンドを実行したとき、
/etc/init.d/clamav-milter の、上記 stop) 内が実行される。


<下記、既に述べた方法でインストールされた /etc/init.d/clamav-milter を上記に述べた方法で、修正したものの抜粋である。>


----------(省略)----------
  stop)
        echo -n "Stopping Clamav Milter Daemon( ${INSTANCESUF} ): "
        #killproc clamav-milter (コメントアウトして、下のようにした。)
        killproc -p /var/run/clamav/clamav-milter_${INSTANCESUF}.pid
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/clamav-milter_${INSTANCESUF}
        ;;


----------(省略)----------


ここで、下記に内容を示している、killproc()ファンクションがコールされるわけだが、
修正前(上記のコメントアウトしている部分)の呼び出し方では、
killproc()ファンクション内において、pid_file変数が設定されない状態になる。
すると、インスタンスが区別されない。

(下記に、killproc()ファンクション の一部を抜粋した。)
この場合、# Find pid. の次の行で、プロセスIDを取得しようとして、
__pids_var_run() ローカルファンクションが呼ばれるものの、
動作中のプロセスIDを見つけられずに、return 3 で復帰してきてしまう。

ところが、killproc()ファンクションは、さらなる手立てで、プロセスIDを探索しようとする。
$pid は空のままなので、さらに下にある、__pids_pidof ローカルファンクションが呼び出される。
(これ以上は追跡していないが、)おそらく、この探索を経て、
「clam-milter_local」と「clam-milter_global」とが、区別されることなく共にプロセスが終了させられてしまう。
元は同じ実行ファイルから生じているプロセスだからだろう。

clam-milterの複数のプロセスが区別されないと、
service clamav-milter_local stop で、clamav-milter_global まで終了してしまう。


<下記、CentOS 6.7 64bit 版の、/etc/init.d/functions スクリプト から順不同で抜粋したものである>

----------(省略)----------

# A function to stop a program.
killproc() {
        local RC killlevel= base pid pid_file= delay try binary=

        RC=0; delay=3; try=0
        # Test syntax.
        if [ "$#" -eq 0 ]; then
                echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
                return 1
        fi
        if [ "$1" = "-p" ]; then
                pid_file=$2
                shift 2
        fi
        if [ "$1" = "-b" ]; then

----------(省略)----------
        # Find pid.
        __pids_var_run "$1" "$pid_file" "$binary"
        RC=$?
        if [ -z "$pid" ]; then
                if [ -z "$pid_file" ]; then
                        pid="$(__pids_pidof "$1")"


----------(省略)----------

__pids_var_run() {
        local base=${1##*/}
        local pid_file=${2:-/var/run/$base.pid}


----------(省略)----------
# Output PIDs of matching processes, found using pidof
__pids_pidof() {
        pidof -c -m -o $$ -o $PPID -o %PPID -x "$1" || \
                pidof -c -m -o $$ -o $PPID -o %PPID -x "${1##*/}"
}
----------(省略)----------


対策は、__pids_var_run ローカルファンクションの段階で、
pidファイルに基づいてプロセスIDを見つけられるようにすることである。

そのために、既に設定してきたように、呼び出しの元の、/etc/init.d/clamav-milter で、
「killproc」を「-pオプションを付けて呼び出し、pidファイルのパスを明示したわけだ。
killproc -p /var/run/clamav/clamav-milter_${INSTANCE}.pid
killproc()ファンクション内で、条件(-pオプション有で)分岐して、
pid_file変数に、たとえば、/var/run/clamav/clamav-milter_local.pid が設定される。
これによって、__pids_var_run ローカルファンクションでは、このpidファイルが扱われるので、
固有のプロセスIDの取得に成功するようである。



以上

2016年2月19日金曜日

【Postfix 2.6.6 x86_64】役割分担の異なる複数のPostfixインスタンスを動作させる【Linux CentOS 6.7 64bit】

「同一マシン内で、待受けIPアドレスか待受けTCPポートが異なった複数のPostfixインスタンスを動作させ、役割分担を実現する」


更新 2022/05/07 smtp_bind_address=0.0.0.0について 
更新 2022/07/18 配送エラー(dsn=4.4.1)と対処方法


Postfixは、同一マシンに、それぞれ異なる設定を持つ複数のインスタンスを動作させることができる。

これは、Postfixのマルチプルインスタンスモードで実現できる。

同一マシン内で複数インスタンスを扱うことで、例えば、
一方のインスタンスがSMTPでメールをクライアントから受け取り、
そこからSMTPプロキシなどを経て処理を経た後に、
他方のインスタンスにSMTPで入力することで、配送などの処理を継続させることが同一マシン内で可能になる。

クライアント→ [(eth0-インスタンスA)→ SMTPプロキシ(内部処理など)→ (lo-インスタンスB)] →外部SMTP


以下では、これまでのもともとのシングルインスタンス(メイン)に加えて、
さらに新しいインスタンス(サブ)を追加して構成する。



■Postfixの設定

マルチプルインスタンスに関する設定のみ抜粋している。
その他、たとえばリレーのための設定などは省略している。

○Postfixを複数インスタンスモードに切り替え

# postmulti -e init

これによって、main.cf に、次の2行が追加された。(diff コマンドで変更前のmain.cfと比べた。)
multi_instance_enable = yes
multi_instance_wrapper = ${command_directory}/postmulti -p --

○インスタンスの作成
(とりあえず、一個のみ「追加」する)

-I オプションに続けて、postfix- から始まる任意のインスタンス名を指定する。
# postmulti -I postfix-dept1-localnet -e create

これによって、main.cf に、次の1行が追加された。
multi_instance_directories = /etc/postfix-dept1-localnet

○上で作成したインスタンスの有効化 

# postmulti -i postfix-dept1-localnet -e enable

この段階までで、新規に作成するインスタンスのためのファイルがディレクトリに作成されていた。
・/etc/postfix-dept1-localnet
main.cf  master.cf
・/var/spool/postfix-dept1-localnet
active  bounce  corrupt  defer  deferred  flush  hold  incoming  maildrop  pid  private  public  saved  trace

○各インスタンスの通信インターフェイスについての設定

各インスタンスは、待ち受け用として「異なるIPアドレス」か「異なるTCPポート」と結びついている必要がある。

・異なるIPアドレスを用いる場合
ここでは、eth0に、 192.168.250.48 が割り当てられているとする。

(メイン インスタンスの設定)
# vi /etc/postfix/main.cf
inet_interfaces = localhost

(サブ インスタンスの設定)←追加分である

#vi /etc/postfix-dept1-localnet/main.cf
inet_interfaces = 192.168.250.48
#(罠)コメントアウトすること ↓(さもなければ、25番ポートが開かない)
#master_service_disable = inet

・異なるTCPポートを用いる場合
たとえば、指定するインスタンスにおいて、25ではなく2525で待受けするには次の様に設定する。

# cd /etc/postfix-dept1-localnet
# vim master.cf
(略)
#smtp      inet  n       -       n       -       -       smtpd
2525      inet  n       -       n       -       -       smtpd
(略)

○Postfixを再起動して、設定を有効化

# service postfix restart



■動作確認

○インスタンスの確認

 
各インスタンスの情報を表示させる
# postmulti -l -a
- - y /etc/postfix
postfix-dept1-localnet - y /etc/postfix-dept1-localnet
(名前、グループ名、有効かどうか、設定ファイルディレクトリ)
1行目は、メインインスタンス
2行目は、名前付きのサブインスタンス 


各インスタンスの状態を表示させる
# postmulti -p status
postfix/postfix-script: the Postfix mail system is running: PID: 16934
postfix-dept1-localnet/postfix-script: the Postfix mail system is running: PID: 17000


○開いているポートの確認

# netstat -plnt | grep :25
tcp        0      0 192.168..250.48:25            0.0.0.0:*                   LISTEN      17000/master
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      16934/master
tcp        0      0 ::1:25                      :::*                        LISTEN      16934/master


○sendmailコマンドで、各インスタンスそれぞれについてメールを送出

(メイン インスタンス を使って送信)
# echo test | sendmail -C /etc/postfix -f from@example.com to@example.com

問題なく、メールを送信することができた。


(サブ インスタンス を使って送信)
# echo test | sendmail -C /etc/postfix-dept1-localnet -f from@example.com to@example.com

こちらは、エラーが発生した。
Feb 19 00:34:56 test postfix-dept1-localnet/sendmail[17043]: fatal: User root(0) is not allowed to submit mail
そこで、次のパラメーターを、サブインスタンスの main.cf に次のコマンドで設定した
authorized_submit_users = static:anyone
# postconf -c /etc/postfix-dept1-localnet -e authorized_submit_users=static:anyone
# service postfix restart

問題なくメールを送信できるようになった。


そのときのログ(/var/log/maillog)
Feb 19 00:51:23 test postfix-dept1-localnet/pickup[17002]: xxxxxxxxxx: uid=0 from=<from@example.com>
Feb 19 00:51:23 test postfix-dept1-localnet/cleanup[17081]: xxxxxxxxxx: message-id=<20160218200123.xxxxxxxxxx@test.localdomain>
Feb 19 00:51:23 test postfix-dept1-localnet/qmgr[17003]: xxxxxxxxxx: from=<from@example.com>, size=290, nrcpt=1 (queue active)
Feb 19 00:51:23 test postfix-dept1-localnet/smtp[17083]: xxxxxxxxxx: to=<to@example.com>, relay=smtp.example.com:25, delay=0.25, delays=0.03/0.02/0.04/0.16, dsn=2.0.0, status=sent (250 ok 1111111111 qp 44444)
Feb 19 00:51:23 test postfix-dept1-localnet/qmgr[17003]: xxxxxxxxxx: removed

サブインスタンス名(postfix-dept1-localnet)で表示されていることがわかる。


このエラーが生じたように、サブインスタンスのために自動的に作成された main.cf は、
パッケージから展開されたオリジナルの main.cf(こちらはメインインスタンスが使用しているもの)とは、 少々異なっているようである。
必要に応じて、設定を調整する必要があるのだと思った。



★ところで、複数インスタンス構成で、送信時に次のエラーが発生し、
インターネット上のsmtpサーバにリレーできない場合があった。
Mar 13 05:00:01 mailsvr postfix-dept1-transfer/pickup[22237]: xxxC51xxxx: uid=0 from=<fromaddress@mydomain>
Mar 13 05:00:01 mailsvr postfix-dept1-transfer/cleanup[22242]: xxxC51xxxx: message-id=<20160312xxxxxx.xxxC51xxxx@mailsrv.mydomain>
Mar 13 05:00:01 mailsvr postfix-dept1-transfer/qmgr[22238]: xxxC51xxxx: from=<fromaddress@mydomain>, size=289, nrcpt=1 (queue active)
Mar 13 05:00:01 mailsvr postfix-dept1-transfer/smtp[22244]: connect to smtp.relay.to[5.6.7.8]:587: Connection timed out
Mar 13 05:00:31 mailsvr postfix-dept1-transfer/smtp[22244]: xxxC51xxxx: to=<toaddress@example.com>, relay=none, delay=30, delays=0.05/0.01/30/0, dsn=4.4.1, status=deferred (connect to smtp.relay.to[5.6.7.8]:587: Connection timed out)
このエラーに、随分悩まされたが解決方法がわかった。

複数インスタンスを構成している場合、それらを同時に存在させるために設定を工夫していた。
各インスタンスは、待ち受けポート番号あるいはアドレスを他のインスタンスとずらすことによって、
同時に存在できるようにしていた。

待受けアドレスを変更する場合には、既に述べた通り、inet_interfaces の設定で行う。
この値は、デフォルトは、all になっているのでこの(Connection timed out)問題は生じない。
ところが、(先の理由などのために)ここにIPアドレスを明示している場合に問題が生じる場合がある。

inet_interfaces に、IPアドレスを指定した場合、それがループバックアドレスでなければ、
そのIPアドレスを、SMTPクライアントのソースアドレスとして用いるのである。
この場合には、待受け時のアドレスの指定としてだけで用いられるのではないのだ。
そのため指定したアドレスでインターネットへの接続ができない場合、この(Connection timed out)問題が生じるのである。

したがって、解決方法は二つ考えられる。

一つは、inet_interfaces で指定する値を次の様に変えることである。
inet_interfaces の値を、ループバックアドレス、インターネットに接続できるIPアドレスにする。
あるいは、all(デフォルト値)にする。

もう一つは、そのインスタンスにおいてSMTPクライアントが使用するソースアドレスを、次の様にして明示することである。
# cd /etc/postfix-dept1-transfer
# vim master.cf
(略)
smtp      unix  -       -       n       -       -       smtp
        -o smtp_bind_address=1.2.3.4
(略)
(注意)先頭にある、「smtp      inet  n       -       n       -       -       smtpd」 ではない!

 上では、-o smtp_bind_address=1.2.3.4 を設定しているが、それだと「1.2.3.4」のインターフェスしか使用されない。
 代わりに、「-o smtp_bind_address=0.0.0.0」 を設定すると、リレー先サーバーのネットワークに応じて適切なインターフェイス(IPアドレス)を自動選択された。
 このようにしておくと、フォールバックリレーの設定でネットワークが異なるリレー先サーバーが指定されていたとしても、適切に通信が可能になる。


変更後、postfixを再起動した。
無事に、インターネット上にあるsmtpサーバへリレーすることができるようになった。



○外部ネットワークから、メールソフトを使って送信

こちらも問題なく、送信することができた。

既に確かめたように、192.168.250.48:25 を開いているのは、サブインスタンス(postfix-dept1-localnet)である。
すなわち、このサブインスタンスがクライアント(192.168.250.47)からのメールを受け、取り扱うことになる。

そのときのログ(/var/log/maillog)
Feb 19 01:05:46 test postfix-dept1-localnet/smtpd[17096]: connect from unknown[192.168.250.47]
Feb 19 01:05:46 test postfix-dept1-localnet/smtpd[17096]: xxxxxxxxxx: client=unknown[192.168.250.47]
Feb 19 01:05:46 test postfix-dept1-localnet/cleanup[17099]: xxxxxxxxxx: message-id=<xxxxxxxxxx.xxxxxxxxxx@example.com>
Feb 19 01:05:46 test postfix-dept1-localnet/qmgr[17003]: xxxxxxxxxx: from=<from@example.com>, size=603, nrcpt=1 (queue active)
Feb 19 01:05:46 test postfix-dept1-localnet/smtpd[17096]: disconnect from unknown[192.168.250.47]
Feb 19 01:05:46 test postfix-dept1-localnet/smtp[17100]: xxxxxxxxxx: to=<to@example.com>, relay=smtp.example.com:25, delay=0.3, delays=0.03/0.02/0.06/0.19, dsn=2.0.0, status=sent (250 ok 1111111111 qp 44444)
Feb 19 01:05:46 test postfix-dept1-localnet/qmgr[17003]: xxxxxxxxxx: removed



◆その後、数年間運用していたがメール送信が滞ることがあった。(番外編)

調べてみると、次のエラーがログに記録されていた。

複数インスタンスの場合、下記の例のように、postfix-outgoing のように問題が生じているインスタンスを区別することができる。

Jul 18 07:36:15 MailServer postfix-outgoing/error[12345]: **********: to=<to@example.com>, relay=none, delay=0.09, delays=0.09/0/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to smtp.outgoing.example.com[*.*.*.*]:587: Connection timed out)

上記ログには、dsn=4.4.1 と記録され、Connection timed out になっていることがわかる。
次の配送先メールサーバーは、上の例では、smtp.outgoing.example.com である。

配送状況を示す dsn=4.4.1 は、この配送先メールサーバーが一時的なエラーを返しているということを意味する。その結果、タイムアウトになっているのだ。

思い当たったのは、インターネットに接続しているルーターのグローバルIPアドレスがしばしば変化することである。
たまたま割り当てられたグローバルIPアドレスが以前にスパムメールの配信元として使われていたことがある可能性を考え、次の対処を行った。


<対処手順 その1>
1、グローバルIPアドレスの更新を行った。

そこで、ルーターを再起動することで、自動的に割り当てられるグローバルIPアドレスを別のものに更新した。
ISP(プロバイダ)によってはこの方法ではアドレスは変わらないところもあるので注意が必要である。

2、キューをフラッシュして再送信した。

キューの確認
# postqueue -c /etc/postfix-outgoing -p
(省略)
**********      516 Sat Jul 18 07:13:44  from@example.com
(lost connection with smtp.example.com[*.*.*.*] while receiving the initial server greeting)
                                         to@example.com
-- 424 Kbytes in 8 Requests.
キューフラッシュ
# postqueue -c /etc/postfix-outgoing -f

キューの再確認
# postqueue -c /etc/postfix-outgoing -p
Mail queue is empty
キューが空になったので、配送先サーバーにメールが受け取られたと判断した。
メールログにも、次の表示を確認できた。
dsn=2.0.0, status=sent

<対処手順 その2>
続いて、フォールバック用のSMTPサーバーを設定しておく。こちらの方法でも問題は解決できた。
同様の問題が発生するのに備えて、フォールバックSMTPサーバーの設定は必要だと思う。

次のように登録しておくと、relayhost のSMTPサーバーでの配送が失敗しても、
smtp_fallback_relay で指定しているSMTPサーバーで配送が試みられるようになる。

relayhost = smtp.outgoing.example.com:587
smtp_fallback_relay = another-smtp.example.com:587

それぞれのSMTPサーバーについて、認証設定も併せて必要になる。
登録方法、認証設定などについては次のページを参考にしてください。

http://akira-arets.blogspot.com/2015/05/postfix-266-x8664linux-centos-65-64bit.html

以上



<参考>

・Managing multiple Postfix instances on a single host/Using the postmulti(1) command
< http://www.postfix.org/MULTI_INSTANCE_README.html > 2016年2月19日

・Postfix Configuration Parameters/master_service_disable (default: empty)
< http://www.postfix.org/postconf.5.html#master_service_disable > 2016年2月19日

(マルチプルインスタンス構成の方法について主に参考になった文献)
・Configure Postfix with multiple instances on centos
< http://www.linuxpcfix.com/configure-postfix-with-multiple-instances-on-centos/ > 2016年2月18日

・Postfix Multi Instance Configuration
< http://steam.io/2013/11/05/postfix-multi-instance-configuration/ > 2016年2月18日


(以下の文献は作成の方法が異なっていた。)
・Postfix Multiple Instances
< http://edoceo.com/howto/postfix-multiple-instances > 2016年2月18日

・HowTo make two instance of postfix running on same machine
< http://linuxpoison.blogspot.jp/2008/02/howto-make-two-instance-of-postfix.html > 2016年2月18日


(Connection timed out 問題の解決で役に立った情報)
正解をググり当てるのが大変だった。 ↓この投稿が突破口となった。

・Postfix - specify interface to deliver outbound mail on
< http://serverfault.com/questions/234487/postfix-specify-interface-to-deliver-outbound-mail-on > 2016年3月13日

・Postfix main.cf file format / inet_interfaces (default: all)
< http://www.postfix.org/postconf.5.html#inet_interfaces > 2016年3月13日

・Postfix main.cf file format / smtp_bind_address (default: empty)
< http://www.postfix.org/postconf.5.html#smtp_bind_address > 2016年3月13日

・postfix multiple IP SMTP banner/Solution - Postfix version 2.7 or above required:
< https://serverfault.com/questions/650057/postfix-multiple-ip-smtp-banner > 2017年5月16日

・№2446 postfix 同一の宛先に送信しているのに成功と失敗する場合がある
< https://centossrv.com/bbshtml/webpatio/2446.shtml > 2020年7月18日

2016年2月17日水曜日

【Postfix 2.6.6 x86_64】STARTTLSでSMTPサーバーへリレーする方法【Linux CentOS 6.7 64bit minimal】

「Postfixから外部SMTPサーバへリレーする際にSTARTTLSで接続できるように設定する」


Postfixは「外部のSMTPサーバ」にリレーすることでも、メールを送信することができる。
もちろん、自力で各ドメインのメールサーバに届けることもできる。

SMTP-AUTUを要求する「外部のSMTPサーバ」に、
平文でユーザー名とパスワードを送り認証を受けて、メールを送り出す方法や、
自力でメールを届けさせる方法については次のページで扱った。
http://akira-arets.blogspot.jp/2015/05/postfix-266-x8664linux-centos-65-64bit.html

これを基本として、ここでは、リレー先の「外部のSMTPサーバ」がSTARTTLSに対応していて、
Postfixとの間で暗号化経路を構成してからSMTP-AUTHする場合を扱う。
ただし、外部SMTPサーバ側がSTARTTLSに対応している必要がある。

また、リレー先を複数用意おいて、メインのリレー先に到達させられない場合に対応できるようにする。

環境は、CentOS 6.7 64bit minimal で行った。
(注意)以下の設定は、安全なプライベートネットワークでの動作のみ考慮している。


■Postfixの設定


○基本的な設定

外部のSMTPサーバへのリレーを受け付ける送信元ネットワーク
(スペース区切って列挙できる。)
# postconf -e "mynetworks=127.0.0.0/8 [::1]/128 192.168.0.0/16 172.16.0.0/12"

メールを受け取るインターフェイス
# postconf -e inet_interfaces=all



○外部のSMTPサーバにリレーするための設定

・メインのリレー先SMTPサーバ([example.com]:587 のように[ ]で囲むとMXレコードを引かない。)
# postconf -e relayhost=example.com:587

・バックアップのリレー先SMTPサーバ(MXレコードを引かない場合は、同様に[ ]で括る。)
(スペースで区切って列挙できる。)
# postconf -e smtp_fallback_relay="backup.example.com:587"

このようにsmtp_fallback_relayでバックアップとしてのSMTPサーバを登録しておくことで、
メインのリレーサーバーが応答しない場合には、即座にバックアップSMTPサーバへ接続するようになる。
(注)
Postfix2.2以前では、smtp_fallback_relayは、fallback_relayという名前だった。†3
メインのリレー先が利用不可になっているときに直ちにsmtp_fallback_relayでリトライされる。†2


リレー先SMTPサーバの認証情報をファイルに作成
# echo "example.com:587 myusername:thisispassword" >> /etc/postfix/relay_password
# echo "backup.example.com:587 myusername:thisispassword" >> /etc/postfix/relay_password

認証情報ファイルからdbファイルを作成して、Postfixに登録
# postmap /etc/postfix/relay_password
# postconf -e smtp_sasl_password_maps=hash:/etc/postfix/relay_password



○リレー先SMTPサーバから認証を受けるための必要な設定

予め、次のようにパッケージを追加インストールしておく。
これは、平文SMTP-AUTHでも必要なものである。
# yum install cyrus-sasl-plain

# postconf -e smtp_sasl_auth_enable=yes
↑この設定がなければ、次のようなエラーが発生する。(/var/log/maillog)
status=bounced
said: 530 5.7.0 Authentication required (in reply to MAIL FROM command)
# postconf -e smtp_sasl_security_options=noanonymous
↑この設定がなければ、次のようなエラーが発生する。(/var/log/maillog)
status=deferred
warning: SASL authentication failure: No worthy mechs found
SASL authentication failed; cannot authenticate to server
no mechanism available
以上までは、平文でSMTP-AUTHを行う場合と同じである。


<★>
次の設定を行うことによって、STARTTLSに対応してTLSによる暗号化経路が作成されるようになる。
(ただし、外部SMTPサーバ側がSTARTTLSに対応している必要がある。)

# postconf -e smtp_tls_security_level=may

外部SMTPサーバが非対応ならば、平文でSMTP-AUTHが試みられる。
その場合、平文でパスワードを含む認証情報がネットワーク上を流れることになるので注意。



○TLS通信を行おうとする外部SMTPサーバが発行する「証明書」を検証する設定

以上の設定だけでも、メールを外部のサーバにリレーすることはできた。
しかし、次のようなメッセージがログ(/var/log/maillog)に確認された。
これは外部SMTPサーバが提示する公開鍵証明書の正当性が確かめられなかったことを示す。
Feb 16 00:19:13 secondary postfix/smtp[5777]: certificate verification failed for backup.example.com:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Feb 16 00:19:14 secondary postfix/smtp[5777]: xxxxxxxxxD: to=<test@example.com>, relay=backup.example.com:587, delay=0.63, delays=0.24/0.03/0.31/0.05, dsn=2.0.0, status=sent (250 2.0.0 xxxxxxxxxxxxxx Message accepted for delivery)
Feb 16 00:19:14 secondary postfix/qmgr[5741]: xxxxxxxxxD: removed
これは、次の設定を行うことによって解消された

# postconf -e smtp_tls_CAfile=/etc/pki/tls/certs/ca-bundle.crt



○Postfixの再起動

再起動をして、設定を有効化した。

# service postfix restart



■動作テスト

次のようなコマンドで、以上で設定済みのローカルのPostfixにメールを送った。
# echo testtest | sendmail -f 送信元アドレス 受信先アドレス


リレー先SMTPサーバを経て受信先では、次のようなメールヘッダーを確認できた。
(sendmailコマンド→Postfix→リレー先 まで抜粋)
Received: from local.example.com
    (authenticated bits=0)
    by backup.example.com (/) with ESMTP id xxxxxxxxxxxxxx
    (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO)

    for <test@example.com>; Tue, 16 Feb 2016 00:23:24 +0900 (JST)
    (envelope-from me@example.com)
Received: by local.example.com (Postfix, from userid xx)
    id xxxxxxxxxD; Tue, 16 Feb 2016 00:23:23 +0900 (JST)
Message-Id: <201602xxxxxxxxx.xxxxxxxxxD@local.example.com>
Date: Tue, 16 Feb 2016 00:23:23 +0900 (JST)
From: me@example.com (test)
To: undisclosed-recipients:;

testtest

以上


<参考>
(1) Postfix からのメール送信も SSL で暗号化する
< https://www.compnet.jp/archives/3175 > 2016年2月16日

(2) postfix smtp_fallback_relay for deferred messages to a single domain
< https://serverfault.com/questions/452824/postfix-smtp-fallback-relay-for-deferred-messages-to-a-single-domain > 2017年6月20日

(3) Postfix main.cf ファイルフォーマット/smtp_fallback_relay
< http://www.postfix-jp.info/trans-2.3/jhtml/postconf.5.html > 2017年6月20日

2016年2月16日火曜日

【Postfix 2.6.6 x86_64】Postfixで溜まっているキューを再配送あるいは削除する【Linux CentOS 6.7 64bit minimal】

Postfixにおいて、送信に失敗したメールはキューに保留され、送信がリトライされる。

送信不能なメールであれば、/var/log/maillog に、送信失敗記録をしばらくは残し続けることになる。

これは、Postfixの再起動でも解放されない。

キューを再配送あるいはすべて削除するには各々次のようにコマンドを実行する。



○念のためにキューを確認した。
mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
xxxxxxxxx      326 Tue Feb 16 11:11:11  sendfrom@example.com
(connect to exsample.com:587: Connection timed out)
                                         sendto@example.com

<すべてのキューを再配送する場合>
# postqueue -f


<全てのキューを削除する場合>
(注意!)
# postsuper -d ALL
postsuper: Deleted: 7 messages


○再度、キューを確認した。
#  mailq
Mail queue is empty


◆複数インスタンスでPostfixが動作している場合

代わりに次のコマンドを用いる。


○指定したインスタンスが扱うキューの一覧を得る。

# postqueue -c /etc/postfix-dept-transfer -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
7E1CD369EB2E      292 Sat May  1 19:00:00  mailto@example.com
(connect to smtp.server.example.com[192.168.1.120]:25: Connection timed out)
                                         envelope-to@example.com

○指定したインスタンスが扱うキューのうち指定したキューを消去する

# postsuper -c /etc/postfix-dept-transfer -d 7E1CD369EB2E
postsuper: 7E1CD369EB2E: removed
postsuper: Deleted: 1 message

○指定したインスタンスが扱う全てのキューを消去する

# postsuper -c /etc/postfix-dept-transfer -d ALL



以上



<参考>
・Flush the Postfix mail queue to force retry
< http://www.networkinghowtos.com/howto/flush-the-postfix-mail-queue-to-force-retry/ > 2016年5月6日

・[Linux][postfix] postfix にてキューにたまったメールの削除方法
< http://blog.kaburk.com/tools/postfix-mailq-delete.html > 2016年2月16日

・POSTQUEUE(1)
< http://www.postfix.org/postqueue.1.html > 2016年3月9日

2016年2月15日月曜日

【Postfix 2.6.6 x86_64】Postfixを通過するメールに対してウイルス検査を行う【clamav-milter 0.99-3.el6】【Linux CentOS 6.7 64bit minimal】


■ClamAVを導入し、設定し、動作テストを行った

次の手順でClamAV(clamd)を導入した。
http://akira-arets.blogspot.jp/2016/01/clamav-clamdscan.html

上記の手順で、次のことが達成される。

・clamdのインストール(依存・関連パッケージを含む)
・clamdの起動(また、システム起動時の自動起動設定)
・ウイルス定義ファイルの自動更新設定
・clamdscanコマンドによるウイルス検査動作テスト
・clamd動作時の、ソケットファイルの確認 (注意:これは、clamdのソケットファイルである。)
/var/run/clamav/clamd.sock


■clamav-milterを導入と設定を行った

○インストールを行った。

(Epelリポジトリを有効化しておくこと。)
# yum install clamav-milter
======================================================
 Package                            Arch                      Version                          Repository               Size
======================================================
 clamav-milter                      x86_64                    0.99-3.el6                       epel                     89 k
Installing for dependencies:
 sendmail-milter                    x86_64                    8.14.4-9.el6                     base                     57 k

Transaction Summary
======================================================

Installed:
  clamav-milter.x86_64 0:0.99-3.el6

Dependency Installed:
  sendmail-milter.x86_64 0:8.14.4-9.el6

Complete!


○clamav-milterがシステム起動時に動作するように設定した。

# chkconfig clamav-milter on


clamdとclamav-milterが、システム起動時に動作するように設定されていることを確認した。
# chkconfig --list | grep clamav-milter
clamav-milter   0:off   1:off   2:on    3:on    4:on    5:on    6:off

○clamav-milterサービスの起動と確認を行った。

サービスの設定は次のファイルで行う。
(デフォルトで、次の項目が有効化されていた。他にもたくさんオプションがありコメントアウトされていた。)
# vi /etc/clamav-milter.conf
MilterSocket /var/run/clamav/clamav-milter.sock
User clam
PidFile /var/run/clamav/clamav-milter.pid
# ClamdSocket unix:path
# ClamdSocket tcp:host:port
ClamdSocket unix:/var/run/clamav/clamd.sock
#OnInfected Quarantine
#RejectMsg "REJECT - AntiVirus detected: %v"
AddHeader Replace
この設定ファイルで、clamdのソケットファイルの指定を行っているようである。
また、生成されるclamav-milter自身のソケットファイルのパスの指定も行っているようだ。

AddHeader オプションについて(デフォルトでは、無効にされている。)
有効にする(Replaceか、Addを用いる)と、次のような情報を取り扱ったメールヘッダーに付け加える。
X-Virus-Status: Clean
X-Virus-Scanned: clamav-milter 0.99 at test.localdomain 
・AddHeader Replace
メールヘッダーの下部に、上記の情報が記載された。(置き換えられることもあるらしい。)
(注意)DKIM signatures を使っているとき一致しなくなってしまうらしい。 
・AddHeader Add

メールヘッダーのトップ(clamav-milterの時点、postfixの取り扱い情報はその直後)に、上記の情報が記載された。
(注意)procmailなどの処理を混乱させるかもしれないという。


OnInfected オプションについて
もし、このPostfixが送信専用であれば、Reject を設定した方が身内の利用者にとっては親切だと思う。 
Rejectを設定すると、配送を拒否しエラーメッセージを送信者に返す。(5xx error)
メッセージの内容は、RejectMsg オプションで任意のものを追加できる。
(/var/log/maillog にウイルス発見の旨が現れる)
Feb 17 00:51:26 secondary postfix/cleanup[10443]: xxxxxxxxxx: milter-reject: END-OF-MESSAGE from localhost[127.0.0.1]: 5.7.1 Command rejected; from=<test@example.com> to=<testto@example.com>
(その際に送信者が受け取るエラーメッセージ)
This is the mail system at host postfix.local

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system

<test@example.com>: REJECT - AntiVirus detected: Eicar-Test-Signature

Final-Recipient: rfc822; test@example.com
Action: failed
Status: 5.7.1
Diagnostic-Code: X-Postfix; REJECT - AntiVirus detected: Eicar-Test-Signature

送信専用でなく外部からメールがやってくるのなら、デフォルト(Quarantine)のままが良いかもしれない。
その場合、送信者は問題なく送信ができたように錯覚する。
しかし、ウイルス入りメールは配信されることなく、/var/spool/postfix/hold/ 内に保管される。


サービスの起動を行った。
# service clamav-milter start
Starting Clamav Milter Daemon:                             [  OK  ]
ソケットファイルが作成されたことを確認した。
(注意:clamav-milterのソケットファイルである。)
 # ls /var/run/clamav/ -al
total 16
drwxr-xr-x   2 clam clam 4096 Feb 10 19:21 .
drwxr-xr-x. 14 root root 4096 Feb 10 18:59 ..
-rw-rw-r--   1 clam clam    6 Feb 10 19:21 clamav-milter.pid
srw-r--r--   1 clam root    0 Feb 10 19:21 clamav-milter.sock
-rw-rw-r--   1 root root    6 Feb 10 19:21 clamd.pid
srw-rw-rw-   1 root root    0 Feb 10 19:21 clamd.sock

(!)ソケットの所有者やグループが、clamとrootになっているので、
このままではpostfixのプロセスからこのソケットにアクセスすることができない。
そのため、次のようにして、設定を変更する。


○postfixのプロセスがソケット(clamav-milter.sock)にアクセスできるように設定した。

一度、サービスを止めた。
# service clamav-milter stop
Stopping Clamav Milter Daemon:                             [  OK  ]

デーモン起動用のファイルを次の様に一部変更した。(スタート処理部分に下線部を追加した。)
# vi /etc/rc.d/init.d/clamav-milter

(省略)
# See how we were called.
case "$1" in
  start)
        echo -n "Starting Clamav Milter Daemon: "
        daemon clamav-milter $CLAMAV_FLAGS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/clamav-milter

        [ $RETVAL -eq 0 ] && chown postfix:postfix /var/run/clamav/clamav-milter.sock
        [ $RETVAL -eq 0 ] && chmod 0660 /var/run/clamav/clamav-milter.sock
        ;;
  stop)
(省略)


○サービスを起動し、clamav-milter.sockの所有者とグループがpostfixになっているか確認した。

# service clamav-milter start
Starting Clamav Milter Daemon:                             [  OK  ]
# ls /var/run/clamav/ -al
total 16
drwxr-xr-x   2 clam    clam    4096 Feb 10 19:55 .
drwxr-xr-x. 14 root    root    4096 Feb 10 18:59 ..
-rw-rw-r--   1 clam    clam       6 Feb 10 19:55 clamav-milter.pid
srw-rw----   1 postfix postfix    0 Feb 10 19:55 clamav-milter.sock
-rw-rw-r--   1 root    root       6 Feb 10 19:21 clamd.pid
srw-rw-rw-   1 root    root       0 Feb 10 19:21 clamd.sock


■Postfixの追加設定


○clamav-milterを経由させるための設定を追加した。

・milter動作に問題があった場合には、回避してメール配信を継続させる。
# postconf -e milter_default_action=accept

・clamav-milterの、ソケットファイルを指定した。
(ネットワークから送達されてくるメールに対して処理させる。)
# postconf -e smtpd_milters=unix:/var/run/clamav/clamav-milter.sock

(ローカルからコマンドで送信するメールに対して処理させる。)
# postconf -e non_smtpd_milters=unix:/var/run/clamav/clamav-milter.sock

・milterプロトコルのバージョンを指定した。
# postconf -e milter_protocol=2


smtpd_milters と non_smtpd_milters とで、挙動を変えたい場合は、
設定ファイルが各々違うclamav-milterのインスタンスを複数作成し、それぞれのsockファイルを指定すると良いと思う。

【Clamav-milter 0.99 3.el6】Clamav-milterの複数のインスタンス化(複数のソケットを作成する)【Linux CentOS 6.7 64bit】
http://akira-arets.blogspot.jp/2016/02/centos6-multiple-clamavmilter-instances.html



○Postfixの再起動を行った。
# service postfix restart


以上で、準備完了。



■動作テスト

当メールシステムのメールボックスに配信されるようにメールを送信した。
メールボックスにdovecotのIMAPでアクセスして、メールを受け取ることができた。

fetchmail コマンドを実行することで、Postfixに到達し、clamav-milterを経て、ウイルスチェックが為されたようである。
次のように、メールヘッダーに、clamav-milterによる情報を確認した。
(AddHeader Replace オプションが有効なので、ヘッダーの下部に発見した。)
X-Virus-Scanned: clamav-milter 0.99 at test.localdomain
X-Virus-Status: Clean


○実際に検知させてみた。


次のサイトから、The EICAR test string の内容(アスキー文字列)をコピーし、
エディタで空のファイルに書き込み保存する。(仮に、virus_testというファイルとする。)
https://en.wikipedia.org/wiki/EICAR_test_file


そして、この内容を、sendmailで送信する。

# cat virus.test | sendmail -f 送信元アドレス 送信先アドレス
 
 
〇感染メールを検知した場合、次のようなログが記載される。
 
# grep Virus /var/log/clamav-milter.log
Mon Jul 18 22:30:03 2016 -> VirusEvent: about to execute '/root/Actions/clamav-milter.InfectedMassageFound' 'Win.Trojan.Locky-30621' '65xxxxxxxxB' 'transferfrom@example.com' 'to@domain' 'Emailing: Image (850).pdf' '<4dbdxxxxxxxxxxxxxxxxxxxxxxxxxxx@example.com>' 'Mon, 18 Jul 2016 17:58:19 +0430'
Mon Jul 18 22:30:03 2016 -> VirusEvent: child exited with code 0
 
 
 






<総じて、次のようなシステムになった>
 
Incoming mails→ <fetchmail →[Postfix (⇔ clamav-milterclamd ]→ Maildir/ →dovecot> ⇔ Client PCs 




ところで、
clamav-milterのソケットを複数用意して、それぞれ異なる挙動を設定したい場合、
次のようにして、複数のソケットを用意することができた。

http://akira-arets.blogspot.jp/2016/02/centos6-multiple-clamavmilter-instances.html

Postfixが複数インスタンス動作していて、それぞれでclamav-milterの挙動を変えたい場合に有用だと思う。






以上



<参考>
・清水正人 「Postfix 実践入門」 技術評論社 2010年、P.330-338



投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad