nullpopopoでタグ「mysql」が付けられているもの

とっくにあけきりましてオメデトウ御座います。 (っ´∀`)っ ゃー でございます。
久々に記事書こうとしたら、このblogのIDとパスワードをセットで忘れてしまいまして本当に焦りました。なので次の方法で思い出したわけで、まあ、次忘れたときのためにメモろうかと。

1) MySQLにログインする

$ mysql -h <DB_SERVER> -u <USERNAME> -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 226404
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


2) Movable Typeのデータベースに入る

mysql> use <DATABASE_NAME>;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed


3) mt_authorのテーブルをselectする

mysql> select author_email,author_name,author_nickname,author_password,author_hint from mt_author;
+------------------------+-------------+-------------------------+-----------------+--------------+
| author_email           | author_name | author_nickname         | author_password | author_hint  |
+------------------------+-------------+-------------------------+-----------------+--------------+
| hoge@example.com       | hoge        | (っ´∀`)っ ゃー       | OXeT67r/BsJDf   | 再設定~~   |
+------------------------+-------------+-------------------------+-----------------+--------------+


少なくとも、自分が author_email に設定されたメールを読める環境であれば、 author_hint に設定された再設定用キーワードをブラウザから入力してやれば、リセットされたパスワードをメールで受け取ることができます。さすがに auther_password では生PWは表示されないので、今回は例示用にselectしてみたけど、見るだけ虚しいので別に表示しなくてよいですw

author_name はログイン時に入力するIDのことで、 author_nickname は記事投稿時に表示される自分の名前です。ここで大事なのは author_nickname ですが、ほんとにこれ自分のIDなの?と確認するためにも、ニックネームは表示したほうがよいかも。
こんちわ、久々に登場 (っ´∀`)っ ゃー です。このたび引越することになったので、自宅サーバにあるコンテンツを安いVPSへ引越することにしました。移行先の管理はほとんどPLESKでできるので便利です。パッケージのインストールはコマンドラインから行うものの、ゾーン作成やバーチャルホスト作成はすべてブラウザでの作業です。

■■ 旧環境コンテンツバックアップ

あらかじめ、旧環境のコンテンツとDBをバックアップします。コンテンツは、ドキュメントルート以下をtar.gzで固めて新サーバへSCPします。DBはMySQLを使っているので、以下のようにしてダンプをとります。

$ mysqldump -u root -p 【データベース名】 > blogs.sql


■■ バーチャルホスト作成

PLESKにログイン → ログイン後のメニューから
ドメイン → Add New Domain
をクリックする

My Domains
をクリックする

Domain name    blogcube.info
        (wwwにチェックを入れる)

Proceed to hosting setup  にチェックを入れ、OKをクリックする

Warning: The domain resolves to another IP address (43.244.34.199). Please correct DNS settings.
というメッセージが出るが、まだネームサーバの移行をしていないために表示されるものなので気にしない。


Hosting type     Physical hosting

OK


SSLサポート    なし
FTPログイン    admin
PW        ********
quota        Unlimited
shell        /bin/bash

以下にチェックを入れる
SSI support
PHP support    safeモードのチェックははずす
CGI support
Perl support
Python support
FastCGI support
Web statistics    Webalizer

OK


■■ DB作成

PLESKから
ドメイン → blogcube.info → Databases → Add new database
の順にクリックする

Database name    blogs
OK

Database name というアイコンができるのでクリックし、ユーザを作る


■■ blogcubeのコンテンツとダンプしたDBを持ってくる

[root@hogehoge ~]# cd /var/www/vhosts/blogcube.info/private
[root@hogehoge private]# scp admin@43.244.34.199:/home/admin/admin.* ./
[root@hogehoge private]# chown admin. admin.*


■■ コンテンツを解凍する

[root@hogehoge private]# tar xvzf blogs.tar.gz
[root@hogehoge private]# chown -R admin. blogs


■■ 解凍したコンテンツをコピーする

[root@hogehoge private]# cd ../httpdocs/
[root@hogehoge httpdocs]# cp -pr ../private/blogs/* ./


■■ CGIをcgi-binディレクトリに移す

[root@hogehoge httpdocs]# cp -p *.cgi ../cgi-bin/


■■ mt-config.cgi を修正する

旧環境では、ドキュメントルート以下のどこでもCGIが使えましたが、今借りているVPSではcgi-binディレクトリが別にあるので、mt-config.cgiのCGIPathを書き換えてやる必要があります。

[root@hogehoge httpdocs]# cp -p mt-config.cgi mt-config.cgi.20080320
[root@hogehoge httpdocs]# vi mt-config.cgi

ここを
CGIPath    http://www.blogcube.info/

こうする
CGIPath    http://www.blogcube.info/cgi-bin/


[root@hogehoge httpdocs]# diff mt-config.cgi mt-config.cgi.20080320
17c17
< CGIPath    http://www.blogcube.info/cgi-bin/
---
> CGIPath    http://www.blogcube.info/


■■ mt-check.cgi を見ながら足りないモジュールをインストールする

HOSTSを書いてから
http://www.blogcube.info/cgi-bin/mt-check.cgi
にアクセスし、足りないモジュールを追加する。


■ Image::Size

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-Image-Size

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-Image-Size         noarch     3.1.1-1.el4.rf   rpmforge           40 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 40 k
Is this ok [y/N]: y


■ SOAP::Lite (version >= 0.5)

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-SOAP-Lite

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-SOAP-Lite          noarch     0.71-1.el4.rf    rpmforge          426 k
Installing for dependencies:
 perl-Authen-SASL        noarch     2.10-1.el4.rf    rpmforge           41 k
 perl-GSSAPI             x86_64     0.26-1.el4.rf    rpmforge          120 k
 perl-MIME-Lite          noarch     3.021-1.el4.rf   rpmforge           94 k
 perl-MailTools          noarch     2.02-1.el4.rf    rpmforge           98 k
 perl-Net-Jabber         noarch     2.0-1.2.el4.rf   rpmforge          124 k
 perl-Net-XMPP           noarch     1.02-1.el4.rf    rpmforge          126 k
 perl-XML-Stream         noarch     1.22-1.2.el4.rf  rpmforge           77 k

Transaction Summary
=============================================================================
Install      8 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.1 M
Is this ok [y/N]: y


■ Image::Magick

[root@hogehoge ~]# yum --enablerepo=rpmforge install ImageMagick-perl

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 ImageMagick-perl        x86_64     6.2.8.0-3.el5.4  base              146 k
Installing for dependencies:
 GConf2                  x86_64     2.14.0-9.el5     base              1.5 M
 ImageMagick             x86_64     6.2.8.0-3.el5.4  base              3.3 M
 ORBit2                  x86_64     2.14.3-4.el5     base              262 k
 audiofile               x86_64     1:0.2.6-5        base              107 k
 avahi                   x86_64     0.6.16-1.el5     base              256 k
 avahi-glib              x86_64     0.6.16-1.el5     base               14 k
 chkfontpath             x86_64     1.10.1-1.1       base               15 k
 cryptsetup-luks         x86_64     1.0.3-2.2.el5    base              619 k
 dbus-glib               x86_64     0.70-5           base              154 k
 dbus-python             x86_64     0.70-7.el5       base              187 k
 esound                  x86_64     1:0.2.36-3       base              130 k
 gamin                   x86_64     0.1.7-8.el5      base              126 k
 ghostscript             x86_64     8.15.2-9.1.el5_1.1  updates           5.9 M
 ghostscript-fonts       noarch     5.50-13.1.1      base              801 k
 gnome-keyring           x86_64     0.6.0-1.fc6      base              166 k
 gnome-mime-data         x86_64     2.4.2-3.1        base              691 k
 gnome-mount             x86_64     0.5-3.el5        base               70 k
 gnome-vfs2              x86_64     2.16.2-4.el5     base              1.3 M
 hal                     x86_64     0.5.8.1-25.el5_1.1  updates           362 k
 hwdata                  noarch     0.211-1          base              278 k
 kbd                     x86_64     1.12-19.el5      base              1.0 M
 lcms                    x86_64     1.15-1.2.2       base              170 k
 libFS                   x86_64     1.0.0-3.1        base               30 k
 libIDL                  x86_64     0.8.7-1.fc6      base               87 k
 libXfont                x86_64     1.2.2-1.0.3.el5_1  updates           246 k
 libXres                 x86_64     1.0.1-3.1        base               14 k
 libbonobo               x86_64     2.16.0-1.fc6     base              521 k
 libbonoboui             x86_64     2.16.0-1.fc6     base              394 k
 libcroco                x86_64     0.6.1-2.1        base              129 k
 libdaemon               x86_64     0.10-5.el5       base               24 k
 libfontenc              x86_64     1.0.2-2.2.el5    base               19 k
 libglade2               x86_64     2.6.0-2          base               96 k
 libgnome                x86_64     2.16.0-6.el5     base              860 k
 libgnomecanvas          x86_64     2.14.0-4.1       base              224 k
 libgnomeui              x86_64     2.16.0-5.el5     base              984 k
 libgsf                  x86_64     1.14.1-6.1       base              113 k
 libnotify               x86_64     0.4.2-6.el5      base               38 k
 librsvg2                x86_64     2.16.1-1.el5     base              178 k
 libvolume_id            x86_64     095-14.9.el5     base               37 k
 libwmf                  x86_64     0.2.8.4-10.1     base              821 k
 libwnck                 x86_64     2.16.0-4.fc6     base              185 k
 notification-daemon     x86_64     0.3.5-8.el5      base               48 k
 pciutils                x86_64     2.2.3-4          base               79 k
 pm-utils                x86_64     0.99.3-6.el5.centos.17  base              131 k
 shared-mime-info        x86_64     0.19-3.el5       base              148 k
 startup-notification    x86_64     0.8-4.1          base               32 k
 ttmkfdir                x86_64     3.0.9-23.el5     base               46 k
 urw-fonts               noarch     2.3-6.1.1        base              4.5 M
 xorg-x11-font-utils     x86_64     1:7.1-2          base               77 k
 xorg-x11-xfs            x86_64     1:1.0.2-4        base               73 k

Transaction Summary
=============================================================================
Install     51 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 28 M
Is this ok [y/N]: y


■ Crypt::DSA

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-Crypt-DSA

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-Crypt-DSA          noarch     0.14-1.el4.rf    rpmforge           35 k
Installing for dependencies:
 perl-Convert-ASN1       noarch     0.20-1.1         base               42 k
 perl-Convert-PEM        noarch     0.07-1.2.el4.rf  rpmforge           19 k
 perl-Data-Buffer        noarch     0.04-1.2.el4.rf  rpmforge           13 k

Transaction Summary
=============================================================================
Install      4 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 109 k
Is this ok [y/N]: y


■ XML::Atom

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-XML-Atom

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-XML-Atom           noarch     0.23-1.el4.rf    rpmforge           46 k
Installing for dependencies:
 perl-Class-Singleton    x86_64     1.03-1.2.el4.rf  rpmforge           14 k
 perl-DateTime           x86_64     0.42-1.el4.rf    rpmforge          127 k
 perl-DateTime-Locale    noarch     0.35-1.el4.rf    rpmforge          144 k
 perl-DateTime-TimeZone  noarch     0.6904-1.el4.rf  rpmforge          397 k
 perl-Params-Validate    x86_64     0.89-1.el4.rf    rpmforge          107 k

Transaction Summary
=============================================================================
Install      6 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 836 k
Is this ok [y/N]: y


[root@hogehoge ~]# yum install perl-XML-Parser

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-XML-Parser         x86_64     2.34-6.1.2.2.1   base              210 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 210 k
Is this ok [y/N]: y


[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-XML-XPath

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-XML-XPath          noarch     1.13-2.2.el4.rf  rpmforge           81 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 81 k
Is this ok [y/N]: y


■ Cache::Memcached

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-Cache-Memcached

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-Cache-Memcached    noarch     1.24-1.el4.rf    rpmforge           26 k
Installing for dependencies:
 perl-String-CRC32       x86_64     1.4-2.fc6        base               13 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 39 k
Is this ok [y/N]: y


■ IO::Compress::Gzip

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-PerlIO-gzip

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-PerlIO-gzip        x86_64     0.18-1.el4.rf    rpmforge           44 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 44 k
Is this ok [y/N]: y


[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-IO-Compress-Base

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-IO-Compress-Base   noarch     2.008-1.el4.rf   rpmforge           54 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 54 k
Is this ok [y/N]: y


■ IO::Compress::Gzip IO::Uncompress::Gunzip

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-IO-Compress-Zlib

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-IO-Compress-Zlib   noarch     2.008-1.el4.rf   rpmforge          137 k
Installing for dependencies:
 perl-Compress-Raw-Zlib  x86_64     2.008-1.el4.rf   rpmforge          171 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 308 k
Is this ok [y/N]: y


■ Archive::Zip

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-Archive-Zip

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-Archive-Zip        noarch     1.23-1.el4.rf    rpmforge          112 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 112 k
Is this ok [y/N]: y


■ XML::SAX

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-XML-SAX

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-XML-SAX            noarch     0.16-1.el4.rf    rpmforge           77 k
Installing for dependencies:
 perl-XML-NamespaceSupport  noarch     1.09-1.2.1       base               15 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 93 k
Is this ok [y/N]: y


■ Mail::Sendmail

[root@hogehoge ~]# yum --enablerepo=rpmforge install perl-Mail-Sendmail

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 perl-Mail-Sendmail      noarch     0.79-1.2.el4.rf  rpmforge           23 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 23 k
Is this ok [y/N]: y


これで全てOK


■■ プラグインなどをcgi-binにコピー

[root@hogehoge ~]# cd /var/www/vhosts/blogcube.info/httpdocs
[root@hogehoge httpdocs]# cp -rp ./`ls -lA | egrep ^d | awk '{print $9}' | egrep -v '(test|nullpopopo|revenge)'` ../cgi-bin/


■■ mt-config.cgi を修正する

ここを
CGIPath    http://www.blogcube.info/

こうする
CGIPath    http://www.blogcube.info/cgi-bin/


■■ エラー修正

/var/www/vhosts/blogcube.info/statistics/logs/error_log をtailしていると
[Wed Mar 19 23:51:09 2008] [error] [client 43.244.34.199] Premature end of script headers: mt.cgi
[Wed Mar 19 23:51:27 2008] [error] [client 43.244.34.199] Premature end of script headers: mt-config.cgi
と表示される。

なので、
[root@hogehoge cgi-bin]# cd ..
[root@hogehoge blogcube.info]# chmod 755 cgi-bin

そして、プログラムが書き込みを行えるように
[root@hogehoge blogcube.info]# chmod 777 httpdocs/


■■ ブログを作成する

http://www.blogcube.info/cgi-bin/mt.cgi


■■ まだ今までのブログが見えないので、sqlを流し込む

[root@hogehoge blogcube.info]# cd private/
[root@hogehoge private]# mysql -u blogs -p blogs < blogs.sql


■■ リンクテスト

ひととおり、ダッシュボードのリンクをクリックして問題ないことを確認した


■■ サブドメイン作成

PLESKから、サブドメインを作成する。作るのは以下のもの。

revenge
nullpopopo


■ サブドメインから余計なものを削除する

[root@hogehoge ~]# rm -fr /var/www/vhosts/blogcube.info/subdomains/revenge/httpdocs/*
[root@hogehoge ~]# rm -fr /var/www/vhosts/blogcube.info/subdomains/nullpopopo/httpdocs/*


■ サブドメインのディレクトリにコンテンツをコピーする

[root@hogehoge ~]# cp -pr /var/www/vhosts/blogcube.info/httpdocs/revenge/* /var/www/vhosts/blogcube.info/subdomains/revenge/httpdocs/
[root@hogehoge ~]# cp -pr /var/www/vhosts/blogcube.info/httpdocs/nullpopopo/* /var/www/vhosts/blogcube.info/subdomains/nullpopopo/httpdocs/


■■ サイトパスを変更する

それぞれのブログごとに、サイトパスを変更後、再構築をする。

■ nullpopopo

old    /home/admin/public_html/blogcube/nullpopopo/
new    /var/www/vhosts/blogcube.info/subdomains/nullpopopo/httpdocs/


■ revenge

old    /home/admin/public_html/blogcube/revenge/
new    /var/www/vhosts/blogcube.info/subdomains/revenge/httpdocs/


■ www

old    /home/admin/public_html/blogcube
new    /var/www/vhosts/blogcube.info/httpdocs


■■ 更新テスト

更新先のほうで、エントリを投稿し、hostsを書いたブラウザから見て反映されていて、かつ、hostsをコメントアウトしたら更新が反映されなくなることを確認する。


■■ ネームサーバ移転

バリュードメインで、ネームサーバをVPSサーバに向ける。そして、旧サーバからblogcube.infoのゾーンを削除し、再度ブラウザで確認する。

以上、終了。

proftpdのアカウント管理をMySQLでやってみました。
今回、MySQLは5系を使いたかったので、phpと同様、 centosplus リポジトリからインストールしました。
なお、今回インストールする proftpd のパッケージは、SRPMから自分で作成しますので、
あらかじめ rpm-build を導入しておいてください。


■■ rpm-build インストール

[root@hoge ~]# yum install rpm-build
(中略)
Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 rpm-build               i386       4.3.3-23_nonptl  base              458 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 458 k
Is this ok [y/N]: y


■■ nullpopopo(管理ユーザ)のrpmビルド環境を作る

rpmのビルドは「必ず」一般ユーザで行います。なので、一般ユーザのホームディレクトリの下に
rpmディレクトリと .rpmmacros ファイルを作成してください。

[root@hoge ~]# su - nullpopopo
[nullpopopo@hoge ~]$ vi .rpmmacros
%_topdir                %(echo $HOME)/rpm
%_builddir              %{_topdir}/BUILD
%_rpmdir                %{_topdir}/RPMS
%_sourcedir             %{_topdir}/SOURCES
%_specdir               %{_topdir}/SPECS
%_srcrpmdir             %{_topdir}/SRPMS

[nullpopopo@hoge ~]$ mkdir -p rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS}


■■ MySQLサーバのインストール

[root@hoge ~]# yum --enablerepo=centosplus install mysql-server mysql-devel mysqlclient10 mysqlclient10-devel php-mysql
(中略)
Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 mysql-devel             i386       5.0.54-1.el4.centos  centosplus        2.8 M
 mysql-server            i386       5.0.54-1.el4.centos  centosplus        9.6 M
 mysqlclient10           i386       3.23.58-9.2.c4   centosplus        238 k
 mysqlclient10-devel     i386       3.23.58-9.2.c4   centosplus         48 k
 php-mysql               i386       5.1.6-3.el4s1.8  centosplus         77 k
Installing for dependencies:
 e2fsprogs-devel         i386       1.35-12.11.el4_6.1  update            487 k
 krb5-devel              i386       1.3.4-54         base              824 k
 mysql                   i386       5.0.54-1.el4.centos  centosplus        2.8 M
 mysql-libs              i386       5.0.54-1.el4.centos  centosplus        1.8 M
 openssl-devel           i586       0.9.7a-43.17.el4_6.1  base              1.6 M
 perl-Compress-Zlib      i386       1.42-1.el4       centosplus         54 k
 perl-DBD-MySQL          i386       3.0008-1.el4.centos  centosplus        145 k
 perl-DBI                i386       1.54-1.el4s1     centosplus        673 k
 perl-HTML-Parser        i386       3.35-6           base               82 k
 perl-HTML-Tagset        noarch     3.03-30          base               12 k
 perl-URI                noarch     1.30-4           base               79 k
 perl-libwww-perl        noarch     5.805-1.1.1      centosplus        371 k
 php-pdo                 i386       5.1.6-3.el4s1.8  centosplus        220 k
 zlib-devel              i386       1.2.1.2-1.2      base               89 k
Updating for dependencies:
 perl                    i386       4:5.8.8-5.el4s1_2  centosplus         11 M

Transaction Summary
=============================================================================
Install     19 Package(s)
Update       1 Package(s)
Remove       0 Package(s)
Total download size: 33 M
Is this ok [y/N]: y


■■ MySQLの起動

■ MySQLの起動

[root@hoge ~]# /etc/init.d/mysqld start
Initializing MySQL database:                               [  OK  ]
Starting MySQL:                                            [  OK  ]


■ 自動起動設定


[root@hoge ~]# chkconfig mysqld --list
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@hoge ~]# chkconfig mysqld on

[root@hoge ~]# chkconfig mysqld --list
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off


■■ MySQL Rootパスワードの設定

■ まずはデフォルトのユーザとパスワードを確認する

[nullpopopo@hoge ~]$ mysql -h localhost -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.54 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host,password from mysql.user;
+------+------------------+----------+
| user | host             | password |
+------+------------------+----------+
| root | localhost        |          |
| root | hoge.example.com |          |
| root | 127.0.0.1        |          |
|      | localhost        |          |
|      | hoge.example.com |          |
+------+------------------+----------+
5 rows in set (0.00 sec)


■ rootのパスワードを設定する

mysql> set password for root@localhost=password('root_password');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@127.0.0.1=password('root_password');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@hoge.example.com=password('root_password');
Query OK, 0 rows affected (0.00 sec)


■ パスワードがかかったことを確認する

mysql> select user,host,password from mysql.user;
+------+------------------+------------------+
| user | host             | password         |
+------+------------------+------------------+
| root | localhost        | 3cfeabb26241321d |
| root | hoge.example.com | 3cfeabb26241321d |
| root | 127.0.0.1        | 3cfeabb26241321d |
|      | localhost        |                  |
|      | hoge.example.com |                  |
+------+------------------+------------------+
5 rows in set (0.01 sec)


■ 匿名ユーザを削除する

mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;
+------+------------------+------------------+
| user | host             | password         |
+------+------------------+------------------+
| root | localhost        | 3cfeabb26241321d |
| root | hoge.example.com | 3cfeabb26241321d |
| root | 127.0.0.1        | 3cfeabb26241321d |
+------+------------------+------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye


■ パスワードつきのrootユーザでログインできることを確認する

[nullpopopo@hoge ~]$ mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.54 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.01 sec)

mysql> quit
Bye


[nullpopopo@hoge ~]$ mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.54 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye


[nullpopopo@hoge ~]$ mysql -h hoge.example.com -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.54 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye


■■ MySQL ライブラリの設定

■ 設定ファイルに追記

[root@hoge ~]# cp -p /etc/ld.so.conf /etc/ld.so.conf.orig
[root@hoge ~]# vi /etc/ld.so.conf
ここを
include ld.so.conf.d/*.conf

こうする
include ld.so.conf.d/*.conf
/usr/lib/mysql


■ 設定反映

[root@hoge ~]# ldconfig


■■ ProFTPD インストール

■ ProFTPDのインストールに必要なパッケージをインストールする

[nullpopopo@hoge SRPMS]$ su -
[root@hoge ~]# yum install pam-devel ncurses-devel pkgconfig gcc-c++ openldap-devel libacl-devel postgresql-devel
(中略)
Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 gcc-c++                 i386       3.4.6-9          base              2.4 M
 libacl-devel            i386       2.2.23-5.3.el4   base               78 k
 ncurses-devel           i386       5.4-15.el4       base              1.4 M
 openldap-devel          i386       2.2.13-8.el4_6.2  update            1.3 M
 pam-devel               i386       0.77-66.23       base               85 k
 pkgconfig               i386       1:0.15.0-3       base               47 k
 postgresql-devel        i386       7.4.19-1.el4_6.1  update            1.0 M
Installing for dependencies:
 cyrus-sasl-devel        i386       2.1.19-14        base              1.3 M
 libattr-devel           i386       2.4.16-3.1.el4   base               28 k
 libstdc++-devel         i386       3.4.6-9          base              8.6 M
 postgresql              i386       7.4.19-1.el4_6.1  update            2.0 M
 postgresql-libs         i386       7.4.19-1.el4_6.1  update            147 k

Transaction Summary
=============================================================================
Install     12 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 18 M
Is this ok [y/N]: y


■ パッケージのダウンロード

[root@hoge ~]# logout
[nullpopopo@hoge ~]$ cd rpm/SRPMS/
[nullpopopo@hoge SRPMS]$ wget http://apt.sw.be/redhat/el4/en/i386/SRPMS.dag/proftpd-1.2.10-10.rf.src.rpm
[nullpopopo@hoge SRPMS]$ rpm -ivh proftpd-1.2.10-10.rf.src.rpm

warning: group dag does not exist - using root
warning: user dag does not exist - using root
は気にしない

[nullpopopo@hoge SRPMS]$ cd ../SPECS/
[nullpopopo@hoge SPECS]$ rpmbuild -ba proftpd.spec --with mysql
[nullpopopo@hoge SPECS]$ rpm -ivh --test ../RPMS/i386/proftpd-1.2.10-10.rf.i386.rpm
[nullpopopo@hoge SPECS]$ su
[root@hoge SPECS]# rpm -ivh ../RPMS/i386/proftpd-1.2.10-10.rf.i386.rpm
Preparing...                ########################################### [100%]
   1:proftpd                ########################################### [100%]


[root@hoge SPECS]# /usr/sbin/proftpd -l
Compiled-in modules:
  mod_core.c
  mod_xfer.c
  mod_auth_unix.c
  mod_auth_file.c
  mod_auth.c
  mod_ls.c
  mod_log.c
  mod_site.c
  mod_readme.c
  mod_auth_pam.c
  mod_sql.c
  mod_sql_mysql.c
  mod_tls.c
  mod_cap.c

[root@hoge SPECS]# /usr/sbin/proftpd -vv
 - ProFTPD Version: 1.2.10 (stable)
 -   Scoreboard Version: 01040002
 -   Built: Mon Feb 11 17:33:48 JST 2008
 -     Module: mod_core.c
 -     Module: mod_xfer.c
 -     Module: mod_auth_unix.c
 -     Module: mod_auth_file.c
 -     Module: mod_auth.c
 -     Module: mod_ls.c
 -     Module: mod_log.c
 -     Module: mod_site.c
 -     Module: mod_readme.c
 -     Module: mod_auth_pam.c
 -     Module: mod_sql.c
 -     Module: mod_sql_mysql.c
 -     Module: mod_tls.c
 -     Module: mod_cap/1.0


[root@hoge SPECS]# ldd /usr/sbin/proftpd
        libcrypt.so.1 => /lib/libcrypt.so.1 (0x0084d000)
        libssl.so.4 => /lib/libssl.so.4 (0x00a5d000)
        libcrypto.so.4 => /lib/libcrypto.so.4 (0x008f4000)
        libm.so.6 => /lib/tls/libm.so.6 (0x00806000)
        libz.so.1 => /usr/lib/libz.so.1 (0x0083b000)
        libmysqlclient.so.15 => /usr/lib/mysql/libmysqlclient.so.15 (0x00111000)
        libpam.so.0 => /lib/libpam.so.0 (0x00a93000)
        libc.so.6 => /lib/tls/libc.so.6 (0x006d2000)
        libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x009e0000)
        libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x009f6000)
        libcom_err.so.2 => /lib/libcom_err.so.2 (0x0082b000)
        libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x008d1000)
        libresolv.so.2 => /lib/libresolv.so.2 (0x0087d000)
        libdl.so.2 => /lib/libdl.so.2 (0x00800000)
        /lib/ld-linux.so.2 (0x006b8000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x00892000)
        libaudit.so.0 => /lib/libaudit.so.0 (0x008ab000)

mod_sql.c と mod_sql_mysql.c がモジュールに組み込まれ、 libmysqlclient.so.15 がリンクされてるのでOK。

[root@hoge SPECS]# exit
[nullpopopo@hoge SPECS]$ su -
Password:
[root@hoge ~]#


■ ProFTPD 1.2.10 自動起動設定

[root@hoge ~]# chkconfig proftpd on
[root@hoge ~]# chkconfig proftpd --list
proftpd         0:off   1:off   2:on    3:on    4:on    5:on    6:off


■ MySQL ProFTPD用データベースの作成

[root@hoge ~]# mkdir /etc/proftpd
[root@hoge ~]# cd /etc/proftpd
[root@hoge proftpd]# vi proftpd.schema
CREATE TABLE groups (
    groupname VARCHAR(30) NOT NULL ,
    gid SMALLINT(5) UNSIGNED NOT NULL DEFAULT 1000,
    members varchar(255) default NULL,
    PRIMARY KEY ( groupname ),
    UNIQUE KEY gid (gid)
);

CREATE TABLE users (
    userid varchar(30) NOT NULL,
    password varchar(30) NOT NULL,
    uid SMALLINT(5) UNSIGNED NOT NULL DEFAULT 1000,
    gid SMALLINT(5) UNSIGNED NOT NULL DEFAULT 1000,
    homedir varchar(255) default NULL,
    shell varchar(255) default '/bin/true',
    PRIMARY KEY (userid),
    UNIQUE KEY uid (uid)
);


■ データベース「proftpd」を作成する。

[root@hoge proftpd]# mysqladmin -u root -p create proftpd
Enter password:

[root@hoge proftpd]# mysql -u root -p < proftpd.schema proftpd
Enter password:

[root@hoge proftpd]# mysql -u root -p proftpd
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.54 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>


■ proftpd データベースのユーザ proftpd を作成する

mysql> GRANT SELECT,UPDATE,INSERT ON proftpd.* TO proftpd@localhost IDENTIFIED BY 'proftpd_password';
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye


■ DBをreloadする

[root@hoge proftpd]# mysqladmin -u root -p reload
Enter password:


■ ProFTPD設定

[root@hoge proftpd]# cd /etc/
[root@hoge etc]# cp -p proftpd.conf proftpd.conf.orig
[root@hoge etc]# vi proftpd.conf
# This is a basic ProFTPD configuration file (rename it to
# 'proftpd.conf' for actual use.  It establishes a single server
# and a single anonymous login.  It assumes that you have a user/group
# "nobody" and "ftp" for normal operation and anon.

ServerIdent                     on ""
ServerName                      "hoge.example.com"
ServerType                      standalone
DefaultServer                   on

# Port 21 is the standard FTP port.
Port                            21

# Umask 022 is a good standard umask to prevent new dirs and files
# from being group and world writable.
Umask                           022


RootLogin                       off
#ListOptions                     "-la"
ListOptions                     "-a"


# To prevent DoS attacks, set the maximum number of child processes
# to 30.  If you need to allow more than 30 concurrent connections
# at once, simply increase this value.  Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd).
MaxInstances                    30

# Set the user and group under which the server will run.
#User                           nobody
#Group                          nogroup
User                            webmaster
Group                           webmaster

# To cause every FTP user to be "jailed" (chrooted) into their home
# directory, uncomment this line.
#DefaultRoot ~
DefaultRoot ~ !wheel

RequireValidShell               off
UseReverseDNS                   off
IdentLookups                    off
TimesGMT                        off
#TimesGMT                        on
TimeoutIdle                     600
TimeoutLogin                    300
TimeoutNoTransfer               600
TimeoutStalled                  600
ShowSymlinks                    on
MaxClientsPerHost               3
MaxHostsPerUser                 10

#AllowStoreRestart              on
#AllowRetrieveRestart           on
#MaxStoreFileSize               100Mb

LogFormat allinfo "%t :  %u (%a [%h]) : [%s], %T, %m (%f)"
LogFormat write "%t : %u : %F (%a)"
LogFormat read "%t : %u : %F (%a)"
LogFormat auth "%t : %u (%a [%h])"
ExtendedLog /var/log/proftpd/all.log   ALL allinfo
ExtendedLog /var/log/proftpd/write.log WRITE write
ExtendedLog /var/log/proftpd/read.log  READ read
ExtendedLog /var/log/proftpd/auth.log  AUTH auth

<Directory /*>
  AllowOverwrite                on
  AllowStoreRestart             on
  AllowRetrieveRestart          on
</Directory>

<IfModule mod_sql_mysql.c>
    SQLAuthenticate             users
    SQLConnectInfo              proftpd@localhost:3306 proftpd proftpd_password
    SQLAuthTypes                Plaintext
    SQLUserInfo                 users userid password uid gid homedir shell
    SQLGroupInfo                groups groupname gid members
    AuthOrder                   mod_sql.c
</IfModule>

# Normally, we want files to be overwriteable.
AllowOverwrite          on

# Bar use of SITE CHMOD by default
#<Limit SITE_CHMOD>
#  DenyAll
#</Limit>

# chmodコマンドが叩けないので、叩けるようにした
# by nullpopopo 2008/02/11
<Limit SITE_CHMOD>
  AllowAll
</Limit>

<Directory /var/ftp>
  <Limit ALL>
    DenyAll
  </Limit>
</Directory>


# A basic anonymous configuration, no upload directories.  If you do not
# want anonymous users, simply delete this entire <Anonymous> section.
#<Anonymous ~ftp>
#  User                          ftp
#  Group                         ftp
#
#  # We want clients to be able to login with "anonymous" as well as "ftp"
#  UserAlias                     anonymous ftp
#
#  # Limit the maximum number of anonymous logins
#  MaxClients                    10
#
#  # We want 'welcome.msg' displayed at login, and '.message' displayed
#  # in each newly chdired directory.
#  DisplayLogin                  welcome.msg
#  DisplayFirstChdir             .message
#
#  # Limit WRITE everywhere in the anonymous chroot
#  <Limit WRITE>
#    DenyAll
#  </Limit>
#</Anonymous>


■ ProFTPD 1.2.10 グループ・ユーザをDBに追加

[root@hoge etc]# mysql -u root -p proftpd
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.0.54 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>


mysql> show tables;
+-------------------+
| Tables_in_proftpd |
+-------------------+
| groups            |
| users             |
+-------------------+
2 rows in set (0.00 sec)


グループを追加する。
mysql> INSERT INTO groups VALUES ('vhost',1000,'');
Query OK, 1 row affected (0.02 sec)

ユーザを追加する。
テーブル「users」へ追加するデータは
「ユーザ名」「パスワード」「UID」「GID」「ホームディレクトリ」「シェル」の順番である。
mysql> INSERT INTO users VALUES ('www_example_com','www_example_com',1000,1000,'/home/vhost/www.example.com','/bin/true');
Query OK, 1 row affected (0.00 sec)


グループの確認
mysql> select * from groups;
+-----------+------+---------+
| groupname | gid  | members |
+-----------+------+---------+
| vhost     | 1000 |         |
+-----------+------+---------+
1 row in set (0.00 sec)

ユーザの確認
mysql> select * from users;
+-----------------+-----------------+------+------+-----------------------------+-----------+
| userid          | password        | uid  | gid  | homedir                     | shell     |
+-----------------+-----------------+------+------+-----------------------------+-----------+
| www_example_com | www_example_com | 1000 | 1000 | /home/vhost/www.example.com | /bin/true |
+-----------------+-----------------+------+------+-----------------------------+-----------+
1 row in set (0.00 sec)

mysql> exit
Bye


■■ proftpd 起動スクリプト修正

TimesGMT の'(on|off|FALSE)'にもかかわらず、FTPクライアントに表示されたりxferlogに書き込まれたりする
時刻が9時間遅い問題があるので、起動スクリプトを修正することで解決する。

[root@hoge etc]# vi /etc/init.d/proftpd

ここを
start() {
        echo -n $"Starting $prog: "
        daemon proftpd
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/proftpd
}

こうする
start() {
        echo -n $"Starting $prog: "
        export TZ=JST-9
        daemon proftpd
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/proftpd
}


■■ proftpd 起動

[root@hoge etc]# /etc/init.d/proftpd start
Starting proftpd:                                          [  OK  ]


あとは、FTPユーザ www_example_com でログインし、ファイルのDOWN/UPを試してください。
ファイルやディレクトリのタイムスタンプが9時間ズレていなければOKです。

GIGAZINEさまの記事 MySQLの状態がリアルタイムでわかるMySQL用topコマンド「mytop」と「innotop」 に触発されて、mytopを入れてみた。GIGAZINEさまの記事ではソースからコンパイルしているが、なんでもrpmで入れたい派の私は、rpmforgeからパッケージを探すことにした。

■■ パッケージを探す

sh-3.00# yum --enablerepo=rpmforge search mytop
Loading "fastestmirror" plugin
Searching Packages:
Setting up repositories
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
Excluding Packages in global exclude list
Finished


mytop.noarch                             1.4-1.el4.rf           rpmforge
Matched from:
mytop
mytop is a console-based (non-gui) tool for monitoring the threads and
overall performance of a MySQL 3.22.x, 3.23.x, and 4.x server. It runs
on most Unix systems (including Mac OS X) which have Perl, DBI, and
Term::ReadKey installed. And with Term::ANSIColor installed you even
get color. If you install Time::HiRes, you'll get good real-time
queries/second stats. As of version 0.7, it even runs on Windows
(somewhat).
http://jeremy.zawodny.com/mysql/mytop/
blogcubeのサーバは、ココを参考にしてproftpdの認証データをmysqlに持たせている。
この方法でサーバ作ろうと思い立ったのが1年くらい前で、当時わけもわからずコピペで作ったのだが、ちょっと運用に難が出たというか、ちょびっとだけ面倒だなーと思うようになってきた。

理由は、ftpのアカウントを作るのにわざわざSSHでログインしてmysqlぶっ叩いてinsertするのが面倒だから。せっかくphpMyAdmin入れてるんだから、そこからアカウント作ったり消したりパスワード変更したりできたほうがよい。勿論、phpMyAdminのセキュリティをガッチリしておかないとならないのは言うまでもないが、ここでは本筋じゃないので割愛。

■ 変更箇所

旧) SQLAuthTypes                Crypt
新) SQLAuthTypes                Plaintext

あとはproftpdを再起動してやれば、プレーンテキスト(平文)としてパスワードが表示される。ただし、今までCrypt化したパスワードは、一度作りなおしてやらなければならない。ちなみに、ほかに使える認証方式はココを参考にすれば大丈夫でしょう。
カスタム検索

カレンダー