サーバー設定 · 3 min read · Oct 05, 2025

完璧なサーバー - Debian Lenny (Debian 5.0) [ISPConfig 2] - ページ 4

11 MySQL

MySQLをインストールするために、次のコマンドを実行します。

apt-get install mysql-server mysql-client libmysqlclient15-dev

MySQLのrootユーザーのパスワードを提供するように求められます。このパスワードは、ユーザーroot@localhostおよび[メール protected]に対して有効であるため、後でMySQLのrootパスワードを手動で指定する必要はありません。

MySQL “root” ユーザーの新しいパスワード: <– yourrootsqlpassword
MySQL “root” ユーザーのパスワードを再入力してください: <– yourrootsqlpassword

MySQLがlocalhostだけでなくすべてのインターフェースでリッスンするようにしたいため、/etc/mysql/my.cnfを編集し、bind-address = 127.0.0.1の行をコメントアウトします。

vi /etc/mysql/my.cnf

| [...] # skip-networkingの代わりに、デフォルトは現在localhostのみにリッスンすることです。 # これはより互換性があり、セキュリティが低下することはありません。 #bind-address = 127.0.0.1 [...] |

その後、MySQLを再起動します。

/etc/init.d/mysql restart

ネットワークが有効になっていることを確認します。次のコマンドを実行します。

netstat -tap | grep mysql

出力は次のようになります。

server1:~# netstat -tap | grep mysql  
tcp        0      0 *:mysql                 *:*                     LISTEN      6612/mysqld  
server1:~#

12 Postfix With SMTP-AUTH And TLS

SMTP-AUTHおよびTLSを使用してPostfixをインストールするために、次の手順を実行します。

apt-get install postfix libsasl2-2 sasl2-bin libsasl2-modules procmail

2つの質問が求められます。次のように回答します。

メール構成の一般的なタイプ: <– インターネットサイト
システムメール名: <– server1.example.com

次に、次のコマンドを実行します。

dpkg-reconfigure postfix

再度、いくつかの質問が求められます。

メール構成の一般的なタイプ: <– インターネットサイト
システムメール名: <– server1.example.com
ルートおよびポストマスターのメール受取人: <– [空白]
受け入れる他の宛先 (なしの場合は空白): <– server1.example.com, localhost.example.com, localhost.localdomain, localhost
メールキューの同期更新を強制しますか? <– いいえ
ローカルネットワーク: <– 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
ローカル配信にprocmailを使用しますか? <– はい
メールボックスサイズ制限 (バイト): <– 0
ローカルアドレス拡張文字: <– +
使用するインターネットプロトコル: <– すべて

次に、次のコマンドを実行します。

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'  
echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf  
echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf

その後、TLS用の証明書を作成します。

mkdir /etc/postfix/ssl  
cd /etc/postfix/ssl/  
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key  
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key  
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

次に、PostfixをTLS用に構成します (myhostnameに正しいホスト名を使用していることを確認してください)。

postconf -e 'myhostname = server1.example.com'
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'

ファイル/etc/postfix/main.cfは次のようになります。

cat /etc/postfix/main.cf

| # /usr/share/postfix/main.cf.distのコメント付きの、より完全なバージョンを参照してください # Debian特有: ファイル名を指定すると、そのファイルの最初の行が名前として使用されます。 # Debianのデフォルトは/etc/mailnameです。 #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no # .domainを追加するのはMUAの仕事です。 append_dot_mydomain = no # 次の行をコメント解除すると、「遅延メール」警告が生成されます #delay_warning_time = 4h readme_directory = no # TLSパラメータ smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key smtpd_use_tls = yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # smtpクライアントでSSLを有効にするための情報は、postfix-docパッケージの/usr/share/doc/postfix/TLS_README.gzを参照してください。 myhostname = server1.example.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = server1.example.com, localhost.example.com, localhost.localdomain, localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all 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 smtpd_tls_auth_only = no smtp_use_tls = yes smtp_tls_note_starttls_offer = yes 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 |

認証はsaslauthdによって行われます。これを正しく機能させるために、いくつかの変更を行う必要があります。Postfixは/var/spool/postfix内でchrootされて実行されるため、次のようにします。

mkdir -p /var/spool/postfix/var/run/saslauthd

次に、saslauthdを有効にするために/etc/default/saslauthdを編集する必要があります。STARTをyesに設定し、OPTIONS=”-c -m /var/run/saslauthd”の行をOPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”に変更します。

vi /etc/default/saslauthd

| # # saslauthdデーモンの設定 # 詳細については/usr/share/doc/sasl2-bin/README.Debianを参照してください。 # # saslauthdは自動的に起動時に実行されるべきですか? (デフォルト: いいえ) START=yes # このsaslauthdインスタンスの説明。推奨されます。 # (提案: SASL Authentication Daemon) DESC="SASL Authentication Daemon" # このsaslauthdインスタンスの短い名前。強く推奨されます。 # (提案: saslauthd) NAME="saslauthd" # saslauthdが使用する認証メカニズムは何ですか? (デフォルト: pam) # # このDebianパッケージでの利用可能なオプション: # getpwent -- getpwent()ライブラリ関数を使用 # kerberos5 -- Kerberos 5を使用 # pam -- PAMを使用 # rimap -- リモートIMAPサーバーを使用 # shadow -- ローカルシャドウパスワードファイルを使用 # sasldb -- ローカルsasldbデータベースファイルを使用 # ldap -- LDAPを使用 (設定は/etc/saslauthd.confにあります) # # 一度に1つのオプションのみ使用できます。詳細についてはsaslauthdのマニュアルページを参照してください。 # # 例: MECHANISMS="pam" MECHANISMS="pam" # このメカニズムの追加オプション。 (デフォルト: なし) # メカニズム固有のオプションについてはsaslauthdのマニュアルページを参照してください。 MECH_OPTIONS="" # いくつのsaslauthdプロセスを実行する必要がありますか? (デフォルト: 5) # 値が0の場合、各接続ごとに新しいプロセスがフォークされます。 THREADS=5 # その他のオプション (デフォルト: -c -m /var/run/saslauthd) # 注意: -mオプションを指定しないとsaslauthdは実行されません! # # 警告: -dオプションを指定しないでください。 # -dオプションを指定すると、saslauthdはデーモンではなくフォアグラウンドで実行されます。これにより、システムが正常にブートしなくなります。デバッグモードでsaslauthdを実行したい場合は、安全のため手動で実行してください。 # # Debian固有の情報については/usr/share/doc/sasl2-bin/README.Debianを参照してください。 # saslauthdのマニュアルページおよび'saslauthd -h'の出力を参照して、これらのオプションに関する一般的な情報を取得してください。 # # Postfixユーザーの例: "-c -m /var/spool/postfix/var/run/saslauthd" #OPTIONS="-c -m /var/run/saslauthd" OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r" |

次に、Postfixユーザーをsaslグループに追加します (これにより、Postfixがsaslauthdにアクセスする権限を持つことが保証されます)。

adduser postfix sasl

次に、Postfixを再起動し、saslauthdを開始します。

/etc/init.d/postfix restart  
/etc/init.d/saslauthd start

SMTP-AUTHおよびTLSが正しく機能しているか確認するために、次のコマンドを実行します。

telnet localhost 25

Postfixメールサーバーへの接続が確立されたら、次のコマンドを入力します。

ehlo localhost

次の行が表示される場合、すべてが正常です。

250-STARTTLS

および

250-AUTH LOGIN PLAIN

私のシステムでの出力は次のようになります。

server1:/etc/postfix/ssl# telnet localhost 25  
Trying 127.0.0.1...  
Connected to localhost.  
Escape character is '^]'.  
220 server1.example.com ESMTP Postfix (Debian/GNU)  
ehlo localhost  
250-server1.example.com  
250-PIPELINING  
250-SIZE 10240000  
250-VRFY  
250-ETRN  
250-STARTTLS  
250-AUTH LOGIN PLAIN  
250-AUTH=LOGIN PLAIN  
250-ENHANCEDSTATUSCODES  
250-8BITMIME  
250 DSN  
quit  
221 2.0.0 Bye  
Connection closed by foreign host.  
server1:/etc/postfix/ssl#
quit

と入力してシステムのシェルに戻ります。

13 Courier-IMAP/Courier-POP3

Courier-IMAP/Courier-IMAP-SSL (ポート993のIMAPs用) およびCourier-POP3/Courier-POP3-SSL (ポート995のPOP3s用)をインストールするには、次のコマンドを実行します。

apt-get install courier-authdaemon courier-base courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-ssl gamin libgamin0 libglib2.0-0

2つの質問が求められます。

ウェブベースの管理用のディレクトリを作成しますか? <– いいえ
SSL証明書が必要ですか <– はい

インストール中に、IMAP-SSLおよびPOP3-SSL用のSSL証明書がlocalhostというホスト名で作成されます。これを正しいホスト名 (このチュートリアルではserver1.example.com) に変更するには、証明書を削除します…

cd /etc/courier  
rm -f /etc/courier/imapd.pem  
rm -f /etc/courier/pop3d.pem

… 次の2つのファイルを修正します。CN=localhostをCN=server1.example.comに置き換えます (必要に応じて他の値も変更できます)。

vi /etc/courier/imapd.cnf

| [...] CN=server1.example.com [...] |

vi /etc/courier/pop3d.cnf

| [...] CN=server1.example.com [...] |

その後、証明書を再作成します…

mkimapdcert  
mkpop3dcert

… そして、Courier-IMAP-SSLおよびCourier-POP3-SSLを再起動します。

/etc/init.d/courier-imap-ssl restart  
/etc/init.d/courier-pop-ssl restart

ISPConfigを使用しない場合は、Postfixを構成してユーザーのMaildir*にメールを配信します。

postconf -e 'home_mailbox = Maildir/'  
postconf -e 'mailbox_command ='  
/etc/init.d/postfix restart

*注意: ISPConfigを使用する予定の場合は、これを行う必要はありません。ISPConfigはprocmailレシピを使用して必要な構成を行います。ただし、ISPConfigのWebインターフェースの管理 -> サーバー -> 設定 -> EメールでMaildirを有効にすることを確認してください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。