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

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

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

1. 前提条件

このチュートリアルでは、ホスト名 server1.example.com と IP アドレス 192.168.1.100、ゲートウェイ 192.168.1.1 をネットワーク構成に使用します。これらの設定はあなたの環境によって異なる場合があるため、適宜置き換えてください。さらに進む前に、このチュートリアルで説明されているように、Ubuntu 18.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 18.04 LTS _Bionic Beaver_ - Release amd64 (20180425.1)]/ bionic main restricted  
#deb cdrom:[Ubuntu-Server 18.04 LTS _Bionic Beaver_ - Release amd64 (20180425.1)]/ bionic 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/ bionic main restricted  
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic main restricted  
  
## 最終リリース後に生成された主要なバグ修正更新。  
deb http://de.archive.ubuntu.com/ubuntu/ bionic-updates main restricted  
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-updates main restricted  
  
## N.B. このリポジトリのソフトウェアは Ubuntu チームによって完全にサポートされていません。  
## また、universe のソフトウェアは Ubuntu セキュリティチームからのレビューや更新を受けません。  
deb http://de.archive.ubuntu.com/ubuntu/ bionic universe  
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic universe  
deb http://de.archive.ubuntu.com/ubuntu/ bionic-updates universe  
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-updates universe  
  
## N.B. このリポジトリのソフトウェアは Ubuntu チームによって完全にサポートされておらず、  
## 無料ライセンスの下にない可能性があります。  
## ソフトウェアの使用権について自分自身を満足させてください。  
## また、multiverse のソフトウェアは Ubuntu セキュリティチームからのレビューや更新を受けません。  
deb http://de.archive.ubuntu.com/ubuntu/ bionic multiverse  
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic multiverse  
deb http://de.archive.ubuntu.com/ubuntu/ bionic-updates multiverse  
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-updates multiverse  
  
## N.B. このリポジトリのソフトウェアは、  
## メインリリースに含まれるソフトウェアほど広範にテストされていない可能性がありますが、  
## 一部のアプリケーションの新しいバージョンが含まれており、便利な機能を提供する可能性があります。  
## また、backports のソフトウェアは Ubuntu セキュリティチームからのレビューや更新を受けません。  
deb http://de.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse  
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse  
  
## Canonical の 'partner' リポジトリからソフトウェアを追加するには、次の 2 行のコメントを解除してください。  
## このソフトウェアは Ubuntu の一部ではありませんが、Canonical および  
## 各ベンダーによって Ubuntu ユーザーへのサービスとして提供されています。  
# deb http://archive.canonical.com/ubuntu bionic partner  
# deb-src http://archive.canonical.com/ubuntu bionic partner  
  
deb http://security.ubuntu.com/ubuntu bionic-security main restricted  
# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted  
deb http://security.ubuntu.com/ubuntu bionic-security universe  
# deb-src http://security.ubuntu.com/ubuntu bionic-security universe  
deb http://security.ubuntu.com/ubuntu bionic-security multiverse  
# deb-src http://security.ubuntu.com/ubuntu bionic-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

送信および 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  
[...]  

注意: 「-o …. 」行の前の空白は重要です!

その後、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 で 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

MariaDB のパスワード認証方法をネイティブに設定し、後で PHPMyAdmin から root ユーザーとして接続できるようにします:

echo "update mysql.user set plugin = 'mysql_native_password' where user='root';" | mysql -u root

ファイル /etc/mysql/debian.cnf を編集し、MYSQL / MariaDB の root パスワードをそこに 2 回設定します。

nano /etc/mysql/debian.cnf

追加する必要がある MySQL root パスワードは、読み取り専用で表示され、この例ではパスワードは “howtoforge” です。

# Automatically generated for Debian scripts. DO NOT TOUCH!  
[client]  
host = localhost  
user = root  
password = howtoforge  
socket = /var/run/mysqld/mysqld.sock  
[mysql_upgrade]  
host = localhost  
user = root  
password = howtoforge  
socket = /var/run/mysqld/mysqld.sock  
basedir = /usr

次に、MariaDB を再起動します:

service mysql restart

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

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 12210/mysqld

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

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

apt-get -y install amavisd-new spamassassin clamav clamav-daemon 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 libdbd-mysql-perl

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

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

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

freshclam  
service clamav-daemon start

最初の freshclam の実行時に次のエラーは無視できます。

ERROR: /var/log/clamav/freshclam.log is locked by another process  
ERROR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log).

amavisd-new プログラムには、Ubuntu 18.04 に現在バグがあり、メールが Dkim で正しく署名されないことを防いでいます。次のコマンドを実行して amavisd-new をパッチします。

cd /tmp  
wget https://git.ispconfig.org/ispconfig/ispconfig3/raw/stable-3.1/helper_scripts/ubuntu-amavisd-new-2.11.patch  
cd /usr/sbin  
cp -pf amavisd-new amavisd-new_bak  
patch < /tmp/ubuntu-amavisd-new-2.11.patch

最後の ‘patch’ コマンドでエラーが発生した場合、Ubuntu がその問題をその後修正した可能性があるため、そのエラーは無視しても安全です。

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

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

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