先日CentOS 6.0がリリースされたので、色々試している方も多いと思います。MySQLについて、Scientific Linux/CentOS 6.0では派生元のRed Hat Enterprise Linux 6.0と同様、バージョン5.1.52が採用されています。このディストリビューション付属版のMySQL 5.1.52ですが、残念なことにInnoDB Pluginが無効化されてしまっています。
* Fri Jan 8 2010 Tom Lane <tgl@redhat.com> 5.1.42-4 - Sync with current Fedora build, including: - Update to MySQL 5.1.42, for various fixes described at http://dev.mysql.com/doc/refman/5.1/en/news-5-1-42.html - Disable symbolic links by default in /etc/my.cnf Resolves: #553653 - Remove static libraries (.a files) from package, per packaging guidelines - Change %%define to %%global, per packaging guidelines - Disable building the innodb plugin; it tickles assorted gcc bugs and doesn't seem entirely ready for prime time anyway. Resolves: #553632 - Start mysqld_safe with --basedir=/usr, to avoid unwanted SELinux messages (see 547485) - Stop waiting during "service mysqld start" if mysqld_safe exits Resolves: #544095
バージョン5.1.42のInnoDB PluginはまだRC版だったので無効化するのは正しいのですが、バージョン5.1.52を採用するにあたっても再度有効化はしてくれなかったようです。もったいないですね。
一方、最新版のMySQL 5.5を入れようとすると、今度はRPMの依存関係でmysql-libsをアンインストールする必要がでてきてしまい、
# yum erase mysql-libs Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Removing: mysql-libs x86_64 5.1.52-1.el6_0.1 @sl-security 4.0 M Removing for dependencies: cronie x86_64 1.4.4-2.el6 @sl 166 k cronie-anacron x86_64 1.4.4-2.el6 @sl 41 k crontabs noarch 1.10-32.1.el6 @sl 2.4 k openoffice.org-brand x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 852 k openoffice.org-calc x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 28 k openoffice.org-calc-core x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 23 M openoffice.org-core x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 237 M openoffice.org-draw x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 25 k openoffice.org-draw-core x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 2.1 M openoffice.org-graphicfilter x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 663 k openoffice.org-impress x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 29 k openoffice.org-impress-core x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 3.0 M openoffice.org-langpack-en x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 0.0 openoffice.org-langpack-ja_JP x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 36 M openoffice.org-math x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 15 k openoffice.org-math-core x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 3.3 M openoffice.org-pdfimport x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 3.8 M openoffice.org-presenter-screen x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 4.6 M openoffice.org-writer x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 31 k openoffice.org-writer-core x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 15 M openoffice.org-xsltfilter x86_64 1:3.2.1-19.6.el6_0.5 @sl-security 1.9 M postfix x86_64 2:2.6.6-2.2.el6_1 @sl-security 9.7 M redhat-lsb x86_64 4.0-2.1.el6 @sl 22 k redland x86_64 1.0.7-11.el6 @sl 602 k sysstat x86_64 9.0.4-12.el6_0.1 @sl-fastbugs 753 k Transaction Summary ==================================================================================================== Remove 26 Package(s) Reinstall 0 Package(s) Downgrade 0 Package(s) Is this ok [y/N]:
と、Pythonほどではありませんがなかなか面倒なことになります。ううむ…
Scientific Linux/CentOS 6.0でMySQL 5.5を使いたい場合は、今のところRemiを使うのがよさそうです。依存関係を綺麗に解決してくれます。しかし今回はこうした外部リポジトリには頼らず、出たばかりのディストリビューションにあまり大きく手を加えない方向でInnoDB Pluginだけ有効化してみたいと思います。
RPMのビルド環境を作る
ここからはMySQLのSource RPMを元に、InnoDB Pluginを有効化したRPMを再作成していきます。ビルド環境の準備についてはrpmbuildコマンドを使おう - よくきたWikiなどを参考にしてください。.rpmmacrosには_topdir以外に、vendorとdistも定義しておくと便利です。サンプルを以下に示します。
%_topdir /home/taira/rpmbuild %vendor HIRATSUKA Sadao %dist .el6_0
Source RPMをhttp://ftp.jaist.ac.jp/pub/Linux/scientific/6/SRPMS/vendor/などから入手し、インストールします。
$ wget http://ftp.jaist.ac.jp/pub/Linux/scientific/6/SRPMS/vendor/mysql-5.1.52-1.el6_0.1.src.rpm --2011-07-20 00:31:15-- http://ftp.jaist.ac.jp/pub/Linux/scientific/6/SRPMS/vendor/mysql-5.1.52-1.el6_0.1.src.rpm ftp.jaist.ac.jp をDNSに問いあわせています... 150.65.7.130, 2001:200:141:feed::feed ftp.jaist.ac.jp|150.65.7.130|:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 200 OK 長さ: 20854090 (20M) [application/x-wais-source] `mysql-5.1.52-1.el6_0.1.src.rpm' に保存中 100%[==========================================================>] 20,854,090 2.93M/s 時間 8.0s 2011-07-20 00:31:23 (2.48 MB/s) - `mysql-5.1.52-1.el6_0.1.src.rpm' へ保存完了 [20854090/20854090] $ rpm -ivh mysql-5.1.52-1.el6_0.1.src.rpm 1:mysql 警告: ユーザ mockbuild は存在しません - root を使用します 警告: グループ mockbuild は存在しません - root を使用します …
SPECファイルを修正する
SPECS/mysql.specをテキストエディタで開き、241行目、--without-plugin-innodb_pluginと書いてあるところを--with-plugins-innodb_pluginへと書き換えます。with-pluginではなくwith-pluginsとsが付きます。
%configure \ --with-readline \ --with-ssl=/usr \ --without-debug \ --enable-shared \ --with-embedded-server \ --localstatedir=/var/lib/mysql \ --with-unix-socket-path=/var/lib/mysql/mysql.sock \ --with-mysqld-user="mysql" \ --with-extra-charsets=all \ --with-big-tables \ --with-pic \ --with-plugin-innobase \ --with-plugins-innodb_plugin \ --with-plugin-partition \ --enable-local-infile \ --enable-largefile \ --enable-thread-safe-client \ --disable-dependency-tracking
RPMをビルドする
rpmbuildコマンドでRPMをビルドします。この時点でビルドに必要なパッケージが不足している場合は、インストールするように促されます。defineオプションでrunselftestを0に設定すると、ビルド後のテストをスキップすることができます。
$ rpmbuild -bb --define='runselftest 0' mysql.spec 実行中(%prep): /bin/sh -e /var/tmp/rpm-tmp.pDzWkP + umask 022 + cd /home/taira/rpmbuild/BUILD + cd /home/taira/rpmbuild/BUILD + rm -rf mysql-5.1.52 + /usr/bin/gzip -dc /home/taira/rpmbuild/SOURCES/mysql-5.1.52-nodocs + /bin/tar -xf - … + umask 022 + cd /home/taira/rpmbuild/BUILD + cd mysql-5.1.52 + rm -rf /home/taira/rpmbuild/BUILDROOT/mysql-5.1.52-1.el6_0.1.x86_64 + exit 0
いまどきのPCでは5分程度でビルドが完了します。
インストール、設定
作成されたRPMはRPMS/x86_64に保存されています。インストールします。
$ ls -lh 合計 43M -rw-r--r-- 1 taira taira 1.2M 7月 20 00:51 2011 mysql-5.1.52-1.el6_0.1.x86_64.rpm -rw-r--r-- 1 taira taira 516K 7月 20 00:51 2011 mysql-bench-5.1.52-1.el6_0.1.x86_64.rpm -rw-r--r-- 1 taira taira 135K 7月 20 00:51 2011 mysql-devel-5.1.52-1.el6_0.1.x86_64.rpm -rw-r--r-- 1 taira taira 12M 7月 20 00:51 2011 mysql-embedded-5.1.52-1.el6_0.1.x86_64.rpm -rw-r--r-- 1 taira taira 6.4M 7月 20 00:51 2011 mysql-embedded-devel-5.1.52-1.el6_0.1.x86_64.rpm -rw-r--r-- 1 taira taira 2.5M 7月 20 00:51 2011 mysql-libs-5.1.52-1.el6_0.1.x86_64.rpm -rw-r--r-- 1 taira taira 14M 7月 20 00:51 2011 mysql-server-5.1.52-1.el6_0.1.x86_64.rpm -rw-r--r-- 1 taira taira 7.2M 7月 20 00:51 2011 mysql-test-5.1.52-1.el6_0.1.x86_64.rpm # rpm -Uvh mysql-server-5.1.52-1.el6_0.1.x86_64.rpm mysql-5.1.52-1.el6_0.1.x86_64.rpm 準備中... ########################################### [100%] 1:mysql ########################################### [ 50%] 2:mysql-server ########################################### [100%]
小規模サーバ向けmy.cnfのサンプルです。さくらのVPS 512/1Gを想定しています。
[mysqld] ## character set character_set_server = utf8 collation_server = utf8_general_ci ## isolation level transaction_isolation = READ-COMMITTED ## connection max_connections = 151 thread_cache_size = 8 ## per connection buffer sort_buffer_size = 4M ## file descriptor table_open_cache = 4096 ## network max_allowed_packet = 16M ## storage engine default_storage_engine = InnoDB ## innodb plugin ignore-builtin-innodb plugin-load = innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so innodb_file_format = Barracuda innodb_file_per_table = 1 innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT innodb_buffer_pool_size = 64M innodb_log_buffer_size = 8M innodb_log_file_size = 128M ## myisam key_buffer_size = 1M ## query cache query_cache_type = 1 query_cache_size = 16M ## binary log #server_id = 1 #log_bin = mysql-bin #binlog_format = MIXED #binlog_cache_size = 1M ## slow query log slow_query_log = 1 long_query_time = 1.0
show pluginsコマンドで、InnoDB Pluginが有効化されていることが確認できます。
mysql> show plugins; +---------------------+--------+--------------------+---------------------+---------+ | Name | Status | Type | Library | License | +---------------------+--------+--------------------+---------------------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | partition | ACTIVE | STORAGE ENGINE | NULL | GPL | | CSV | ACTIVE | STORAGE ENGINE | NULL | GPL | | MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL | | MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | InnoDB | ACTIVE | STORAGE ENGINE | ha_innodb_plugin.so | GPL | | INNODB_TRX | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMP | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMPMEM | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | | INNODB_CMPMEM_RESET | ACTIVE | INFORMATION SCHEMA | ha_innodb_plugin.so | GPL | +---------------------+--------+--------------------+---------------------+---------+ 14 rows in set (0.00 sec)
ご利用ください。