サーバー設定 · 3 min read · Dec 12, 2025
完璧なサーバー - Fedora 14 x86_64 [ISPConfig 2] - ページ 4
9 MySQL 5
MySQLをインストールするには、次のようにします:
yum install mysql mysql-devel mysql-server次に、MySQLのシステム起動リンクを作成します(これにより、システムが起動するたびにMySQLが自動的に開始されます)およびMySQLサーバーを起動します:
chkconfig –levels 235 mysqld on
/etc/init.d/mysqld start
ネットワークが有効になっているか確認します。次のコマンドを実行します:
netstat -tap | grep mysql次のような出力が表示されるはずです:
[root@server1 ~]# netstat -tap | grep mysql
tcp 0 0 :mysql :* LISTEN 1765/mysqld
[root@server1 ~]#
表示されない場合は、/etc/my.cnfを編集し、skip-networkingオプションをコメントアウトします:
vi /etc/my.cnf| [...] #skip-networking [...] |
その後、MySQLサーバーを再起動します:
/etc/init.d/mysqld restart 次のコマンドを実行して、rootユーザーのパスワードを設定します(そうしないと、誰でもあなたのMySQLデータベースにアクセスできます!)。
[root@server1 ~]# mysql_secure_installation
NOTE: このスクリプトのすべての部分を実行することは、すべてのMySQLサーバーで推奨されます。 本番環境で使用する場合は、各ステップを注意深くお読みください!
MySQLにログインしてセキュリティを確保するためには、rootユーザーの現在のパスワードが必要です。 MySQLをインストールしたばかりで、まだrootパスワードを設定していない場合、パスワードは空白になりますので、ここではEnterキーを押してください。
現在のrootのパスワードを入力してください(なしの場合はEnter): <– ENTER
OK、パスワードが正常に使用されました、次に進みます…
rootパスワードを設定することで、適切な認証なしに誰もMySQLのrootユーザーにログインできないようにします。
rootパスワードを設定しますか? [Y/n] <– ENTER
新しいパスワード: <– yourrootsqlpassword
新しいパスワードを再入力してください: <– yourrootsqlpassword
パスワードが正常に更新されました!
特権テーブルを再読み込みしています..
… 成功!
デフォルトでは、MySQLインストールには匿名ユーザーがあり、誰でもユーザーアカウントを作成せずにMySQLにログインできます。 これはテスト用にのみ意図されており、インストールを少しスムーズにするためです。 本番環境に移行する前に、これらを削除する必要があります。
匿名ユーザーを削除しますか? [Y/n] <– ENTER
… 成功!
通常、rootは「localhost」からのみ接続を許可されるべきです。 これにより、誰かがネットワークからrootパスワードを推測できないようにします。
リモートでのrootログインを禁止しますか? [Y/n] <– ENTER
… 成功!
デフォルトでは、MySQLには誰でもアクセスできる「test」という名前のデータベースがあります。 これもテスト用にのみ意図されており、本番環境に移行する前に削除する必要があります。
テストデータベースとそのアクセスを削除しますか? [Y/n] <– ENTER
- テストデータベースを削除しています…
… 成功! - テストデータベースの特権を削除しています…
… 成功!
特権テーブルを再読み込みすることで、これまでに行ったすべての変更が即座に反映されます。
特権テーブルを今すぐ再読み込みしますか? [Y/n] <– ENTER
… 成功!
クリーンアップ中…
すべて完了! 上記のすべてのステップを完了した場合、あなたのMySQLインストールは今や安全であるはずです。
MySQLをご利用いただきありがとうございます!
[root@server1 ~]#
10 PostfixとSMTP-AUTHおよび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 [::1]/128’
PostfixがPLAINおよびLOGINログインを許可するように、/usr/lib64/sasl2/smtpd.confを編集する必要があります(32ビットシステムでは、このファイルは/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 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.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 data_directory = /var/lib/postfix mail_owner = postfix inet_interfaces = all inet_protocols = 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 ddd $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.7.1/samples readme_directory = /usr/share/doc/postfix-2.7.1/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 [::1]/128 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 |
次に、Postfixとsaslauthdを起動します:
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
Dovecotを起動する前に、プレーンテキスト認証を有効にする必要があります。/etc/dovecot/conf.d/10-auth.confを開き…
vi /etc/dovecot/conf.d/10-auth.conf… disable_plaintext_auth = noという行を追加します:
| [...] # SSL/TLSが使用されていない場合、LOGINコマンドとすべての他のプレーンテキスト認証を無効にします(LOGINDISABLED機能)。 リモートIPがローカルIPと一致する場合(つまり、同じコンピュータから接続している場合)、接続は安全と見なされ、プレーンテキスト認証が許可されます。 #disable_plaintext_auth = yes disable_plaintext_auth = no [...] |
その後、Dovecotを起動します:
/etc/init.d/dovecot startSMTP-AUTHとTLSが正常に機能しているか確認するには、次のコマンドを実行します:
telnet localhost 25 Postfixメールサーバーへの接続が確立されたら、次のように入力します:
ehlo localhost 次の行が表示されれば、すべて正常です:
250-STARTTLS および
250-AUTH LOGIN PLAIN[root@server1 ssl]# telnet localhost 25
Trying 127.0.0.1…
Connected to localhost.
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 LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 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にメールを配信するように設定する必要があります(ISPConfigを使用している場合でもこれを行うことができます - 害はありません;-)):
postconf -e ‘home_mailbox = Maildir/‘
postconf -e ‘mailbox_command =’
/etc/init.d/postfix restart
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。