記事が多くなるにしたがって,再構築に時間がかかるようになってきた。Movable Type のデータベースが Berkeley DB であることも遅さに拍車をかけている。MySQL をインストールして,データベースを MySQL に変換する。今回は移行の調査のみで,実際の移行は後日にする。
■ ■ ■
現在の記事数は 424 で,1つの記事の構築に約1分30秒かかっている。再構築ボタンを押してから間違いを発見してしまうと,待ち時間が異様に長く感じられる。サイト全体の再構築などは気が遠くなるくらいの時間がかかる。再構築に時間がかかるのは,サーバの処理能力が低いということもあるが,Movable Type で使っているデータベースが Berkeley DB であることも原因となっている。データベースを MySQL にすれば,再構築の速度が改善されるらしい。そこで,試しに MySQL を導入して,Berkeley DB 上のデータベースを MySQL に変換してみることにした。
サーバの応答速度は,ab (ApacheBench) コマンドで測定することができる([ぴ] - Vine Linux + mod_perl で Movable Type (4))。再構築の時間を測定できる訳ではないが,速度の目安にはなりそう。ab (Apache Bench)コマンドで,mt.cgi に100回アクセスした場合の平均の応答速度が表示される。ab コマンドについては @IT:Apacheパフォーマンス・チューニングのポイント が詳しい。
$ ab -n 100 http://nlogn.ath.cx/opentype/mt.cgi
...
Time per request: 554.51 [ms] (mean)
...
以下は Vine Linux 2.6,Movable Type 2.661 の例である。
まず MySQL をインストールする。MySQL がインストールされていないことを確認。
$ rpm -qa | grep MySQL
$
VinePlus から apt-get でインストールする。/etc/apt/sources.list を編集して,plus の入っている rpm の行のコメントを外す。近くのサーバを選択するとよい。
rpm http://www.ring.gr.jp/pub/linux/Vine/apt 2.6/$(ARCH) main plus plus-noarch
apt データベースを更新し,MySQL と MySQL-client をインストールする。サーバのローカルネームは tp600 である。
# apt-get update
# apt-get install MySQL MySQL-client
...
RPM コマンドを実行しています (-U)...
MySQL ##################################################
Installing all prepared tables
050319 17:07:55 /usr/sbin/mysqld: Shutdown Complete
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
This is done with:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h tp600 password 'new-password'
See the manual for more instructions.
NOTE: If you are upgrading from a MySQL <= 3.22.10 you should run
the /usr/bin/mysql_fix_privilege_tables. Otherwise you will not be
able to use the new GRANT command!
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at https://order.mysql.com
Starting mysqld daemon with databases from /var/lib/mysql
MySQL-client ##################################################
mysqladmin コマンドで root にパスワードをつけろというメッセージが表示されている。
インストールの確認を行う。
# rpm -qa | grep MySQL
MySQL-client-3.23.53-0vl2
MySQL-3.23.53-0vl2
動作確認を行う。
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 3.23.53
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select host,user,password from mysql.user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| tp600 | root | |
| localhost | | |
| tp600 | | |
+-----------+------+----------+
4 rows in set (0.17 sec)
MySQL の root というユーザにパスワードがついていない。また,user 欄が空欄になっているのは誰でもアクセスできることを示しており,さらに password 欄が空欄なのでパスワードなしでアクセスできてしまうことを示している。セキュリティ上よろしくないので,不要なユーザは削除し,root にはパスワードをつける(MySQLの設定)。
mysql> delete from mysql.user where user="";
必要な Perl モジュールがインストールされているかを確認する。MTPath/mt-check.cgi に Web ブラウザでアクセスするのが簡単。
CHECKING FOR DATA STORAGE MODULES:
The following modules are used by the different data storage options in
Movable Type. In order run the system, your server needs to have at least
one of these modules installed.
DB_File...
Your server has DB_File installed (version 1.809).
DBD::mysql...
Your server does not have DBD::mysql installed. DBI and
DBD::mysql are required if you want to use the MySQL database
backend. Please consult the installation instructions for help
in installing DBD::mysql.
...
DB_File はインストールされているが,DBD::mysql がインストールされていないことが分かる。nlog(n): CPAN の URL リスト変更 でやったのと同じように,CPAN からインストールする。
# perl -MCPAN -e "install 'DBD::mysql'"
...
CPAN.pm: Going to build R/RU/RUDY/DBD-mysql-2.9004.tar.gz
Can't exec "mysql_config": そのようなファイルやディレクトリはありません at Makefile.PL line 174.
readline() on closed filehandle PIPE at Makefile.PL line 176.
Can't exec "mysql_config": そのようなファイルやディレクトリはありません at Makefile.PL line 174.
readline() on closed filehandle PIPE at Makefile.PL line 176.
Can't exec "mysql_config": そのようなファイルやディレクトリはありません at Makefile.PL line 174.
readline() on closed filehandle PIPE at Makefile.PL line 176.
Can't exec "mysql_config": そのようなファイルやディレクトリはありません at Makefile.PL line 174.
readline() on closed filehandle PIPE at Makefile.PL line 176.
Can't exec "mysql_config": そのようなファイルやディレクトリはありません at Makefile.PL line 174.
readline() on closed filehandle PIPE at Makefile.PL line 176.
Failed to determine directory of mysql.h. Use
perl Makefile.PL --cflags=-I<dir>
to set this directory. For details see the INSTALL.html file,
section "C Compiler flags" or type
perl Makefile.PL --help
Running make test
Make had some problems, maybe interrupted? Won't test
Running make install
Make had some problems, maybe interrupted? Won't install
しかし,インストールに失敗してしまう。mysql_config という実行ファイルがないのが原因である。確認してみる。
$ rpm -ql MySQL | grep mysql_config
$
確かにインストールされていない。mysql_config は MySQL-devel パッケージに入っているので,これを apt-get で追加インストールする。
# apt-get install MySQL-devel
MySQL-devel をインストールした後,もう一度 DBD::mysql のインストールを行うと,今度はめでたく成功した。mt-check.cgi にアクセスすると,今度は DBD::mysql のバージョンが表示された。
DBD::mysql...
Your server has DBD::mysql installed (version 2.9004).
Berkeley DB の移行先のデータベースとユーザを作成する。ここではデータベース名を nlogn_db,ユーザ名を nlogn_n とした。パスワードは仮に nlogn_pass とした。
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 58 to server version: 3.23.53
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database nlogn_db;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on nlogn_db.* to nlogn_n@localhost identified by 'nlogn_pass';
Query OK, 0 rows affected (0.42 sec)
mysql> select host,user,password from mysql.user;
+-----------+---------+------------------+
| host | user | password |
+-----------+---------+------------------+
| localhost | root | |
| tp600 | root | |
| localhost | nlogn_n | 4a63cf7e5edae535 |
+-----------+---------+------------------+
5 rows in set (0.00 sec)
mysql> exit
ユーザ nlogn_n にはパスワードがついていることが分かる(表示は暗号化されている)。root にはまだついていない。
公式マニュアルの手順 mtinstall - Movable Typeのアップグレード にしたがって mt.cfg を修正する。
ObjectDriver DBI::mysql
Database nlogn_db
DBUser nlogn_n
データベース用のパスワードを mt-db-pass.cgi に直接平文で書く。念のため,mt-db-pass.cgi の実行許可を外しておく。
$ chmod 600 mt-db-pass.cgi
$ cat mt-db-pass.cgi
nlogn_pass
データベース変換中に,コメントやトラックバックがあるのはトラブルのもとである。しかし,Apache を止めてしまうと,変換 CGI が動作しなくなってしまう。mt-comments.cgi と mt-tb.cgi の実行許可を一時的に外しておくのが安全だろう。
Berkeley DB から MySQL への変換は,アップグレード用のパッケージ MT-2.661-upgrade.tar.gz に入っている mt-db2sql.cgi を使う。mt-db2sql.cgi には問題があり,オリジナルのまま使うとトラックバックの番号がずれることがあるらしいので,修正を行っておく(#BLOG: MTでMySQLへ移行したデータのTrackBack IDがおかしくなる)。ここで言う Trackback ID は,各記事のトラックバック URL に含まれている番号である。受け取ったトラックバックのシリアル番号は Ping ID と呼ばれる。mt-db2sql.cgi を MTPath ディレクトリに置いて,ブラウザでアクセスする。データベースに上手く接続できると,次のように処理が始まる。
Loading database schema...
Loading data...
MT::Trackback
1
10
100
101
102
...
数字が沢山並んだ最後に,
Done copying data from Berkeley DB to your SQL database! All went well.
と表示された。変換時にトラブルが発生することもあるようだが,このサイトでは大丈夫だった。
近日中にサーバの OS を Vine Linux 2.6 から 3.1 にアップグレードする予定。3.1 では,MySQL のバージョンが 4.0.23 になっている(Index - VinePlus/3.1/i386/RPMS.plus)。Vine Linux 2.6 で MySQL 3.23.53 に変換して,さらに 4.0.23 に移行すると何が起こるか分からない。Vine Linxu 3.1 にしてからデータベースもアップグレードすることにした。
確認作業が終了したので,mt.cfg を Berkeley DB 用に戻す。/etc/apt/sources.list を編集して plus の行をコメントアウトするように戻し,apt データベースを更新しておく。
# apt-get update
まとめ
- データベースチェックプログラム mt-check.cgi は MT-2.661-full-lib.tar.gz に入っている
- Berkeley DB から MySQL への変換プログラム mt-db2sql.cgi は MT-2.661-upgrade.tar.gz に入っている
- トラックバックの番号がおかしくなる可能性があるので,mt-db2sql.cgi に修正を加える
- MySQL のパッケージは,MySQL, MySQL-client, MySQL-devel が必要で,VinePlus から入手できる
- Perl モジュールは DBD::mysql が必要で,CPAN から入手できる
- データベース変換作業中は mt-comments.cgi と mt-tb.cgi の実行許可を外しておく
2005年8月29日追記:
記事が長くて容量が大きい場合,Berkeley DB から MySQL に変換すると,記事が途中で切れてしまうことが分かりました(nlog(n): cpufreq は未対応だった)。大きい記事がある場合は,あらかじめ MySQL のテーブルを大きくとっておく必要があります。具体的には schemas/mysql.dump ファイルを編集して entry_text の宣言を text から mediumtext あるいは longtext に変更してから mt-db2sql.cgi を実行します(小粋空間: MySQLでエントリーのフィールドサイズを拡張する)。
2005年12月27日追記:
上記の問題は解決しました (nlog(n): 記事の長さの制限値を変更する)。
Posted by n at 2005-03-20 01:30 | Edit | Comments (0) | Trackback(1)