CentOS メールサーバー構築 (Postfix, Dovecot)
CentOSにメールサーバーを構築します。
メールサーバーには、送信サーバー(SMTP)と受信サーバー(POP/IMAP)がありそれぞれにソフトをインストールし、設定をしていきます。
送信サーバー(SMTP)・・・「Postfix」
受信サーバー(POP/IMAP)・・・「Dovecot」
また、メールの不正中継の防止のために、SMTP-Authの機能も設定します。
Postfix のインストールと設定
Postfixのインストール
Postfixインストールをします。
root で行います。
# yum -y install postfix |
Postfixの設定
Postfixの設定をします。
root で行います。
# vi /etc/postfix/main.cf |
編集する部分が下記になります。
ホスト名を設定 myhostname = user.sanakoro.com ドメイン名を設定 mydomain = sanakoro.com メールアドレス@以降にドメイン名をつける 待ち受けるネットワークインターフェイス設定 メールを受信するドメイン名を設定 自分のネットワークを設定 メールボックスを Maildir 形式に設定 メールサーバーソフト名を隠す 以下を追記 SMTP-Auth を有効化 認証するためのドメイン名を設定 メールの受信者を制限する設定 |
SMTP-Authの設定
# vi /etc/sasl2/smtpd.conf |
既存ユーザー(Linuxユーザー)のパスワードを使う場合
pwcheck_method: saslauthd
既存ユーザーパスワードとは別のSMTP-Authパスワードを設定して使う場合
pwcheck_method: auxprop
どちらのパスワードも使う場合
pwcheck_method: saslauthd auxprop
pwcheck_method: saslauthd または pwcheck_method: auxprop または pwcheck_method: saslauthd auxprop mech_list: plain login |
cyrus-saslをインストールします。
# yum -y install cyrus-sasl cyrus-sasl-plain |
saslauthdの起動設定をします。
CentOS 6 の場合
saslauthdを起動します。
# service saslauthd start |
saslauthdの自動起動設定をします。
# chkconfig saslauthd on |
自動起動設定を確認します。
# chkconfig –list saslauthd saslauthd 0 : off 1 : off 2 : on 3 : on 4 : on 5 : on 6 : off |
CentOS 7 の場合
saslauthdを起動します。
#systemctl start saslauthd |
saslauthdの自動起動設定をします。
#systemctl enable saslauthd |
自動起動設定を確認します。
#systemctl is-enabled saslauthd enabled |
メールボックス(Maildir形式)の設定
メールボックス(Maildir形式)の設定をします。
メールボックスのディレクトリを作成します。
# mkdir -p /etc/skel/Maildir/{new,cur,tmp} |
※新規ユーザー追加時に自動でホームディレクトリにMaildir形式のメールボックスが作成されます。
ディレクトリが作成されたか確認します。
[root@localhost user]# ll /etc/skel/Maildir 合計 12 drwxr-xr-x 2 root root 4096 6月 24 21:58 2018 cur drwxr-xr-x 2 root root 4096 6月 24 21:58 2018 new drwxr-xr-x 2 root root 4096 6月 24 21:58 2018 tmp |
ディレクトリにパーミッションを設定します。
# chmod -R 700 /etc/skel/Maildir/ |
Postfixはデフォルトで起動しているので、再起動します。
CentOS 6 の場合
# service postfix restart |
CentOS7 の場合
#systemctl restart postfix |
Dovcotのインストールと設定
Dovecotのインストール
Dovecotをインストールします。
# yum -y install dovecot |
Dovecotの設定
# vi /etc/dovecot/conf.d/10-mail.conf |
25行目辺りにある「mail_location」の部分を以下のようにします。
mail_location = maildir:~/Maildir
# vi /etc/dovecot /conf.d/10-auth.conf |
10行目あたりにある「disable_plaintext_auth」の部分を以下のようにします。
disable_plaintext_auth = no
CentOS 6 の場合
Dovecotを起動します。
# service dovecot start |
Dovecotの自動起動設定をします。
# chkconfig dovecot on |
自動起動設定を確認します。
# chkconfig –list dovecot dovecot 0 : off 1 : off 2 : on 3 : on 4 : on 5 : on 6 : off |
CentOS 7 の場合
Dovecotを起動します。
#systemctl start dovecot |
Dovecotの自動起動設定をします。
#systemctl enable dovecot |
自動起動設定を確認します。
#systemctl is-enabled dovecot enabled |
メールユーザー追加
メールユーザーを作成します。(メールアドレス user@sanakoro.com を追加します。)
# useradd user ← SSHによるリモート接続できるようにする場合 または # useradd -s /sbin/nologin user ← SSHによるリモート接続できないようにする場合# passwd usr ユーザー testuser のパスワードを変更。 新しいパスワード: 新しいパスワードを再入力してください: passwd: 全ての認証トークンが正しく更新できました。 |
作成したユーザーのホームディレクトリにMaildirディレクトリができているか確認します。
# cd /home/user # ls |
SMTP-Authユーザパスワードの設定
既存ユーザー(linuxユーザー)のパスワードとSMTP-Authパスワードを別にする場合の設定をします。
# saslpasswd2 -u sanakoro.com -c user Password: Again (for verification) |
パスワードは2回入力します.
設定内容を確認します。
# sasldblistusers2 user@sanakoro.com: userPassword |
※パスワードを変更する場合
# saslpasswd2 -u sanakoro.com user
※設定を削除する場合
# saslpasswd2 -u sanakoro.com -d user
設定は「/etc/sasldb2」ファイルに保存されます。
このファイルをのパーミッションとグループを設定します。
パーミッション変更
# chmod 640 /etc/sasldb2 |
グループ変更
# chgrp postfix /etc/sasldb2 |
sasldb2の確認
# ll /etc/sasldb2 |
これで、PostfixとDovecotの設定は完了です。
あとは、メールソフトなどでメール設定を行ってください。
※gmaiやhotmailなどに向けて送信した場合は、送信先の迷惑メールボックスに受信されていることがあります。
以上で、メールサーバーの構築は完了です。