ソフトウェアとハードウェアの境界

ホビー開発に関する誰得情報満載☆

バーチャルホストのメールサーバ②

英語がまぁ上達しない

前回の記事の見出しは、イキって英語で書いてみたのだが、意味合いがちゃんと伝わる文章になっているのか不安だ。
ボクは英辞郎第六版を購入し、PDICを使って英文をなんとか読んでいる。
この業界にいるからには、技術的な文書に関してはリーディングくらいできるようになりたいのだが、まぁ上達しない。
普段使っている英語は「イッツハプニーング」くらいのものだ。
ゆくゆくは「ザッツラーイト」や「ハーイ、クリストファー」も言うようにしたい。

Postfix & Dovecot

PostfixDovecot、その他のデーモン間の関係

http://www.xenlens.com/assets/mailserver_diagram1.png
Debian Wheezy Mail Server – Postfix Dovecot Sasl MySQL PostfixAdmin RoundCube SpamAssassin Clamav Greylist Nginx PHP5 | XenLens
より抜粋

わかりやすい図だとは言わないが、概ね関連が分かる。
より詳細に知りたい場合は元記事も読んでみよう。

前回から続き

tokixy56.hatenablog.com

MariaDBにユーザとデータベースを作成

ユーザ作成
$ mysql -u root -p
Enter password:[password]
...
MariaDB [(none)]> create user 'postfix'@'localhost' identified by [PASSWORD] 'パスワード';
MariaDB [(none)]> create database postfix;
MariaDB [(none)]> grant all privileges on postfix.* to 'postfix'@'localhost';
MariaDB [(none)]> exit

Postfixの設定ファイル(MariaDBへのクエリ設定ファイル)

/etc/postfix/sql/mysql_virtual_domains_maps.cf
user = postfix
password = パスワード
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and active = '1'
/etc/postfix/sql/mysql_virtual_mailbox_maps.cf
user = postfix
user = postfix
password = パスワード
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
/etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf
user = postfix
password = パスワード
hosts = localhost
dbname = postfix
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
/etc/postfix/sql/mysql_virtual_alias_maps.cf
user = postfix
password = パスワード
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf
user = postfix
password = パスワード
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
user = postfix
password = パスワード
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
#handles catch-all settings of target-domain
user = postfix
password = パスワード
hosts = localhost
dbname = postfix
query  = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'

プライベートSSL証明書の作成

SSL証明書作成

詳細は、他の記事参照のこと。

$ openssl genrsa 2048 > mail.key
Generating RSA private key, 2048 bit long modulus
..................................................+++
.................................................+++
e is 65537 (0x10001)

$ openssl req -new -key mail.key > mail.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
#必須項目のみ入力
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:[県名]
Locality Name (eg, city) [Default City]:[市町村]
Organization Name (eg, company) [Default Company Ltd]:[会社名]
Organizational Unit Name (eg, section) []:[部署名]
Common Name (eg, your name or your server's' hostname) []:[ドメイン名]
Email Address []:[メールアドレス]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:[Enter]
An optional company name []:[Enter]

$ openssl x509 -days 3650 -req -signkey mail.key < mail.csr > mail.crt
Signature ok
subject=/C=JP/ST=Ken/L=City-Shi/O=DefaultCompany.Ltd/OU=Engineer/CN=example.com/emailAddress=example@example.com
Getting Private key

$ sudo mv /etc/postfix/mail.crt

$ sudo mv /etc/postfix/mail.key

次回

Dovecotの設定ファイル及び、必須ユーザの作成とディレクトリ、ファイルのパーミッションの変更について記す。
4つの記事くらいに分割しちゃうなぁ…。
メール設定恐ろしや。