サーバー設定 · 4 min read · Sep 25, 2025
完璧なサーバー - Ubuntu 15.04 (nginx, BIND, Dovecot と ISPConfig 3)
このチュートリアルでは、Nginx、PHP、MariaDB、Postfix、pure-ftpd、BIND、Dovecot、および ISPConfig 3 を使用して Ubuntu 15.04 (Vivid Vervet) サーバーをインストールする手順を示します。ISPConfig 3 は、インストールされたサービスをウェブブラウザを通じて構成できるウェブホスティングコントロールパネルです。このセットアップは、ウェブ、メール (スパムおよびウイルスフィルターを含む)、データベース、FTP、および DNS サービスを備えた完全なホスティングサーバーを提供します。
1. 予備ノート
このチュートリアルでは、ホスト名 server1.example.com と IP アドレス 192.168.1.100、ゲートウェイ 192.168.1.1 をネットワーク構成に使用します。これらの設定はあなたの環境によって異なる場合があるため、適宜置き換える必要があります。さらに進む前に、チュートリアルで説明されているように、基本的な最小限の Ubuntu 15.04 のインストールが必要です。
このチュートリアルの手順は root ユーザーとして実行する必要があるため、コマンドの前に “sudo” を付けません。進む前に root ユーザーとしてサーバーにログインするか、次のコマンドを実行してください:
sudo su異なるユーザーとしてシェルにログインしている場合は、root になるためにこのコマンドを実行します。
ファイルを編集するためのコマンドではエディタ “nano” を使用しますが、好みのエディタに置き換えることができます。Nano はシェル用の使いやすいファイルエディタです。nano を使用したいがまだインストールしていない場合は、次のコマンドを実行してください:
apt-get install nano2. Linux インストールの更新
/etc/apt/sources.list を編集します。ファイルからインストール CD をコメントアウトまたは削除し、universe および multiverse リポジトリが有効になっていることを確認します。次のようになります:
nano /etc/apt/sources.list#
# deb cdrom:[Ubuntu-Server 15.04 _Vivid Vervet_ - Release amd64 (20150422)]/ vivid main restricted
#deb cdrom:[Ubuntu-Server 15.04 _Vivid Vervet_ - Release amd64 (20150422)]/ vivid main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://de.archive.ubuntu.com/ubuntu/ vivid main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ vivid main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://de.archive.ubuntu.com/ubuntu/ vivid-updates main restricted
deb-src http://de.archive.ubuntu.com/ubuntu/ vivid-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://de.archive.ubuntu.com/ubuntu/ vivid universe
deb-src http://de.archive.ubuntu.com/ubuntu/ vivid universe
deb http://de.archive.ubuntu.com/ubuntu/ vivid-updates universe
deb-src http://de.archive.ubuntu.com/ubuntu/ vivid-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://de.archive.ubuntu.com/ubuntu/ vivid multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ vivid multiverse
deb http://de.archive.ubuntu.com/ubuntu/ vivid-updates multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ vivid-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://de.archive.ubuntu.com/ubuntu/ vivid-backports main restricted universe multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ vivid-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu vivid-security main restricted
deb-src http://security.ubuntu.com/ubuntu vivid-security main restricted
deb http://security.ubuntu.com/ubuntu vivid-security universe
deb-src http://security.ubuntu.com/ubuntu vivid-security universe
deb http://security.ubuntu.com/ubuntu vivid-security multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu vivid partner
# deb-src http://archive.canonical.com/ubuntu vivid partner その後、次のコマンドを実行します:
apt-get updateapt パッケージデータベースを更新し、
apt-get upgrade最新の更新をインストールします (ある場合)。更新の一環として新しいカーネルがインストールされる場合は、その後システムを再起動する必要があります:
reboot3. デフォルトシェルの変更
/bin/sh は /bin/dash へのシンボリックリンクですが、/bin/dash ではなく /bin/bash が必要です。したがって、次のようにします:
dpkg-reconfigure dashUse dash as the default system shell (/bin/sh)? <– No
これを行わないと、ISPConfig のインストールが失敗します。
4. AppArmor の無効化
AppArmor は、拡張セキュリティを提供するセキュリティ拡張 (SELinux に似ています) ですが、13.10 以降はデフォルトでインストールされません。インストールされているかどうかを確認します。私の意見では、安全なシステムを構成するために必要なく、通常は利点よりも問題を引き起こすことが多いです (サービスが期待通りに動作しなかったためにトラブルシューティングを1週間行った後、すべてが正常であったことがわかり、問題を引き起こしていたのが AppArmor だったということを考えてみてください)。したがって、これを無効にします (後で ISPConfig をインストールしたい場合は必須です)。
次のようにして無効にできます:
service apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils5. システムクロックの同期
システムクロックをインターネット上の NTP ( n etwork t ime p rotocol) サーバーと同期させるのは良いアイデアです。単に次のコマンドを実行します:
apt-get install ntp ntpdateこれでシステム時間は常に同期されます。
6. Postfix、Dovecot、MariaDB、phpMyAdmin、rkhunter、binutils のインストール
Postfix、Dovecot、MariaDB (MySQL の代替) 、rkhunter、および binutils を単一のコマンドでインストールできます:
apt-get install postfix postfix-mysql postfix-doc mariadb-client mariadb-server openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-sieve sudoMariaDB は、元の MySQL 開発者 Monty Widenius によって開発された MySQL データベースサーバーのフォークです。インターネット上のテストによると、MariaDB は MySQL よりも高速で、開発がより活発に行われているため、ほとんどの Linux ディストリビューションは MySQL をデフォルトの「MySQL に似た」データベースサーバーとして MariaDB に置き換えました。MySQL を MariaDB の代わりに使用したい場合は、上記のコマンドの “mariadb-client mariadb-server” を “mysql-client mysql-server” に置き換えてください。
次の質問が表示されます:
Create a self-signed SSL certificate? <-- yes
Host name: <-- server1.example.com
General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com次に、Postfix で TLS/SSL および送信ポートを開きます:
nano /etc/postfix/master.cf送信と smtps セクションのコメントを解除し、次のように行を追加します -o smtpd_client_restrictions=permit_sasl_authenticated,reject を両方のセクションに追加し、それ以降はすべてコメントアウトします:
[...]
submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
smtps inet n - - - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
[...] その後、Postfix を再起動します:
service postfix restartMariaDB/MySQL が localhost だけでなくすべてのインターフェースでリッスンするようにします。したがって、/etc/mysql/mariadb.conf.d/mysqld.cnf (MariaDB 用) または /etc/mysql/my.cnf (MySQL 用) を編集し、bind-address = 127.0.0.1 の行をコメントアウトします:
MariaDB
nano /etc/mysql/mariadb.conf.d/mysqld.cnf次に、MariaDB で root パスワードを設定します。次のコマンドを実行します:
mysql_secure_installation次の質問が表示されます:
Enter current password for root (enter for none): <-- press enter
Set root password? [Y/n] <-- y
New password: <-- Enter the new MariaDB root password here
Re-enter new password: <-- Repeat the password
Remove anonymous users? [Y/n] <-- y
Disallow root login remotely? [Y/n] <-- y
Reload privilege tables now? [Y/n] <-- y次に、次のコマンドを実行して認証プラグインを無効にします:
echo "update user set plugin='' where User='root';flush privileges;" | mysql --defaults-file=/etc/mysql/debian.cnf mysqlPHPMyAdmin からのパスワードベースの認証を許可します。
MySQL
nano /etc/mysql/my.cnf[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
[...] その後、MariaDB / MySQL を再起動します:
service mysql restartMariaDB と MySQL の systemd サービス名は “mysql” なので、再起動コマンドは両方で同じです。
ネットワーキングが有効になっていることを確認します。次のコマンドを実行します:
netstat -tap | grep mysql出力は次のようになります:
root@server1:~# netstat -tap | grep mysql
tcp 0 0 *:mysql *:* LISTEN 23785/mysqld
root@server1:~#7. Amavisd-new、SpamAssassin、Clamav のインストール
amavisd-new、SpamAssassin、および ClamAV をインストールするには、次のコマンドを実行します:
apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perlISPConfig 3 のセットアップでは、内部で SpamAssassin フィルターライブラリをロードする amavisd-new を使用するため、RAM を解放するために SpamAssassin を停止できます:
service spamassassin stop
update-rc.d -f spamassassin removeClamAV ウイルス対策の署名を更新し、Clamd サービスを開始します。更新プロセスには時間がかかる場合があるため、途中で中断しないでください。
freshclam
service clamav-daemon start新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。