サーバー管理 · 3 min read · Jan 31, 2026

CentOS 6.4におけるPureFTPdとMySQLを用いた仮想ホスティング(クォータおよび帯域幅管理を含む)

CentOS 6.4におけるPureFTPdとMySQLを用いた仮想ホスティング(クォータおよび帯域幅管理を含む)

バージョン 1.0
著者: Falko Timme
Twitterでフォローしてください

この文書では、実際のシステムユーザーの代わりにMySQLデータベースからの仮想ユーザーを使用するPureFTPdサーバーのインストール方法を説明します。これははるかにパフォーマンスが高く、単一のマシンで数千のFTPユーザーを持つことができます。さらに、このセットアップでのクォータおよびアップロード/ダウンロード帯域幅制限の使用方法も示します。パスワードはMD5文字列としてデータベースに暗号化されて保存されます。

MySQLデータベースの管理には、phpMyAdminのようなWebベースのツールを使用できます。このhowtoでもphpMyAdminがインストールされます。phpMyAdminは快適なグラフィカルインターフェースであり、コマンドラインをいじる必要はありません。

このチュートリアルはCentOS 6.4に基づいています。基本的なCentOS 6.4システムをすでにセットアップしている必要があります。たとえば、このチュートリアルの最初の6章に記載されているように: 完璧なサーバー - CentOS 6.4 x86_64 (Apache2, Dovecot, ISPConfig 3)

このhowtoは実用的なガイドとして意図されており、理論的な背景はカバーしていません。それらはWeb上の他の多くの文書で扱われています。

この文書は一切の保証なしで提供されます!これはそのようなシステムを設定する唯一の方法ではないことを言いたいです。この目標を達成する方法はたくさんありますが、これは私が取る方法です。これがあなたにとって機能するという保証はありません!

1 前書き

このチュートリアルでは、ホスト名server1.example.comとIPアドレス192.168.0.100を使用します。これらの設定はあなたの環境によって異なる場合があるため、適切な場所で置き換える必要があります。

2 MySQLとphpMyAdminのインストール

まず、CentOSシステムでEPELリポジトリを有効にします。これは、このチュートリアルの過程でインストールするいくつかのパッケージが公式のCentOS 6.4リポジトリには存在しないためです:

rpm --import https://fedoraproject.org/static/0608B895.txt  
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm  
rpm -ivh epel-release-6-8.noarch.rpm
yum install yum-priorities

/etc/yum.repos.d/epel.repoを編集します…

vi /etc/yum.repos.d/epel.repo

…そして、[epel]セクションにpriority=10の行を追加します:

| [epel] name=Extra Packages for Enterprise Linux 6 - $basearch #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 priority=10 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 [...] |

これで、次のようにMySQLとphpMyAdminをインストールできます:

yum install mysql mysql-server phpMyAdmin httpd

その後、/etc/httpd/conf.d/phpMyAdmin.confファイルを編集して、すべてのIPアドレスからphpMyAdminにアクセスできるようにします。デフォルトでは、127.0.0.1からのみアクセス可能です。このセクションをコメントアウトします:

#  
#   Order Deny,Allow  
#   Deny from All  
#   Allow from 127.0.0.1  
#   Allow from ::1  
#

ファイルが次のようになるようにします:

vi /etc/httpd/conf.d/phpMyAdmin.conf

| # phpMyAdmin - Web based MySQL browser written in php # # Allows only localhost by default # # But allowing phpMyAdmin to anyone other than localhost should be considered # dangerous unless properly secured by SSL Alias /phpMyAdmin /usr/share/phpMyAdmin Alias /phpmyadmin /usr/share/phpMyAdmin # # Order Deny,Allow # Deny from All # Allow from 127.0.0.1 # Allow from ::1 # Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 # These directories do not require access over HTTP - taken from the original # phpMyAdmin upstream tarball # Order Deny,Allow Deny from All Allow from None Order Deny,Allow Deny from All Allow from None Order Deny,Allow Deny from All Allow from None # This configuration prevents mod_security at phpMyAdmin directories from # filtering SQL etc. This may break your mod_security implementation. # # # # SecRuleInheritance Off # # |

次に、MySQLとApacheのシステム起動リンクを作成します(システムが起動するたびに両方が自動的に開始されるように)し、両方のサービスを開始します:

chkconfig --levels 235 mysqld on  
/etc/init.d/mysqld start
chkconfig --levels 235 httpd on  
/etc/init.d/httpd start

MySQLユーザーrootのパスワードを作成します(yourrootsqlpasswordを使用したいパスワードに置き換えます):

mysql_secure_installation

[root@server1 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

MySQLにログインしてセキュリティを確保するためには、rootユーザーの現在のパスワードが必要です。
MySQLをインストールしたばかりで、まだrootパスワードを設定していない場合、パスワードは空白になりますので、ここではそのままEnterを押してください。

Enter current password for root (enter for none): <– ENTER
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] <– ENTER
New password: <– yourrootsqlpassword
Re-enter new password: <– yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] <– ENTER
… Success!

Normally, root should only be allowed to connect from ‘localhost’.
This ensures that someone cannot guess at the root password from
the network.

Disallow root login remotely? [Y/n] <– ENTER
… Success!

By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] <– ENTER

  • Dropping test database…
    … Success!
  • Removing privileges on test database…
    … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] <– ENTER
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

[root@server1 ~]#

3 MySQLサポート付きPureFTPdのインストール

CentOSのPureFTPdパッケージは、MySQL、PostgreSQL、LDAPなどのさまざまなバックエンドをサポートしています。したがって、通常のPureFTPdパッケージをインストールするだけで済みます:

yum install pure-ftpd

次に、すべての仮想ユーザーがマッピングされるftpグループ(ftpgroup)とユーザー(ftpuser)を作成します。グループIDとユーザーID2001を、システムで空いている番号に置き換えます:

groupadd -g 2001 ftpgroup  
useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftpgroup ftpuser

4 PureFTPd用のMySQLデータベースの作成

次に、pureftpdという名前のデータベースと、PureFTPdデーモンが後でpureftpdデータベースに接続するために使用するpureftpdという名前のMySQLユーザーを作成します:

mysql -u root -p
CREATE DATABASE pureftpd;  
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pureftpd'@'localhost' IDENTIFIED BY 'ftpdpass';  
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pureftpd'@'localhost.localdomain' IDENTIFIED BY 'ftpdpass';  
FLUSH PRIVILEGES;

ftpdpassという文字列を、MySQLユーザーpureftpdに使用したいパスワードに置き換えます。MySQLシェル内で、必要なデータベーステーブルを作成します(はい、テーブルは1つだけです!):

USE pureftpd;
CREATE TABLE ftpd (  
User varchar(16) NOT NULL default '',  
status enum('0','1') NOT NULL default '0',  
Password varchar(64) NOT NULL default '',  
Uid varchar(11) NOT NULL default '-1',  
Gid varchar(11) NOT NULL default '-1',  
Dir varchar(128) NOT NULL default '',  
ULBandwidth smallint(5) NOT NULL default '0',  
DLBandwidth smallint(5) NOT NULL default '0',  
comment tinytext NOT NULL,  
ipaccess varchar(15) NOT NULL default '*',  
QuotaSize smallint(5) NOT NULL default '0',  
QuotaFiles int(11) NOT NULL default 0,  
PRIMARY KEY (User),  
UNIQUE KEY User (User)  
) ENGINE=MyISAM;
quit;

ご覧の通り、quit;コマンドでMySQLシェルを終了し、Linuxシェルに戻りました。

ちなみに(あなたのFTPサーバーシステムのホスト名がserver1.example.comであると仮定しています)、ブラウザでhttp://server1.example.com/phpMyAdmin/にアクセスし、ユーザーpureftpdとしてログインできます。次に、データベースを確認できます。後でphpMyAdminを使用してPureFTPdサーバーを管理できます。

Share: X/Twitter LinkedIn

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

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