CentOS5系にdovecot2をインストール MySQL,Postfix,

CentOS5系にdovecot2をインストール MySQL,Postfix,

スマートフォンでpush通知出来るようにIMAP-IDLE対応のdovecot2をインストールする。

基本的には メールサーバ構築のまとめ(複数のバーチャルドメイン+Postfix+MySQL+Dovecot+procmail+Clam AntiVirus+spamassassin+postfixadmin) のdovecotの部分をdovecot2にするための記事。

ATrpmsリポジトリを追加

yumでインストールできるようにするため、ATrpmsリポジトリを追加する。

# vi /etc/yum.repos.d/atrpms.repo

[atrpms]
name=Redhat Enterprise Linux $releasever - $basearch - ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
enabled=0
gpgcheck=1
gpgkey=http://atrpms.net/RPM-GPG-KEY.atrpms

dovecot 2のインストール(アップデート)

# yum install dovecot --enablerepo=atrpms

Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * centosplus: www.ftp.ne.jp
 * epel: ftp.kddilabs.jp
 * extras: www.ftp.ne.jp
 * rpmforge: ftp.riken.jp
 * updates: www.ftp.ne.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dovecot.i386 1:2.1.1-2_132.el5 set to be updated
--> Processing Dependency: libpq.so.5 for package: dovecot
--> Running transaction check
---> Package postgresql84-libs.i386 0:8.4.13-1.el5_8 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                 Arch       Version                  Repository    Size
================================================================================
Updating:
 dovecot                 i386       1:2.1.1-2_132.el5        atrpms       2.5 M
Installing for dependencies:
 postgresql84-libs       i386       8.4.13-1.el5_8           base         213 k

Transaction Summary
================================================================================
Install       1 Package(s)
Upgrade       1 Package(s)

Total download size: 2.7 M
Is this ok [y/N]: y

... 

Running Transaction
  Installing     : postgresql84-libs                                        1/3 
  Updating       : dovecot                                                  2/3 
  Cleanup        : dovecot                                                  3/3 
warning: /etc/dovecot.conf saved as /etc/dovecot.conf.rpmsave

Dependency Installed:
  postgresql84-libs.i386 0:8.4.13-1.el5_8                                       

Updated:
  dovecot.i386 1:2.1.1-2_132.el5                                                

Complete!

設定ファイルの編集

アップデートした場合、設定ファイルはに変更があるのでスクリプトがあるみたいだけど最初から設定することにする。
http://wiki2.dovecot.org/Upgrading

dovecot2では設定ファイルの書式が変わり、諸々の設定は conf.d/以下に置かれている。

dovecot.confを編集
・ オリジナルをコピーしておく
# cd /etc/dovecot
# cp -a dovecot.conf dovecot.conf.org

・ dovecot.confを編集
# vi /etc/dovecot/dovecot.conf

# Protocols we want to be serving.
#protocols = imap pop3 lmtp
protocols = imap pop3 ←追記

master.conf
# cd /etc/dovecot/conf.d/

# vi /etc/dovecot/conf.d/10-master.conf

service imap-login {
  inet_listener imap {
    port = 143 ←コメント削除
  }
  inet_listener imaps {
    port = 993 ←コメント削除
    ssl = yes ←コメント削除
  }

...

service pop3-login {
  inet_listener pop3 {
    port = 110  ←コメント削除
  }
  inet_listener pop3s {
    port = 995  ←コメント削除
    ssl = yes  ←コメント削除
  }
}

....

service auth {

  unix_listener auth-userdb {
    #mode = 0666
    #user = 
    #group = 
  }

  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {  ←コメント削除
    # mode = 0666
    mode = 0660      ←追記
    user = postfix   ←追記
    group = postfix  ←追記
  }                  ←コメント削除

  # Auth process is run as this user.
  #user = $default_internal_user
}
10-mail.conf
# vi /etc/dovecot/conf.d/10-mail.conf

# See doc/wiki/Variables.txt for full list. Some examples:
#
#   mail_location = maildir:~/Maildir
#   mail_location = mbox:~/mail:INBOX=/var/mail/%u
#   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#mail_location = 
mail_location = maildir:/mail/%d/%u  ← 追記

...


# Valid UID range for users, defaults to 500 and above. This is mostly
# to make sure that users can't log in as daemons or other system users.
# Note that denying root logins is hardcoded to dovecot binary and can't
# be done even if first_valid_uid is set to 0.
#first_valid_uid = 500
#last_valid_uid = 0
first_valid_uid = 10000  ← 追記

# Valid GID range for users, defaults to non-root/wheel. Users having
# non-valid GID as primary group ID aren't allowed to log in. If user
# belongs to supplementary groups with non-valid GIDs, those groups are
# not set.
#first_valid_gid = 1
#last_valid_gid = 0
first_valid_gid = 10000  ← 追記

10-auth.conf
# vi /etc/dovecot/conf.d/10-auth.conf

# Space separated list of wanted authentication mechanisms:
#   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
#   gss-spnego
# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login digest-md5 cram-md5  ←追加

....

#!include auth-deny.conf.ext
#!include auth-master.conf.ext

!include auth-system.conf.ext
!include auth-sql.conf.ext         ←コメント削除
#!include auth-ldap.conf.ext
#!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext
10-ssl.conf
# vi /etc/dovecot/conf.d/10-ssl.conf

#ssl_cert = 

MySQLを使うための設定

※自分はunixユーザでメールを使わないので下記設定で問題ないが、以前頂いたコメントによると問題がある模様。参考まで。

auth-mysql.conf.ext を新規作成
# vi /etc/dovecot/conf.d/auth-mysql.conf.ext 

driver = mysql
default_pass_scheme = PLAIN
connect = dbname=postfix host=localhost user=postfix password=passwd
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'
user_query = SELECT concat('/mail/', maildir) as home, 10000 as uid, 10000 as gid FROM mailbox WHERE username = '%u' AND active = '1'
auth-sql.conf.extを修正
# vi /etc/dovecot/conf.d/auth-sql.conf.ext

passdb {
  driver = sql

  # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
  #args = /etc/dovecot/dovecot-sql.conf.ext
  args = /etc/dovecot/conf.d/auth-mysql.conf.ext  ←追記
}

...

userdb {
  driver = sql
  #args = /etc/dovecot/dovecot-sql.conf.ext
  args = /etc/dovecot/conf.d/auth-mysql.conf.ext  ←追記
}

参考

  • CentOS で EPEL や ATrpms のパッケージを yum で利用できるようにする
  • Dovecot2.x/設定
  • Postfix + Dovecot 2 + PostfixAdmin + MySQL [がらくたネット]