IMAP4 構築ログ
IMAPサーバが 64bit + IPv6 環境で動作するかの検証です
IMAPサーバの有名な実装は以下 4つありますが今回 Dovecot を導入してみたので紹介します
Cyrus-IMAP | Courier-IMAP | UW | Dovecot | |
---|---|---|---|---|
メール保存形式 | 独自形式 | Maildir | mbox可能 Maildir不可 その他多数の形式に対応 |
mbox Maildir |
通信方式 | IPv4/IPv6 | IPv4/IPv6 | 別途 inetd/xinetd 必要 | IPv4/IPv6 |
vpopmail | 不可 | 不可 | 不可 | 可 |
DB認証 LDAP,MySQL,PostgreSQL |
対応 | 対応 | 非対応 | 対応 |
まず Cyrus-IMAP と UW は Maildir形式に対応していないため Postfixと相性が悪そうです
Courier-IMAPは 今まで使えていて不満もありませんでしたが
今回新しい実装ということで mbox形式にも対応している Dovecot を試すことにしました
また近い将来 インターネット経由でIMAPを利用することを考えて下記 セキュリティを重視します
- imapsプロトコルで SSL利用
- アカウント管理を LDAPで行い UNIXパスワードと別パスワードを使う
CPU | PhenomII X4 905e (2.5GHz 4コア) |
---|---|
マザーボード | GA-880GM-USB3 |
メモリ | 16GB (DDR3-1066) |
イーサネット | Realtek8111D (R8168 GbE) |
Linuxカーネルバージョン | 3.0.0 (x86_64) |
GCC | 4.5.2 |
glibc | 2.13.1 |
Linux-PAM | 1.1.3 |
OpenSSL | 1.0.0d |
LDAP | 2.4.23 |
PostgreSQL | 9.1.0 |
MySQL | 5.5.15 |
Postfix | 2.8.4 |
Dovecot | 2.0.17 |
インストール
ソースコードからのインストール手順は下記の通りです
Dovecotダウンロードサイトから最新のソースコードを取得します
$ tar -xzf dovecot-2.0.17.tar.gz
$ cd dovecot-2.0.17
$ ./configure --prefix=/usr --localstatedir=/var --with-ssldir=/usr/etc/ssl --with-ldap=yes --with-pgsql --with-mysql
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
〜
Install prefix . : /usr
File offsets ... : 64bit
I/O polling .... : epoll
I/O notifys .... : inotify
SSL ............ : yes (OpenSSL)
GSSAPI ......... : no
passdbs ........ : static passwd passwd-file shadow pam checkpassword ldap sql
: -bsdauth -sia -vpopmail
userdbs ........ : static prefetch passwd passwd-file checkpassword ldap sql nss
: -vpopmail
SQL drivers .... : pgsql mysql
: -sqlite
$ make
make all-recursive
make[1]: ディレクトリ `/home/admin/dovecot-2.0.17' に入ります
Making all in .
〜
make[3]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます
make[2]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます
make[1]: ディレクトリ `/home/admin/dovecot-2.0.17' から出ます
$ su
# make install
Making install in .
make[1]: ディレクトリ `/home/admin/dovecot-2.0.17' に入ります
/bin/sh ./update-version.sh . .
〜
make[3]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます
make[2]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます
make[1]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます
#
$ tar -xzf dovecot-2.0.17.tar.gz $ cd dovecot-2.0.17 $ ./configure --prefix=/usr --localstatedir=/var --with-ssldir=/usr/etc/ssl --with-ldap=yes --with-pgsql --with-mysql checking for a BSD-compatible install... /bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk 〜 Install prefix . : /usr File offsets ... : 64bit I/O polling .... : epoll I/O notifys .... : inotify SSL ............ : yes (OpenSSL) GSSAPI ......... : no passdbs ........ : static passwd passwd-file shadow pam checkpassword ldap sql : -bsdauth -sia -vpopmail userdbs ........ : static prefetch passwd passwd-file checkpassword ldap sql nss : -vpopmail SQL drivers .... : pgsql mysql : -sqlite $ make make all-recursive make[1]: ディレクトリ `/home/admin/dovecot-2.0.17' に入ります Making all in . 〜 make[3]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます make[2]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます make[1]: ディレクトリ `/home/admin/dovecot-2.0.17' から出ます $ su # make install Making install in . make[1]: ディレクトリ `/home/admin/dovecot-2.0.17' に入ります /bin/sh ./update-version.sh . . 〜 make[3]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます make[2]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます make[1]: ディレクトリ `/home/admin/dovecot-2.0.17/doc' から出ます #
DBでアカウント管理も可能です
OpenLDAP PostgreSQL MySQL はインストール済なので
–with-ldap –with-pgsql –with-mysql を付けています
(今回は LDAPのみ使います)
/usr/bin/ 配下には doveadm doveconf dsync コマンドが
/usr/sbin/ 配下には dovecot デーモンがインストールされます
次に サーバの設定ファイルを記述します
いずれもサンプルがあるので まずサンプルをコピーしてから必要な編集を行います
# cp -r /usr/share/doc/dovecot/example-config/* /usr/etc/dovecot/ # ls -R /usr/etc/dovecot/ /usr/etc/dovecot/: README dovecot-db.conf.ext dovecot-ldap.conf.ext dovecot.conf conf.d dovecot-dict-sql.conf.ext dovecot-sql.conf.ext /usr/etc/dovecot/conf.d: 10-auth.conf 20-lmtp.conf auth-master.conf.ext 10-director.conf 20-pop3.conf auth-passwdfile.conf.ext 10-logging.conf 90-acl.conf auth-sql.conf.ext 10-mail.conf 90-plugin.conf auth-static.conf.ext 10-master.conf 90-quota.conf auth-system.conf.ext 10-ssl.conf auth-checkpassword.conf.ext auth-vpopmail.conf.ext 15-lda.conf auth-deny.conf.ext 20-imap.conf auth-ldap.conf.ext #
dovecot.conf がメインで それ以外の設定ファイルは
dovecot.conf からインクルードされている構成です
まずは dovecot.conf から
(編集した行のみ記載します) protocols = imaps pop3s listen = ::
protocols には IMAPs POP3s のみを指定しました SSLの設定は後述します
listen には :: を指定しIPv6のみとしましたが 通常は IPv4も可能となる *, :: で指定します
次は dovecot-ldap.conf.ext です LDAPアカウント管理が必要な場合編集します
(編集した行のみ記載します) hosts = ::1 dn = cn=Manager,dc=mydomain dnpass = パスワード base = ou=People,dc=local pass_attrs = uid=user,userPassword=password,uidNumber=uid,gidNumber=gid,homeDirectory=home,mailDirectory=mail
hosts は LDAPサーバのホストを指定します
dn dnpass base はそれぞれ検索に使う LDAPアカウント パスワード 検索ベース位置 の指定です
pass_attrs の設定が重要です 1回のLDAP検索で uid gid home mail 情報も取る設定にします
LDAP自体の設定とアカウント情報の投入方法については後述します
conf.d/10-auth.conf の設定です
(編集した行のみ記載します) disable_plaintext_auth = no #!include auth-system.conf.ext !include auth-ldap.conf.ext
プレインテキストを許可しているのは プロトコルが暗号化される imaps pop3s だからです
また !include の行を修正して 利用したい auth-ldap.conf.ext のみを有効化します
conf.d/10-mail.conf の設定です
(編集した行のみ記載します) mail_location = maildir:~/Maildir
ここで Maildir形式を指定しています
ひとまず Dovecot本体のインストールと設定は以上です
SSL証明書の作成
IMAPs と POP3s に必要な SSL証明書を作成します
Dovecotのソースコードに mkcert.sh スクリプトが付属しているのでそれを利用します
まずは 設定ファイル /usr/etc/dovecot/dovecot-openssl.cnf を下記のように作成します
[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_distinguished_name
x509_extensions = cert_type
prompt = no
[ req_distinguished_name ]
countryName = JP
stateOrProvinceName = Tokyo
localityName = Test-ku
0.organizationName = Test Coporation
organizationalUnitName = Test Section
commonName = phenom.mydomain
emailAddress = postmaster.mydomain
[ cert_type ]
nsCertType = server
[ req ] default_bits = 1024 encrypt_key = yes distinguished_name = req_distinguished_name x509_extensions = cert_type prompt = no [ req_distinguished_name ] countryName = JP stateOrProvinceName = Tokyo localityName = Test-ku 0.organizationName = Test Coporation organizationalUnitName = Test Section commonName = phenom.mydomain emailAddress = postmaster.mydomain [ cert_type ] nsCertType = server
mkcert.shを実行します
# cd /usr/etc/dovecot # SSLDIR=/usr/etc/ssl sh ~admin/dovecot-2.0.17/doc/mkcert.sh Generating a 1024 bit RSA private key .................................................++++++ .............................++++++ writing new private key to '/usr/etc/ssl/private/dovecot.pem' ----- subject= /C=JP/ST=Tokyo/L=Test-ku/O=Test Coporation/OU=Test Section/CN=phenom.mydomain/emailAddress=postmaster.mydomain SHA1 Fingerprint=41:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:80 #
LDAPアカウント設定
arinux (参考サイト)を参考にしました
http://sourceforge.jp/projects/postldapadmin/ から postLDAPadmin_admin パッケージを取得します
このパッケージ 元々 Postfix用の LDAPアカウント管理ツールですが
中に含まれる postLDAPadmin.schema だけを拝借します
# tar --strip-components=1 -xzf postLDAPadmin_admin-2.20.tar.gz postldapadmin/postLDAPadmin.schema
# mv postLDAPadmin.schema /usr/etc/openldap/schema/
# tar --strip-components=1 -xzf postLDAPadmin_admin-2.20.tar.gz postldapadmin/postLDAPadmin.schema # mv postLDAPadmin.schema /usr/etc/openldap/schema/
また slapd.conf に postLDAPadmin.schema を読み込む指定
ldap.conf には認証に利用する ou の指定が必要です
/usr/etc/openldap/slapd.conf の追加設定行
include /usr/etc/openldap/schema/postLDAPadmin.schema
/usr/etc/openldap/ldap.conf の追加設定行
# # nsswitch # nss_base_passwd ou=People,dc=mydomain?one nss_base_group ou=Group,dc=mydomain?one
OpenLDAPを再起動後 早速アカウントを登録していきますが
現在のデータの登録状況を確認します
OpenLDAPのインストールと基本データの登録は OpenLDAPのインストール で行ったので
# ldapsearch -x -b 'dc=mydomain' -D 'cn=Manager,dc=mydomain' -LLL -W Enter LDAP Password: dn: dc=mydomain objectClass: dcObject objectClass: organization dc: mydomain o: mydomain dn: ou=People,dc=mydomain objectClass: organizationalUnit ou: People dn: ou=Group,dc=mydomain objectClass: organizationalUnit ou: Group #
となっており ou=People と ou=Group まで作られています
今回 メール関連の登録情報はアカウント登録情報に統合する形で People 内に登録します
# ldapadd -a -x -D 'cn=Manager,dc=mydomain' -W Enter LDAP Password: dn: cn=users,ou=Group,dc=local gidNumber: 100 objectClass: top objectClass: posixGroup cn: users adding new entry "cn=users,ou=Group,dc=mydomain" dn: uid=imaptest,ou=People,dc=mydomain objectClass: top objectClass: posixAccount objectClass: account objectClass: postLdapAdmin uid: imaptest cn: for IMAP uidNumber: 500 gidNumber: 100 homeDirectory: /home/admin loginShell: /usr/bin/bash userPassword: (パスワードを設定) gecos: admin mailbox mail: admin@mydomain mailDirectory: /home/admin/Maildir/ adding new entry "cn=imaptest,ou=People,dc=mydomain" Ctrl+D を入力 #
下線箇所が objectClass: postLdapAdmin に関するメールアカウント設定で
それ以外の箇所が通常の LDAPアカウント登録情報です
ここでは imaptestというアカウント名と個別のパスワードを登録しました
実体(メールボックス)は 別の既存UNIXアカウントです
実際は メールアカウント名とUNIXアカウント名を一致させたほうが
運用上の紛らわしさが少ないでしょう
その他設定
あとは /etc/services に下記設定があることを確認するくらいです
imaps 993/tcp # IMAP over SSL
imaps 993/udp # IMAP over SSL
pop3s 995/tcp # POP-3 over SSL
pop3s 995/udp # POP-3 over SSL
imaps 993/tcp # IMAP over SSL imaps 993/udp # IMAP over SSL pop3s 995/tcp # POP-3 over SSL pop3s 995/udp # POP-3 over SSL
運用
サービスの開始と起動は単純で
dovecotプログラムを実行したり stop引数を付けて停止させるだけです
dovecotを起動した後の 確認としてはTCPポート番号が開いているかの確認と
$ netstat -a
〜
tcp6 0 0 [::]:imaps [::]:* LISTEN
tcp6 0 0 [::]:pop3s [::]:* LISTEN
〜
〜
$
$ netstat -a 〜 tcp6 0 0 [::]:imaps [::]:* LISTEN tcp6 0 0 [::]:pop3s [::]:* LISTEN 〜 〜 $
プロセスでも確認できます
$ ps aux | grep dovecot root 3532 0.0 0.0 23580 876 ? Ss 01:55 0:00 /usr/sbin/dovecot mail 3544 0.0 0.0 15116 1024 ? S 01:55 0:00 dovecot/anvil root 3545 0.0 0.0 15240 1016 ? S 01:55 0:00 dovecot/log root 3555 0.0 0.0 25896 3516 ? S 01:55 0:00 dovecot/config mail 4537 0.0 0.0 23732 2752 ? S 02:12 0:00 dovecot/imap-login admin 4538 0.0 0.0 18944 2588 ? S 02:12 0:00 dovecot/imap mail 9178 0.0 0.0 69656 4040 ? S 10:13 0:00 dovecot/auth root 9179 0.0 0.0 21316 1404 ? S 10:13 0:00 dovecot/ssl-params $
プログラムは 1つだけでしたが プロセスとしては複数起動しています
admin (一般ユーザ権限) で dovecot/imap が起動しているのは
メーラーから実際にクライアント接続しているためです
メーラーである Sylpheed (Linux版) の設定画面です
pop3sで Dovecotへの正常接続が確認できました
サーバ指定は IPv6アドレスを指定していますが
IPv6 DNS環境があれば IPv6ホスト名でもつながります
pop3s を利用しているので SSLタブの設定で
「SSLを使用」にチェックが必要です
Sylpheed(Windows8版) の動作画面です 問題なく動作しました
Thunderbird (Windows版) でも動作確認できました
「サーバ名」に IPv6ホスト名を指定する必要があり IPv6アドレスは不可でした
そのため Thunderbirdを使うには IPv6 DNS環境が必須なので注意が必要です
Windows Vistaに標準搭載の Windowsメールです 手軽にメールやニュースをやり取りできます
これも IPv6の設定で問題なくメールが使えました