仕事上、どうしてもテスト的にメールサーバを立てなければならなくなった(LAN内で使うサーバではあるが・・・)。どうせやるならSendMailは使いたくないということでPostfixを使うことにした。
ここではインストールと起動方法の紹介のみを行い、設定・使い方は別のページで紹介する。
PostfixはSendMailの代わりに使うものなので、まずデフォルトでインストールされているSendMailをアンインストールする。
# rpm -e sendmail Postfixをインストールする前に、グループとユーザを作成する。何に使うのかは調査中・・・(とりあえずインストール時に必要)
# groupadd postfix
# groupadd postdrop
# useradd -g postfix postfix
/usr/local/srcなどにPostfixのソース・ファイルをコピーし、次のように展開する。
$ cd /usr/local/src
$ tar zxvf postfix-2.0.16.tar.gz展開してできたソース・ディレクトリに移動し、コンパイルを実行(./configureを行わないのがポイント)。
$ cd /usr/local/src/postfix-2.0.16
$ makeコンパイルが終了したら、インストールを行う。いくつかの質問に答えなければならない(ほとんどデフォルトで大丈夫・・・?)。
$ make install
Postfixの設定は
/etc/postfix/main.cfで行う。編集した場所のみを挙げてみる。
myhostname = mail.andokomuten.jp
mydomain = andokomuten.jp
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain $mydomain
mynetworks_style = subnet
mynetworks = 192.168.0.0/24, 127.0.0.0/8
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
Postfixを自動起動するためのスクリプトファイルを作成する。viで
/etc/rc.d/init.d/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 $?作成後、実行権限を付けてサービスに登録する。
# chmod 755 /etc/rc.d/init.d/postfix
# chkconfig --add postfix
Postfixの起動は次のとおり。
# /etc/rc.d/init.d/postfix start Postfixの停止は次のとおり。
# /etc/rc.d/init.d/postfix stop
Postfixを始めて起動したら、一度だけ次のコマンドを実行する。
# newaliases
独自にドメインを取得してインターネットに直接接続している場合、構築したメールサーバを外部に公開すれば外部にメールを発信したり、外部から独自ドメインのメールアドレス宛てにメールを受け取ることができる。
その場合、プロバイダのメールサーバを経由することになるので、main.cfファイルを編集してrelayhostパラメータにプロバイダのメールサーバを設定する。
relayhost = プロバイダのメールサーバ