最新の安定版である、Postfix 2.10.0 のインストールと設定を行いました。インストール手順と設定概要、その他操作の記録をしておきます。
Postfix 2.10.0 は、2013/02/11 にリリースされています。安定版とはいえ、パッチが出てからのほうが良いかなと思いつつ作業を進め、無事稼働できています。
インストール環境でのPostfixの役割
メール送信用SMTPサーバです。
既存sendmailの停止
chkconfig で 既存のsendmail起動設定を停止します。
# /sbin/chkconfig --list|grep sendmail sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off # /sbin/chkconfig --level 2345 sendmail off # /sbin/chkconfig --list|grep sendmail sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off #
もし、sendmail が起動していたら停止します。
# /etc/init.d/sendmail stop # ps -awef|grep sendmail | grep -v grep #
db4-devel インストール
Postfix 2.10 Patchlevel 0 をインストールする前に、db4-devel(Berkeley DB 開発パッケージ)をインストールする必要があります。
# rpm -qa | grep db4 db4-4.7.25-16.el6.x86_64 db4-utils-4.7.25-16.el6.x86_64 # yum install db4-devel # rpm -qa | grep db4 db4-4.7.25-17.el6.x86_64 db4-devel-4.7.25-17.el6.x86_64 db4-cxx-4.7.25-17.el6.x86_64 db4-utils-4.7.25-17.el6.x86_64 #
この後に、Postfix をインストールします。
Postfix インストール
ソースからインストールします。インストールの手順は以下になります。
# cd /usr/local/src # wget http://mirror.ramix.jp/postfix-release/official/postfix-2.10.0.tar.gz # tar zxvf postfix-2.10.0.tar.gz # cd postfix-2.10.0 # make # make install
postfix-install での確認入力項目は全てデフォルトとします。内容は以下です。
install_root: [/] tempdir: [/usr/local/src/postfix-2.10.0] config_directory: [/etc/postfix] command_directory: [/usr/sbin] daemon_directory: [/usr/libexec/postfix] data_directory: [/var/lib/postfix] html_directory: [no] mail_owner: [postfix] mailq_path: [/usr/bin/mailq] manpage_directory: [/usr/local/man] newaliases_path: [/usr/bin/newaliases] queue_directory: [/var/spool/postfix] readme_directory: [no] sendmail_path: [/usr/sbin/sendmail] setgid_group: [postdrop]
以上でインストール作業は完了です。
aliases
エイリアス設定は以下のように行いました。(実際はメール送信用途のみのサーバですので、エイリアス利用はしないのですが。)
まずは、main.cf に以下を追加しました。
alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases
あとは、Postfix付属のaliasesを利用しました。
# mv /etc/postfix/aliases /etc/aliases # (/etc/aliases の更新) # newaliases
/etc/aliases を変更した際には、毎回 newaliases を実行します。
Postfix 設定ファイル
以下の2つが主要なPostfixの設定ファイルです。
- /etc/postfix/main.cf
- /etc/postfix/master.cf
postconf コマンド
「postconf」コマンドは便利に使えるPostfixの設定ユーティリティです。
私が良く使うオプションは以下です。
- -d
- デフォルトのパラメータを出力
- 出力される行数はかなり多いです。必要に応じてgrepコマンドで絞り込み表示します。
- -n
- main.cf で明示的に指定し、デフォルト値ではなくなったパラメータ設定を表示
起動・停止
postfixコマンドを使って、起動と停止の操作を行います。
# ps -ef|grep postfix | grep -v grep # postfix start postfix/postfix-script: starting the Postfix mail system # ps -ef|grep postfix | grep -v grep root 13442 1 0 18:56 ? 00:00:00 /usr/libexec/postfix/master -w postfix 13443 13442 0 18:56 ? 00:00:00 pickup -l -t unix -u postfix 13444 13442 0 18:56 ? 00:00:00 qmgr -l -t unix -u # postfix stop postfix/postfix-script: stopping the Postfix mail system # ps -ef|grep postfix | grep -v grep #
ちなみに、私の環境では、postfix start 時に以下のようなWarningが発生していました。
# postfix start postfix/postfix-script: warning: /usr/lib/sendmail and /usr/sbin/sendmail differ postfix/postfix-script: warning: Replace one by a symbolic link to the other postfix/postfix-script: starting the Postfix mail system #
/usr/lib/sendmail のスタティックリンクが既存sendmailを見ていたので、lnコマンドで/usr/sbin/sendmail に対してリンクを張り直しました。
メール送信テスト
mailコマンドでメール送信テストを行います。
mailコマンドが入っていない場合はインストールします。
# which mail /usr/bin/which: no mail in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) # # yum install mailx # which mail /bin/mail #
簡単なメール送信コマンドは以下です。
$ echo "this is test mail." | mail (送信先メールアドレス)
メールの送信状況は、/var/log/maillog で確認します。また、実際に送信先メールアドレスにてメールが受信できたか確認します。
補足:alternatives でのMTA選択
私の環境では、alternativesコマンド実行時に、sendmail.postfix が表示されません。
# alternatives --config mta There is 1 program that provides 'mta'. Selection Command ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail Enter to keep the current selection[+], or type selection number: #
おそらく、Postfixインストール時に、/usr/sbin/sendmail をリンクではなくファイルとしてインストールしている為だと思います。main.cf の sendmail_path でも、/usr/sbin/sendmail にしていますし。/var/log/maillog を見ていると、メール送信時にはpostfixが使われていますので問題ないです。