サーバー設定 · 3 min read · Oct 29, 2025
完璧なサーバー - CentOS 4.8 サーバー x86_64 [ISPConfig 2] - ページ 5
10 Postfix With SMTP-AUTH And TLS
今、Postfixとdovecotをインストールします(dovecotは私たちのPOP3/IMAPサーバーになります):
yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain postfix dovecot次に、SMTP-AUTHとTLSを設定します:
postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
postconf -e 'mynetworks = 127.0.0.0/8'/ usr/lib64/sasl2/smtpd.confを編集して、PostfixがPLAINおよびLOGINログインを許可するようにします。32ビットのCentos 4.8では、/usr/lib/sasl2/smtpd.confファイルを編集する必要があります。次のようになります:
vi /usr/lib64/sasl2/smtpd.conf| pwcheck_method: saslauthd mech_list: plain login |
その後、TLS用の証明書を作成します:
mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csropenssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crtopenssl rsa -in smtpd.key -out smtpd.key.unencryptedmv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650次に、PostfixをTLS用に設定します:
postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'次に、Postfixインストールでホスト名を設定します(server1.example.comを自分のホスト名に置き換えてください):
postconf -e 'myhostname = server1.example.com'これらの設定手順の後、次のような/etc/postfix/main.cfがあるはずです(すべてのコメントを削除しました):
cat /etc/postfix/main.cf| queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix mail_owner = postfix inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost unknown_local_recipient_reject_code = 550 alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin xxgdb $daemon_directory/$process_name $process_id & sleep 5 sendmail_path = /usr/sbin/sendmail.postfix newaliases_path = /usr/bin/newaliases.postfix mailq_path = /usr/bin/mailq.postfix setgid_group = postdrop html_directory = no manpage_directory = /usr/share/man sample_directory = /usr/share/doc/postfix-2.2.10/samples readme_directory = /usr/share/doc/postfix-2.2.10/README_FILES smtpd_sasl_local_domain = smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_sasl_authenticated_header = yes smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination mynetworks = 127.0.0.0/8 smtpd_tls_auth_only = no smtp_use_tls = yes smtpd_use_tls = yes smtp_tls_note_starttls_offer = yes smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem smtpd_tls_loglevel = 1 smtpd_tls_received_header = yes smtpd_tls_session_cache_timeout = 3600s tls_random_source = dev:/dev/urandom myhostname = server1.example.com |
デフォルトでは、CentOSのdovecotデーモンはIMAPおよびIMAPsサービスのみを提供します。POP3およびPOP3sも必要なため、dovecotを設定する必要があります。/etc/dovecot.confを編集し、次の行を追加します:protocols = imap imaps pop3 pop3s
vi /etc/dovecot.conf| [...] # ランタイムデータを保存するベースディレクトリ。 #base_dir = /var/run/dovecot/ # 提供したいプロトコル: # imap imaps pop3 pop3s protocols = imap imaps pop3 pop3s [...] |
Postfix、saslauthd、およびdovecotを起動します:
chkconfig --levels 235 sendmail off
chkconfig --levels 235 postfix on
chkconfig --levels 235 saslauthd on
chkconfig --levels 235 dovecot on
/etc/init.d/sendmail stop
/etc/init.d/postfix start
/etc/init.d/saslauthd start
/etc/init.d/dovecot startSMTP-AUTHとTLSが正常に動作しているか確認するには、次のコマンドを実行します:
telnet localhost 25Postfixメールサーバーへの接続が確立されたら、次のように入力します:
ehlo localhost次の行が表示される場合:
250-STARTTLSおよび
250-AUTH PLAIN LOGINすべてが正常です。
[root@server1 ssl]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 server1.example.com ESMTP Postfix
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250 8BITMIME
quit
221 Bye
Connection closed by foreign host.
[root@server1 ssl]#quitと入力してシステムのシェルに戻ります。
10.1 Maildir
dovecotはMaildir形式(mboxではない)を使用するため、サーバーにISPConfigをインストールする場合は、Management -> Server -> Settings -> Emailの下でMaildirを有効にしてください。ISPConfigは必要な設定を行います。
ISPConfigをインストールしたくない場合は、Postfixを構成してユーザーのMaildirにメールを配信する必要があります:
postconf -e 'home_mailbox = Maildir/'
postconf -e 'mailbox_command ='
/etc/init.d/postfix restart11 Apache2 With PHP, Ruby, Python
次に、PHPを使用してApacheをインストールします(これはPHP 4.3.9です。CentOSはPHP5パッケージを提供していません):
yum install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel次に、/etc/httpd/conf/httpd.confを編集します:
vi /etc/httpd/conf/httpd.confそして、DirectoryIndexを次のように変更します:
| [...] DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.pl [...] |
システムが起動時にApacheを開始するように設定します:
chkconfig --levels 235 httpd onApacheを起動します:
/etc/init.d/httpd start11.1 PHPをグローバルに無効にする
(このサーバーにISPConfigをインストールする予定がない場合は、このセクションをスキップしてください!)
ISPConfigでは、ウェブサイトごとにPHPを構成します。つまり、どのウェブサイトがPHPスクリプトを実行でき、どのウェブサイトが実行できないかを指定できます。これは、PHPがグローバルに無効になっている場合にのみ機能します。そうでなければ、すべてのウェブサイトがPHPスクリプトを実行できることになります。
PHPをグローバルに無効にするには、/etc/httpd/conf.d/php.confを編集し、AddType行をコメントアウトします:
vi /etc/httpd/conf.d/php.conf| # # PHPはHTMLに埋め込まれたスクリプト言語で、 # 開発者が動的に生成されたウェブページを書くのを簡単にしようとします。 # LoadModule php4_module modules/libphp4.so # # PHPインタープリターが.php拡張子のファイルを処理するようにします。 # #AddType application/x-httpd-php .php # AddType application/x-httpd-php-source .phps # # index.phpをディレクトリインデックスとして提供されるファイルのリストに追加します。 # DirectoryIndex index.php |
その後、Apacheを再起動します:
/etc/init.d/httpd restart11.2 mod_rubyのインストール
CentOS 4.8にはmod_rubyパッケージがないため、私たち自身でコンパイルする必要があります。まず、いくつかの前提条件をインストールします:
yum install httpd-devel ruby ruby-devel次に、mod_rubyをダウンロードしてインストールします:
cd /tmp
wget http://modruby.net/archive/mod_ruby-1.3.0.tar.gz
tar zxvf mod_ruby-1.3.0.tar.gz
cd mod_ruby-1.3.0/
./configure.rb --with-apr-includes=/usr/include/apr-0
make
make install最後に、mod_rubyモジュールをApacheの設定に追加する必要があります。/etc/httpd/conf.d/ruby.confファイルを作成します…
vi /etc/httpd/conf.d/ruby.conf| LoadModule ruby_module modules/mod_ruby.so |
… そしてApacheを再起動します:
/etc/init.d/httpd restart11.3 mod_pythonのインストール
mod_pythonをインストールするには、単に次のコマンドを実行します…
yum install mod_python… そしてその後Apacheを再起動します:
/etc/init.d/httpd restart新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。