サーバー設定 · 5 min read · Sep 10, 2025

完璧なサーバー - Ubuntu 16.04 (Nginx, MySQL, PHP, Postfix, BIND, Dovecot, Pure-FTPD および ISPConfig 3.1)

このチュートリアルでは、Nginx、PHP、MariaDB、Postfix、pure-ftpd、BIND、Dovecot、および ISPConfig 3.1 を使用して、Ubuntu 16.04 (Xenial Xerus) サーバーをインストールする手順を示します。ISPConfig は、インストールされたサービスをウェブブラウザを通じて構成できるウェブホスティングコントロールパネルです。このセットアップは、ウェブ、メール (スパムおよびウイルス対策フィルターを含む)、データベース、FTP、および DNS サービスを備えた完全なホスティングサーバーを提供します。

1. 前提条件

このチュートリアルでは、ホスト名 server1.example.com と IP アドレス 192.168.1.100、ゲートウェイ 192.168.1.1 をネットワーク構成に使用します。これらの設定はあなたの環境によって異なる場合があるため、適宜置き換えてください。さらに進む前に、チュートリアルで説明されているように、Ubuntu 16.04 の基本的な最小インストールが必要です。

このチュートリアルの手順は root ユーザーとして実行する必要があるため、コマンドの前に “sudo” を付けません。サーバーに進む前に root ユーザーとしてログインするか、次のコマンドを実行してください:

sudo -s

異なるユーザーとしてシェルにログインしている場合は、root になるために使用します。

ファイルを編集するためのコマンドはエディタ “nano” を使用しますが、お好みのエディタに置き換えることができます。Nano はシェル用の使いやすいファイルエディタです。nano を使用したいがまだインストールしていない場合は、次のコマンドを実行してください:

apt-get install nano

2. Linux インストールの更新

/etc/apt/sources.list を編集します。ファイルからインストール CD をコメントアウトまたは削除し、universe および multiverse リポジトリが有効になっていることを確認します。次のようになります:

nano /etc/apt/sources.list
#  
# deb cdrom:[Ubuntu-Server 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420)]/ xenial main restricted  
#deb cdrom:[Ubuntu-Server 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420)]/ xenial 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/ xenial main restricted  
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial main restricted  
## Major bug fix updates produced after the final release of the  
## distribution.  
deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates main restricted  
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-updates main restricted  
## 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  
universe WILL NOT receive any review or updates from the Ubuntu security  
## team.  
deb http://de.archive.ubuntu.com/ubuntu/ xenial universe  
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial universe  
deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates universe  
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-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/ xenial multiverse  
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial multiverse  
deb http://de.archive.ubuntu.com/ubuntu/ xenial-updates multiverse  
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-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/ xenial-backports main restricted universe multiverse  
# deb-src http://de.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe 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 xenial partner  
# deb-src http://archive.canonical.com/ubuntu xenial partner  
deb http://security.ubuntu.com/ubuntu xenial-security main restricted  
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted  
deb http://security.ubuntu.com/ubuntu xenial-security universe  
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe  
deb http://security.ubuntu.com/ubuntu xenial-security multiverse  
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

その後、次のコマンドを実行します:

apt-get update

apt パッケージデータベースを更新し、次に:

apt-get upgrade

最新の更新をインストールします (ある場合)。更新の一環として新しいカーネルがインストールされる場合は、その後システムを再起動する必要があります:

reboot

3. デフォルトシェルの変更

/bin/sh は /bin/dash へのシンボリックリンクですが、/bin/bash が必要です。したがって、次のようにします:

dpkg-reconfigure dash

Use dash as the default system shell (/bin/sh)? <– No

これを行わないと、ISPConfig のインストールが失敗します。

4. AppArmor の無効化

AppArmor は、拡張セキュリティを提供するセキュリティ拡張 (SELinux に似ています) です。インストールされているかどうかを確認し、必要に応じて削除します。私の意見では、セキュアなシステムを構成するために必要ありませんし、通常は利点よりも問題を引き起こします (あるサービスが期待通りに動作しなかったために一週間トラブルシューティングを行った後、すべてが正常であることがわかり、AppArmor が問題を引き起こしていたことがわかることを考えてみてください)。したがって、無効にします (これは、後で ISPConfig をインストールしたい場合は必須です)。

次のように無効にできます:

service apparmor stop  
update-rc.d -f apparmor remove  
apt-get remove apparmor apparmor-utils

5. システムクロックの同期

システムクロックをインターネット上の NTP ( n etwork t ime p rotocol) サーバーと同期させるのは良いアイデアです。単に次のコマンドを実行します:

apt-get -y install ntp ntpdate

これで、システム時間は常に同期されます。

6. Postfix、Dovecot、MariaDB、phpMyAdmin、rkhunter、Binutils のインストール

Postfix をインストールするには、sendmail がインストールされておらず、実行されていないことを確認する必要があります。sendmail を停止して削除するには、次のコマンドを実行します:

service sendmail stop; update-rc.d -f sendmail remove

エラーメッセージ:

Failed to stop sendmail.service: Unit sendmail.service not loaded.

これは問題ありません。sendmail がインストールされていなかったことを意味するだけで、削除するものはありませんでした。

Postfix、Dovecot、MariaDB (MySQL の代替)、rkhunter、および binutils を単一のコマンドでインストールできます:

apt-get -y install postfix postfix-mysql postfix-doc mariadb-client mariadb-server openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-sieve dovecot-lmtpd sudo

MariaDB は、元の MySQL 開発者 Monty Widenius によって開発された MySQL データベースサーバーのフォークです。インターネット上のテストによると、MariaDB は MySQL よりも高速であり、開発がより活発に進められています。そのため、ほとんどの Linux ディストリビューションは、デフォルトの「MySQL に似た」データベースサーバーとして MySQL を MariaDB に置き換えました。MySQL を MariaDB よりも好む場合は、上記のコマンドの “mariadb-client mariadb-server” を “mysql-client mysql-server” に置き換えてください。

次の質問が表示されます:

General type of mail configuration: <-- Internet Site  
System mail name: <-- server1.example.com

次に、Postfix で TLS/SSL および送信ポートを開きます:

nano /etc/postfix/master.cf

次のように submission および 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 restart

MariaDB/MySQL にすべてのインターフェースでリッスンさせるため、/etc/mysql/mariadb.conf.d/50-server.cnf (MariaDB 用) または /etc/mysql/my.cnf (MySQL 用) を編集し、bind-address = 127.0.0.1 の行をコメントアウトします:

MariaDB

nano /etc/mysql/mariadb.conf.d/50-server.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 を再起動します:

service mysql restart

MariaDB と MySQL の systemd サービス名は “mysql” であるため、再起動コマンドは両方のデータベースサーバーで同じです。

次に、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

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  
[...]  

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

service mysql restart

MariaDB と MySQL の systemd サービス名は “mysql” であるため、再起動コマンドは両方のデータベースサーバーで同じです。

MySQL と MariaDB の場合:

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

netstat -tap | grep mysql

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

root@server1:~# netstat -tap | grep mysql  
tcp6 0 0 [::]:mysql [::]:* LISTEN 13796/mysqld  
root@server1:~#

7. Amavisd-new、SpamAssassin、および ClamAV のインストール

amavisd-new、SpamAssassin、および ClamAV をインストールするには、次のコマンドを実行します:

apt-get -y 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-perl postgrey

ISPConfig 3 のセットアップは、内部で SpamAssassin フィルターライブラリを読み込む amavisd-new を使用するため、RAM を解放するために SpamAssassin を停止できます:

service spamassassin stop  
update-rc.d -f spamassassin remove

ClamAV ウイルス対策シグネチャを更新し、Clamd サービスを開始します。更新プロセスには時間がかかる場合があるため、途中で中断しないでください。

service clamav-freshclam restart  
service clamav-daemon start

7.1 Metronome XMPP サーバーのインストール (オプション)

Metronome XMPP サーバーは、XMPP チャットサーバーを提供します。このステップはオプションであり、チャットサーバーが必要ない場合はこのステップをスキップできます。他の ISPConfig 機能はこのソフトウェアに依存していません。

次のパッケージを apt でインストールします。

apt-get -y install git lua5.1 liblua5.1-0-dev lua-filesystem libidn11-dev libssl-dev lua-zlib lua-expat lua-event lua-bitop lua-socket lua-sec luarocks luarocks
luarocks install lpc

Metronome 用のシェルユーザーを追加します。

adduser --no-create-home --disabled-login --gecos 'Metronome' metronome

Metronome を /opt ディレクトリにダウンロードしてコンパイルします。

cd /opt; git clone https://github.com/maranda/metronome.git metronome  
cd ./metronome; ./configure --ostype=debian --prefix=/usr  
make  
make install

Metronome は現在 /opt/metronome にインストールされました。

Share: X/Twitter LinkedIn

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

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