このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
01_linux:03_mail:04_postfix_mysql_postfix_admin [2016/09/15 01:52] – matsui | 01_linux:03_mail:04_postfix_mysql_postfix_admin [2016/12/08 03:25] (現在) – matsui | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 04 Postfix+MySQL+Postfix AdminでバーチャルSMTPサーバの構築 ====== | ||
+ | ===== 1. MySQL ===== | ||
+ | |||
+ | === インストール === | ||
+ | |||
+ | < | ||
+ | # yum install mysql-server | ||
+ | # chkconfig mysqld on | ||
+ | # service mysqld start | ||
+ | </ | ||
+ | |||
+ | === Postfix用のデータベース作成 === | ||
+ | < | ||
+ | # mysql | ||
+ | mysql> create database postfix; | ||
+ | mysql> grant all privileges on postfix.* to postfix@localhost identified by ' | ||
+ | </ | ||
+ | |||
+ | ===== 2. Postfix ===== | ||
+ | <color blue> | ||
+ | |||
+ | === インストール === | ||
+ | |||
+ | < | ||
+ | # cd / | ||
+ | # wget http:// | ||
+ | # mkdir -p / | ||
+ | # rpm -ivh postfix-2.3.3-2.1.el5_2.src.rpm | ||
+ | # cd / | ||
+ | # wget http:// | ||
+ | # gunzip postfix-2.3.3-vda.patch.gz | ||
+ | # wget http:// | ||
+ | # cd / | ||
+ | # cp postfix.spec postfix.spec.old | ||
+ | # vi postfix.spec | ||
+ | ------- 変更と追加 ------- | ||
+ | 2 %define MYSQL 0 | ||
+ | | ||
+ | 2 %define MYSQL 1 | ||
+ | |||
+ | 84 Patch11: postfix-2.3.3-vda.patch | ||
+ | 85 Patch12: postfix-sleep.patch | ||
+ | |||
+ | 141 %patch11 -p1 -b .vda | ||
+ | 142 %patch12 -p1 -b .sleep | ||
+ | |||
+ | # yum -y install pkgconfig rpm-build db4-devel zlib-devel openldap-devel cyrus-sasl-devel pcre-devel mysql-devel openssl-devel | ||
+ | # mkdir -p / | ||
+ | # mkdir -p / | ||
+ | # mkdir -p / | ||
+ | # rpmbuild -ba postfix.spec | ||
+ | |||
+ | #rpm -Uhv / | ||
+ | </ | ||
+ | |||
+ | === yumの設定でpostfixを除外しておく === | ||
+ | < | ||
+ | # vi / | ||
+ | --------- 最後に追加 ------------- | ||
+ | exclude=postfix* | ||
+ | </ | ||
+ | |||
+ | === chkconfig === | ||
+ | |||
+ | < | ||
+ | # chkconfig postfix on | ||
+ | </ | ||
+ | |||
+ | === main.cfの作成 === | ||
+ | |||
+ | < | ||
+ | # vi / | ||
+ | 70 myhostname = test.flateight.com | ||
+ | 92 myorigin = $myhostname | ||
+ | 107 # | ||
+ | 109 inet_interfaces = $myhostname, | ||
+ | 155 # | ||
+ | 158 mydestination = | ||
+ | 288 relay_domains = $mydestination | ||
+ | 256 mynetworks = 168.100.189.0/ | ||
+ | 411 home_mailbox = Maildir/ | ||
+ | 563 smtpd_banner = $myhostname ESMTP unknown | ||
+ | 637 sendmail_path = / | ||
+ | |||
+ | ---------- 追加 ---------- | ||
+ | smtpd_sasl_auth_enable = yes | ||
+ | smtpd_sasl_type = dovecot | ||
+ | smtpd_sasl_path = private/ | ||
+ | smtpd_sasl_local_domain = $myhostname | ||
+ | smtpd_recipient_restrictions = | ||
+ | permit_mynetworks | ||
+ | permit_sasl_authenticated | ||
+ | reject_unauth_destination | ||
+ | |||
+ | message_size_limit = 10485760 | ||
+ | |||
+ | smtpd_use_tls = yes | ||
+ | smtpd_tls_cert_file = / | ||
+ | smtpd_tls_key_file = / | ||
+ | smtpd_tls_session_cache_database = btree:/ | ||
+ | tls_daemon_random_source = dev:/ | ||
+ | |||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | local_transport = virtual | ||
+ | virtual_transport = virtual | ||
+ | virtual_mailbox_base = / | ||
+ | virtual_alias_maps = mysql:/ | ||
+ | virtual_alias_domains = $virtual_alias_maps | ||
+ | virtual_mailbox_domains = mysql:/ | ||
+ | virtual_mailbox_maps = mysql:/ | ||
+ | virtual_minimum_uid = 10000 | ||
+ | virtual_uid_maps = static: | ||
+ | |||
+ | virtual_gid_maps = static: | ||
+ | mailbox_size_limit = 51200000 | ||
+ | message_size_limit = 10240000 | ||
+ | virtual_mailbox_limit = 51200000 | ||
+ | virtual_mailbox_limit_maps = hash:/ | ||
+ | virtual_mailbox_limit_override = yes | ||
+ | virtual_overquota_bounce = yes | ||
+ | virtual_mailbox_limit_inbox = yes | ||
+ | </ | ||
+ | |||
+ | === procmailを利用する場合 === | ||
+ | |||
+ | [[01_linux: | ||
+ | |||
+ | === vquotaファイル作成 === | ||
+ | ユーザやドメイン毎のメールボックスのサイズを指定(virtual_mailbox_limit以下で指定) | ||
+ | < | ||
+ | # vi / | ||
+ | test1@mail.flateight.com | ||
+ | @test2.flateight.com | ||
+ | @mail2.flateight.com | ||
+ | </ | ||
+ | |||
+ | === MySQL認証用ファイルを作成 === | ||
+ | < | ||
+ | # vi / | ||
+ | user = postfix | ||
+ | password = xxpostfix | ||
+ | hosts = localhost | ||
+ | dbname = postfix | ||
+ | table = alias | ||
+ | select_field = goto | ||
+ | where_field = address | ||
+ | |||
+ | #vi / | ||
+ | user = postfix | ||
+ | password = xxpostfix | ||
+ | hosts = localhost | ||
+ | dbname = postfix | ||
+ | table = domain | ||
+ | select_field = domain | ||
+ | where_field = domain | ||
+ | additional_conditions = and active = ' | ||
+ | |||
+ | # vi / | ||
+ | user = postfix | ||
+ | password = xxpostfix | ||
+ | hosts = localhost | ||
+ | dbname = postfix | ||
+ | table = mailbox | ||
+ | select_field = maildir | ||
+ | where_field = username | ||
+ | </ | ||
+ | |||
+ | |||
+ | === MySQL用設定ファイル作成 === | ||
+ | < | ||
+ | # vi / | ||
+ | driver = mysql | ||
+ | default_pass_scheme = PLAIN | ||
+ | connect = dbname=postfix user=postfix host=/ | ||
+ | password_query = SELECT password FROM mailbox WHERE username = ' | ||
+ | user_query = SELECT concat('/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | === TLS セッションキャッシュマネージャの設定(master.cf の編集) コメントを外す === | ||
+ | < | ||
+ | # vi / | ||
+ | submission inet n - n - - smtpd | ||
+ | -o smtpd_enforce_tls=yes | ||
+ | -o smtpd_sasl_auth_enable=yes | ||
+ | -o smtpd_client_restrictions=permit_sasl_authenticated, | ||
+ | smtps inet n - n - - smtpd | ||
+ | -o smtpd_tls_wrappermode=yes | ||
+ | -o smtpd_sasl_auth_enable=yes | ||
+ | -o smtpd_client_restrictions=permit_sasl_authenticated, | ||
+ | </ | ||
+ | |||
+ | ===== 3. Dovecot ===== | ||
+ | |||
+ | === インストール === | ||
+ | < | ||
+ | # yum install dovecot | ||
+ | </ | ||
+ | |||
+ | === 証明書設定 === | ||
+ | |||
+ | < | ||
+ | # cd / | ||
+ | # make mail.pem | ||
+ | # openssl x509 -in mail.pem -outform DER -out mail.der | ||
+ | # cp / | ||
+ | # vi / | ||
+ | listen = [::] | ||
+ | log_path = / | ||
+ | ssl_disable = no | ||
+ | ssl_cert_file = / | ||
+ | ssl_key_file = / | ||
+ | verbose_ssl = yes | ||
+ | mail_location = maildir:/ | ||
+ | last_valid_uid = 10000 | ||
+ | first_valid_gid = 10000 | ||
+ | protocol imap { | ||
+ | } | ||
+ | | ||
+ | protocol pop3 { | ||
+ | } | ||
+ | protocol lda { | ||
+ | postmaster_address = postmaster@example.com | ||
+ | } | ||
+ | auth_verbose = yes | ||
+ | auth_debug = yes | ||
+ | auth_debug_passwords = yes | ||
+ | auth default { | ||
+ | mechanisms = plain login digest-md5 cram-md5 apop | ||
+ | passdb sql { | ||
+ | args = / | ||
+ | } | ||
+ | |||
+ | userdb sql { | ||
+ | args = / | ||
+ | } | ||
+ | |||
+ | | ||
+ | client { | ||
+ | path = / | ||
+ | mode = 0660 | ||
+ | user = postfix | ||
+ | group = postfix | ||
+ | } | ||
+ | } | ||
+ | user = root | ||
+ | } | ||
+ | dict { | ||
+ | } | ||
+ | plugin { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | === 認証ライブラリのインストール === | ||
+ | < | ||
+ | # yum -y install cyrus-sasl-md5 cyrus_sasl_sql cyrus-sasl-plain | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Apacheなどなどのインストール === | ||
+ | |||
+ | < | ||
+ | # yum install httpd | ||
+ | # yum install php-mysql php-xml php-devel php-mbstring php-gd php-pear php-xmlrpc php-soap php-imap | ||
+ | </ | ||
+ | |||
+ | === chkconfig === | ||
+ | |||
+ | < | ||
+ | # chkconfig httpd on | ||
+ | </ | ||
+ | |||
+ | === スタート === | ||
+ | |||
+ | < | ||
+ | # service httpd start | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== 4. ファイアウォールの設定 ===== | ||
+ | |||
+ | === 下記ポートを開ける === | ||
+ | |||
+ | < | ||
+ | 25 | ||
+ | 110 | ||
+ | 143 | ||
+ | 465 番 SMTP over SSL | ||
+ | 993 番 IMAP over SSL | ||
+ | 995 番 POP3 over SSL | ||
+ | </ | ||
+ | |||
+ | |||
+ | === メールディレクトリを用意しておく === | ||
+ | |||
+ | < | ||
+ | # mkdir / | ||
+ | # chown 10000 / | ||
+ | </ | ||
+ | |||
+ | === mailユーザ・グループの変更 === | ||
+ | |||
+ | mailユーザと、mailグループのIDを変更しておく。 | ||
+ | < | ||
+ | # usermod -u 10000 -g 10000 mail | ||
+ | # groupmod -g 10000 mail | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== 5. PostfixAdminインストール ===== | ||
+ | |||
+ | ・ダウンロードURL http:// | ||
+ | |||
+ | < | ||
+ | # cd / | ||
+ | # wget http:// | ||
+ | # tar zxvf postfixadmin_2.3.tar.gz | ||
+ | # mv postfixadmin_2.3 / | ||
+ | # cd / | ||
+ | # vi config.inc.php | ||
+ | 26 $CONF[' | ||
+ | 43 $CONF[' | ||
+ | 49 $CONF[' | ||
+ | 50 $CONF[' | ||
+ | 51 $CONF[' | ||
+ | 52 $CONF[' | ||
+ | 53 $CONF[' | ||
+ | 100 // $CONF[' | ||
+ | 101 $CONF[' | ||
+ | 130 $CONF[' | ||
+ | 158 $CONF[' | ||
+ | 159 $CONF[' | ||
+ | </ | ||
+ | |||
+ | === URLからアクセス === | ||
+ | |||
+ | http:// | ||
+ | |||
+ | 全部OKになっていればOKです。 | ||
+ | |||
+ | setupパスワードを入力し、表示されたsetup_passwordを | ||
+ | config.inc.phpに入力する。 | ||
+ | ↓ | ||
+ | 管理者IDを作成する。 | ||
+ | |||
+ | === setup.phpを削除 === | ||
+ | |||
+ | < | ||
+ | # rm / | ||
+ | </ | ||
+ | |||
+ | === URLからアクセス === | ||
+ | |||
+ | http:// | ||
+ | |||
+ | Web上からpostmaster宛とroot宛を転送するように設定。 | ||
+ | |||
+ | |||
+ | |||
+ | ===== エラー ===== | ||
+ | |||
+ | === ◆user unknown === | ||
+ | |||
+ | Info: auth(default): | ||
+ | === 対処 === | ||
+ | |||
+ | これがあると、passwd認証をしようとするが、当然無いのでunknown userとなってしまう。 | ||
+ | dovecot.confの「auth default」内のpassdb passudをコメントアウトしてやる。 | ||
+ | < | ||
+ | # vi / | ||
+ | auth default { | ||
+ | # | ||
+ | #} | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === ◆pam_authenticate() failed: === | ||
+ | |||
+ | auth(default): | ||
+ | } | ||
+ | |||
+ | === 対処 === | ||
+ | |||
+ | |||
+ | これがあると、まずpam認証を行ってうが当然認証できないので、エラーになってしまう。 | ||
+ | dovecot.confの「auth default」内のpassdb pamをコメントアウトしてやる。 | ||
+ | < | ||
+ | # vi / | ||
+ | auth default { | ||
+ | # | ||
+ | #} | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== postfix master.cfの説明 ===== | ||
+ | |||
+ | smtpd_enforce_tls=yes | ||
+ | |||
+ | デフォルト: | ||
+ | SMTP クライアントに TLS 暗号化を強制する。 | ||
+ | |||
+ | smtpd_sasl_auth_enable=yes | ||
+ | |||
+ | デフォルト: | ||
+ | SMTP Auth (SASL による) を有効にする。 | ||
+ | |||
+ | smtpd_client_restrictions= | ||
+ | |||
+ | デフォルト: | ||
+ | SMTP クライアントが smtpd デーモンにアクセスするときの、アクセス制限設定。 | ||
+ | 記述順にパラメータ値(アクセス制限)が評価される。最後は permit (許可) になる。 | ||
+ | 基本的な書き方としては、 permit_ を書き、最後に reject を書く。 | ||
+ | (全部ふさいで一部分開くポリシー) | ||
+ | パラメータ値は、カンマかスペースで区切る。 | ||
+ | |||
+ | 長くなる場合は、次の行の先頭にスペースを入れることで、行が継続される。 | ||
+ | 例えば | ||
+ | |||
+ | smtpd_client_restrictions=permit_sasl_authenticated, | ||
+ | |||
+ | SMTP Auth で認証が確認された接続を許可。 それ以外は接続を拒否する。(デフォルト: | ||
+ | |||
+ | |||
+ | {{tag> |