メールサーバ(postfix)をソースよりインストールして、運用(外部公開)するまでを紹介します。初回はインストールを中心に記載します。OSは、Fedora14の64bitを使用しました。CentOSの64bitでも同じ操作でインストールできます。32bitのOSにインストールするときは、フォルダー名(lib64→lib)が一部違うので注意してください。

1. sendmailの停止とファイルの退避
OSの起動時にsendmaiが起動しないようにする
[root@localhost ~]# chkconfig sendmail off

コマンドファイルの退避
[root@localhost ~]# mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
[root@localhost ~]# chmod 755 /usr/sbin/sendmail.OFF
[root@localhost ~]# mv /usr/sbin/newusers /usr/sbin/newusers.OFF
[root@localhost ~]# chmod 775 /usr/sbin/newusers.OFF
[root@localhost ~]# mv /usr/bin/mailq /usr/bin/mailq.OFF
[root@localhost ~]# chmod 775 /usr/bin/mailq.OFF

2. Postfixのインストール
本体をインストールする前に必要なモジュールをインストールします。
[root@localhost ~]# yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-ldap db4

 Postfixのダウンロードは、Postfixオフィシャルサイトからダウンロードしてください。ダウンロードが完了したら「/usr/local/src/」にファイルを移動させます。次にPostfix用のユーザーとグループを作成し、先ほどダウンロードしたファイルを展開し、インストールします。

[root@localhost src]# groupadd postfix
[root@localhost src]# useradd postfix -g postfix -M -s /sbin/nologin
[root@localhost src]# groupadd postdrop
[root@localhost src]# tar zxvf postfix-2.6.5.tar.gz
[root@localhost src]# cd postfix-2.6.5
[root@localhost src]# make makefiles CCARGS=”-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl” AUXLIBS=”-L/usr/lib64 -lsasl2″
[root@localhost src]# make
[root@localhost src]# make install
[root@localhost src]# /usr/bin/newaliases

3. 起動
Postfixの起動と確認
[root@localhost ~]# postfix start
または
[root@localhost ~]# /usr/sbin/postfix start

[root@localhost ~]# ps aux | grep post
(結果)
postfix 17104 0.0 0.0 6132 1576 ? S 2010 4:21 qmgr -l -t fifo -u

4. ローカルメールの送信テスト
メールの送信(rootユーザへ)
[root@localhost ~]# mail -s “test” root
内容を記入する
Ctrl + D ← で抜ける
Cc: ← エンター

メールの確認
[root@localhost ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
“/var/spool/mail/root”: 3 messages 1 unread
1 root Sun Feb 20 13:32 19/587 “test”

ログファイルの確認
[root@localhost ~]# tail -n 100 /var/log/maillog

5. 自動起動
ソースよりインストールした場合は、起動ファイルを作成しなければなりません。私自身、以前ネットで公開されていたソースを利用させてもらっています。「黒ぶちメガネのサーバ構築まとめ」さんのサイトを参考にさせていただきました。

[root@localhost ~]# vi /etc/rc.d/init.d/postfix

postfixの内容

#!/bin/sh
#
# postfix Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
# that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf
#
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = “no” ] && exit 0

[ -x /usr/sbin/postfix ] || exit 0
[ -d /etc/postfix ] || exit 0
[ -d /var/spool/postfix ] || exit 0

RETVAL=0

start() {
 # Start daemons.
 echo -n “Starting postfix: ”
 /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure
 RETVAL=$?
 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
 echo
 return $RETVAL
}
stop() {
 # Stop daemons.
 echo -n “Shutting down postfix: ”
 /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure
 RETVAL=$?
 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
 echo
 return $RETVAL
}
reload() {
 echo -n “Reloading postfix: ”
 /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure
 RETVAL=$?
 echo
 return $RETVAL
}
abort() {
 /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure
 return $?
}
flush() {
 /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure
 return $?
}
check() {
 /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure
 return $?
}
restart() {
 stop
 start
}
# See how we were called.
case “$1” in
start)
 start
 ;;
stop)
 stop
 ;;
restart)
 stop
 start
 ;;
reload)
 reload
 ;;
abort)
 abort
 ;;
flush)
 flush
 ;;
check)
 check
 ;;
status)
 status master
 ;;
condrestart)
 [ -f /var/lock/subsys/postfix ] && restart || :
 ;;
*)
 echo “Usage: postfix {start|stop|restart|reload|abort|flush|check|status|condrestart}”
 exit 1
esac
exit $?

[root@localhost ~]# chmod 755 /etc/rc.d/init.d/postfix
[root@localhost ~]# chkconfig –add postfix
[root@localhost ~]# /usr/bin/newaliases
[root@localhost ~]# /etc/rc.d/init.d/postfix start
起動できればOKです。

6. SendMailからPostfixへの切替
 ソースからインストールした場合は、SendMailを停止するだけでOKですが、yumでインストールした場合は、下記のコマンドで変更してください。
[root@localhost ~]# system-switch-mail

(次回の予定 
 次回は、メールサーバー外部公開します。OP25B対策の設定などの紹介をします。