サーバー設定 · 4 min read · Sep 11, 2025
完璧なサーバー - Ubuntu 18.04 (Bionic Beaver) と Apache, PHP, MySQL, PureFTPD, BIND, Postfix, Dovecot, ISPConfig 3.1
このチュートリアルでは、Apache 2.4、Postfix、Dovecot、Bind、PureFTPDを使用して、ISPConfig 3.1のインストールに備えたUbuntu 18.04 (Bionic Beaver) ウェブホスティングサーバーのインストールを示します。結果として得られるシステムは、Web、Mail、Mailinglist、DNS、FTPサーバーを提供します。
ISPConfigは、次のサービスをウェブブラウザを通じて構成できるウェブホスティングコントロールパネルです:ApacheまたはNginxウェブサーバー、Postfixメールサーバー、CourierまたはDovecot IMAP/POP3サーバー、MySQL、BINDまたはMyDNSネームサーバー、PureFTPd、SpamAssassin、ClamAVなど。このセットアップは、Apache(Nginxの代わりに)、BIND(MyDNSの代わりに)、Dovecot(Courierの代わりに)のインストールをカバーします。
1. 前提条件
このチュートリアルでは、ホスト名server1.example.com、IPアドレス192.168.1.100、ゲートウェイ192.168.1.1を使用します。これらの設定はあなたの環境によって異なる場合があるため、適宜置き換えてください。さらに進む前に、チュートリアルで説明されているように、Ubuntu 18.04の基本的な最小インストールが必要です。
このチュートリアルのコマンドは、root権限で実行する必要があります。各コマンドの前にsudoを追加しないようにするために、次のコマンドを実行してrootユーザーになります:
sudo -s2. /etc/apt/sources.listを編集し、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
## Major bug fix updates produced after the final release of the
## distribution.
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. 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/ 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. 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/ 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. 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/ bionic-backports main restricted universe multiverse
# deb-src http://de.archive.ubuntu.com/ubuntu/ bionic-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 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 updateaptパッケージデータベースを更新し、
apt-get upgrade最新の更新をインストールします(ある場合)。更新の一環として新しいカーネルがインストールされる場合は、その後システムを再起動する必要があります:
reboot3. デフォルトシェルを変更する
/bin/shは/bin/dashへのシンボリックリンクですが、/bin/bashが必要です。したがって、次のようにします:
dpkg-reconfigure dashUse dash as the default system shell (/bin/sh)? <– No
これを行わないと、ISPConfigのインストールが失敗します。
4. AppArmorを無効にする
AppArmorは、拡張セキュリティを提供するセキュリティ拡張(SELinuxに似ています)ですが、私の意見では、安全なシステムを構成するために必要ありません。通常、問題を引き起こすことが多いです(あるサービスが期待通りに動作しなかったために1週間トラブルシューティングを行った後、すべてが正常であることがわかり、AppArmorが問題を引き起こしていたことがわかることを考えてみてください)。したがって、これを無効にします(後でISPConfigをインストールしたい場合は必須です)。
次のようにして無効にできます:
service apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils5. システムクロックを同期する
物理サーバーを運用する場合、NTP(network time protocol)サーバーとシステムクロックを同期することは良いアイデアです。仮想サーバーを運用している場合は、このステップをスキップしてください。次のコマンドを実行するだけで、
apt-get -y install ntpシステム時間が常に同期されます。
6. Postfix、Dovecot、MariaDB、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を1つのコマンドでインストールできます:
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次の質問が表示されます:
General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com「システムメール名」には、server1.example.comやserver1.yourdomain.comのようなサブドメインを使用することが重要です。後でメールドメインとして使用したいドメイン(例:yourdomain.tld)ではありません。
次に、PostfixでTLS/SSLおよび送信ポートを開きます:
nano /etc/postfix/master.cf送信およびsmtpsセクションのコメントを外し、次のように行を追加します -o smtpd_client_restrictions=permit_sasl_authenticated,rejectを両方のセクションに追加し、それ以降はすべてコメントアウトします:
[...]
submission inet n - y - - 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 - y - - 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 restartMySQLがlocalhostだけでなくすべてのインターフェースでリッスンするようにしたいので、/etc/mysql/mariadb.conf.d/50-server.cnfを編集し、bind-address = 127.0.0.1の行をコメントアウトします:
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] <-- yMariaDBのパスワード認証方法をネイティブに設定し、後でPHPMyAdminに接続できるようにします:
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」です。「howtoforge」という単語を、mysql_secure_installationコマンドで設定したMySQLのrootユーザーのパスワードに置き換えてください。
# 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ネットワーキングが有効になっていることを確認します。次のコマンドを実行します:
netstat -tap | grep mysql出力は次のようになります:
root@server1:~# netstat -tap | grep mysql
tcp6 0 0 [::]:mysql [::]:* LISTEN 30591/mysqld
root@server1:~#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 libdbd-mysql-perl postgreyISPConfig 3のセットアップでは、amavisdが内部でSpamAssassinフィルターライブラリをロードするため、RAMを解放するためにSpamAssassinを停止できます:
service spamassassin stop
update-rc.d -f spamassassin removeClamAVを起動するには:
freshclam
service clamav-daemon startfreshclamの最初の実行時に次のエラーは無視できます。
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 luarocksluarocks install lpcMetronome用のシェルユーザーを追加します。
adduser --no-create-home --disabled-login --gecos 'Metronome' metronome/optディレクトリにMetronomeをダウンロードし、コンパイルします。
cd /opt; git clone https://github.com/maranda/metronome.git metronome
cd ./metronome; ./configure --ostype=debian --prefix=/usr
make
make installMetronomeは現在/opt/metronomeにインストールされました。
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。