試した環境Centos4.4
Postfix mail_version = 2.2.10 (yumからインストール)
dovecot-1.1.3(ソースからインストール)
メールサーバのドメイン
mail.kapi.jp
設定するバーチャルドメイン
info@kapi.jp
info@postfix.kapi.jp
認証
smtp-authのプレーンテキスト認証
postfix installyumでさくっとインストール
> yum install postfix
[root@demo-system apps]# yum install postfix.x86_64
Setting up Install Processls -la sasldb2
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for postfix to pack into transaction set.
postfix-2.2.10-1.2.1.el4_ 100% |=========================| 40 kB 00:00
---> Package postfix.x86_64 2:2.2.10-1.2.1.el4_7 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
postfix x86_64 2:2.2.10-1.2.1.el4_7 update 3.4 M
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 3.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/1): postfix-2.2.10-1.2 100% |=========================| 3.4 MB 00:03
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: postfix ######################### [1/1]
Installed: postfix.x86_64 2:2.2.10-1.2.1.el4_7
Complete!
デフォルト状態の確認
centosだと事前にsendmailが入っていて有効になっているので止めておく。
>/etc/init.d/sendmail stop
デフォルトMTAの切り替え
> alternatives --config mta
There are 2 programs which provide 'mta'.
Selection Command
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number:2
>
postfixの設定/etc/postfix/main.cfから
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = mail.kapi.jp
mydomain = mail.kapi.jp
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks_style = host
### Virtual domain setting ###
virtual_mailbox_domains = /etc/postfix/vdomain
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 100
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_alias_maps = hash:/etc/postfix/virtual
### debug ###
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
### Sendmail Compatible ###
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
### etc ###
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
smtpd_banner = $myhostname ESMTP unknown
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.2.10/samples
readme_directory = /usr/share/doc/postfix-2.2.10/README_FILES
### smtp sasl setting ###
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
message_size_limit = 10485760
重要なところ
myhostname、mydomainはバーチャルドメインを使用する場合、被らないドメインを
設定する。
### Virtual domain setting ###のところ。
これらは必須。
### Sendmail Compatible ###のところはずれたら問題外だが、yumから入れたらデフォで
OKなはず。
### smtp sasl setting ###saslを使う場合、これも必須。
### Virtual domain setting ###で各設定ファイルや、Pathを指定してるので、これらを
用意する。
vi /etc/postfix/vdomain
# バーチャルドメインするドメインたち
kapi.jp postfix.kapi.jp
vi /etc/postfix/vmailbox
# バーチャルドメインのアカウントごとのメールボックスの場所を指定
info@kapi.jp kapi.jp/info/Maildir/
info@postfix.kapi.jp postfix.kapi.jp/info/Maildir/
/etc/postfix/virtual
# 実アカウントとバーチャルアカウントのaliasをマップしてる(?)
info@kapi.jp info@kapi.jp
info@postfix.kapi.jp info@postfix.kapi.jp
DBを更新
> postmap /etc/postfix/vdomain
> postmap /etc/postfix/vmailbox
> postmap /etc/postfix/virtual
vhostユーザーの作成
上記の設定の通り、ID:5000の場合の例
groupadd vhosts -g 5000
adduser vhosts -s /sbin/nologin -g vhosts -d /dev/null
※uidが違ってしまうので、この後、vipwで直接vhostsユーザーのIDを変更した・・・。
vhostsのDirectoryを作成
confに従い、/var/mail/vhostsディレクトリを作成しておく。
chownでvhosts所有にしておく。
> mkdir /var/mail/vhosts
> chown -R vhosts:vhosts /var/mail/vhosts
このvhostsディレクトリを作成しておくと、設定したバーチャルドメイン宛ての
メールが届き次第、その下の階層が出来上がる。
postfixの起動
> /etc/init.d/postfix start
設定変更、DB更新時は
> /etc/init.d/postfix reload
する必要有り。
■Postfixに関する便利なコマンド
設定の確認
postconf -d
設定BDの更新
postmap [pass]
> postmap /etc/postfix/vdomain
でvdomain.dbが更新される
sasl2のインストール(?)と設定以前悪戦苦闘した時に入れたのか、今回すでに入っていて、どうやって入れたか忘れた・・。
覚えてないってことは多分デフォで入ってたんだろな。
sasl2に関する設定
まずconfを作る。
> vi /usr/lib64/sasl2/smtpd.conf
#pwcheck_method: saslauthd
pwcheck_method: auxprop
mech_list: plain login
■バーチャルドメイン用のアカウント作成
> saslpasswd2 -c -u myhostname username
あ!間違ったって時は以下で削除
> saslpasswd2 -d -u myhostname username
確認は
> sasldblistusers2
info@kapi.jp: userPassword
info@postfix.kapi.jp: userPassword
■/etc/sasldb2
saslpasswd2でユーザーを作ると/etc/sasldb2が出来る
postfixで使いたいので/etc/sasldb2の仲間に入れてもらう
> chgrp postfix /etc/sasldb2
仲間に入れてもらっても見るだけにしてもらう。
> chmod 640 /etc/sasldb2
こうしとく。
> ls -la sasldb2
-rw-r----- 1 root postfix 12288 Feb 16 10:53 sasldb2
saslの設定に関してはここ詳しい
Postfix + SMTP-AUTH2(SASL2)
※この時点でローカルPCのメーラーから送信できるか確認する。
dovecotのインストール
dovecotはyumとかよりソースからの方がやりやすい感があり、今回はソースからやった。
予めdoevecotが入ってる場合、確認して、消しておく。
> tar zxvf dovecot-1.1.2.tar.gz
> cd dovecot-1.1.2
> ./configure --prefix=/opt/apps/dovecot-1.1.3
> make
> make install
dovecotユーザーとグループ作っとく。
> groupadd -g 97 dovecot
> useradd -u 97 -g 97 -d /usr/libexec/dovecot -s /sbin/nologin dovecot
dovecot.confの設定上記のprefixだと/opt/apps/dovecot-1.1.3/etc/下にdovecot.confを用意し修正する。
dovecot.conf
## Dovecot configuration file
protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
ssl_disable = yes
login_user = dovecot
mail_location = maildir:/var/mail/vhosts/%d/%n/Maildir
auth_debug = yes
auth_debug_passwords = yes
mail_debug = yes
protocol imap {
}
protocol lda {
postmaster_address = postmaster@example.com
}
auth default {
mechanisms = plain
passdb passwd-file {
args = /opt/apps/dovecot-1.1.3/etc/dovecot-passwd
}
userdb passwd-file {
args = /opt/apps/dovecot-1.1.3/etc/dovecot-passwd
}
user = root
}
mail_location = maildir:/var/mail/vhosts/%d/%n/Maildir
の書き方に注意が必要。
パスワードファイルの作成
vi dovecot-passwd
info@kapi.jp:{plain}パスワード:5000:5000::/var/mail/vhosts/kapi.jp/info
info@postfix.kapi.jp:{plain}パスワード:5000:5000::/var/mail/vhosts/postfix.kapi.jp/info
後は起動し、接続テスト。
後、設定OKだったらこれやっとくべき。
↓
http://www.abuse.net/relay.htm
Address to test:にドメイン入れて不正中継テスト。
いやぁ~、メールサーバはここまでたどり着くのにかなり苦労した。
↓の参考URLの多さが物語るです。
トラブルシューティング
fatal: no SASL authentication mechanisms
cyrus-sasl-develとかが入ってなくない?
password supplied for is incorrect
単純にIDパスが違う、smtpauthなのにそうなってない、dovecotの設定がおかしい等。
warning: maildir access problem for UID/GID=****/***: create maildir file /(vboxのパス): Permission denied
メール送信時に上記のメールが返ってきて、且つパーミッション設定に間違いが無い場合、作成したvboxユーザーのuidかgidが違っている可能性がある。
2度セットアップをしてしまったサーバ等でrpmやyumを使って行ってると、ユーザーの削除>作成を行っているので、そういうことになるのかも。。。
その場合、
chown (設定したいuid):(設定したいgid) /(vboxのパス)
をやって、IDで合わせてやると解決した。
参考URL
http://kapi.jp/kapi_blog/214
2009年02月17日
関連カテゴリ Linux Unix