対象サーバについて
製品名 | OpenBlockS 600 |
OS(kernel ver) | Debian lenny(2.6.29) |
CPU | 600MHz(AMCC PowerPC 405EX) |
メモリ | 1GB(DDR2 SDRAM) |
ストレージ | 8GB(Compact Flash) |
はじめに
本サイトはCMSの一つであるNucleusを使用して構築していますが、別記事(Nucleus)でまとめているプラグインを入れていくごとにサイトの表示速度が遅くなっていきました。
そこで、PHPのスクリプトを中間コードの状態でキャッシュするeAcceleratorを導入し、PHP自体の高速化を図ります。
eAcceleratorのインストール
ファイルダウンロード
# wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2 # tar jxvf eaccelerator-0.9.6.tar.bz2 eaccelerator-0.9.6/ eaccelerator-0.9.6/COPYING eaccelerator-0.9.6/mm.h eaccelerator-0.9.6/control.php eaccelerator-0.9.6/AUTHORS ...
インストール前の事前PKG導入
READMEに以下の記載があります。
* apache >= 1.3, mod_php >= 5.1 or php with fastcgi support
* autoconf, automake, libtool, m4
本サイトでは上記を参考に、以下のPKGをインストールしました(今更?というものばかりですが…)。
# aptitude install make 以下の新規パッケージがインストールされます: make # aptitude install automake 以下の新規パッケージがインストールされます: autoconf{a} automake autotools-dev{a} m4{a} # aptitude install libtool 以下の新規パッケージがインストールされます: libltdl3-dev{a} libtool 更新: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。 # aptitude install g++ 以下の新規パッケージがインストールされます: g++ g++-4.3{a} libstdc++6-4.3-dev{a} 更新: 0 個、新規インストール: 3 個、削除: 0 個、保留: 0 個。 # aptitude install php5-dev 以下の新規パッケージがインストールされます: automake1.4{a} libssl-dev{a} php5-dev shtool{a}
PKGインストール
READMEを参考にインストールしていきます。
以下、READMEからの抜粋です。
Step 1. Compiling eAccelerator
export PHP_PREFIX=”/usr”
$PHP_PREFIX/bin/phpize
./configure \
–enable-eaccelerator=shared \
–with-php-config=$PHP_PREFIX/bin/php-configmake
You must specify the real prefix where PHP is installed in the “export”
command. It may be “/usr” “/usr/local”, or something else.
Step 2. Installing eAcceleratormake install
上記の通りに実施していきます。
# export PHP_PREFIX="/usr" # $PHP_PREFIX/bin/phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 # ./configure \ > --enable-eaccelerator=shared \ > --with-php-config=$PHP_PREFIX/bin/php-config checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for gcc... gcc ... configure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers. ※1 ... checking for best semaphores type... configure: error: "You need to pass the user id eaccelerator will be running under when using sysvipc semaphores" ※2
※1、2の2つエラーが出たので、書いてある通りに対応していきます。
まず※1のエラーについてはre2cをインストールすることで消えました。
# aptitude show re2c パッケージ: re2c 新規: yes 状態: インストールされていません バージョン: 0.13.5-1 優先度: 任意 セクション: devel メンテナ: Robert S. Edmonds展開サイズ: 553k 依存: libc6 (>= 2.7-1), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.2.1) 説明: tool for generating fast C-based recognizers re2c is a great tool for writing fast and flexible lexers. Unlike other such tools, re2c concentrates solely on generating efficient code for matching regular expressions. Not only does this singleness make re2c more suitable for a wider variety of applications, it allows us to generate scanners which approach hand-crafted ones in terms of size and speed. ホームページ: http://re2c.sourceforge.net/ # aptitude install re2c
バージョンが0.12.0以上であることを確認してからインストールします。
次に※2の対応をします(こちらのサイトを参考にさせて頂きました)。
apacheを実行するユーザのIDを/etc/passwdで調べてから、以下のXXの箇所に入れて再度makeファイルを作成します。
# ./configure \ --enable-eaccelerator=shared \ --with-php-config=$PHP_PREFIX/bin/php-config \ --with-eaccelerator-userid=XX
今回はエラーも出ずにMakefileが作成できましたので、コンパイルとインストール作業を続けます。
# make ... Build complete. Don't forget to run 'make test'. # make test Build complete. Don't forget to run 'make test'. ERROR: Cannot run tests without CLI sapi.
エラーが出たので、注意された通りCLI用に以下のPKGをインストールします。
# aptitude install php5-cli 以下の新規パッケージがインストールされます: php5-cli ...
再度make testします。
# make test Build complete. Don't forget to run 'make test'. bogus test name tests/
エラーがなくなったのでインストールします。
# make install Installing shared extensions: /usr/lib/php5/20060613+lfs/
→インストールは一瞬で終了しました。上記のパスをメモっておきます。
PKGの設定
READMEを参考に設定していきます。
以下、READMEからの抜粋です。
Step 3. Configuring eAccelerator
eAccelerator can be installed both as Zend or PHP extension.
For eaccelerator > 0.9.1, if you have /etc/php.d directory, you should copy eaccelerator.ini inside and modify default value if you need.
If not, you need to edit your php.ini file (usually /etc/php.ini).
To install as Zend extension:
zend_extension=”/usr/lib/php4/eaccelerator.so”
eaccelerator.shm_size=”16″
eaccelerator.cache_dir=”/tmp/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″If you use thread safe build of PHP you must use “zend_extension_ts” instead
of “zend_extension”.To install as PHP extension:
extension=”eaccelerator.so”
eaccelerator.shm_size=”16″
eaccelerator.cache_dir=”/tmp/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″Step 4. Creating cache directory
mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator
php.iniファイルの編集前にcacheファイルの保存先のディレクトリ作成を行います。
# mkdir /var/cache/apache2/eaccelerator # chmod 0777 /var/cache/apache2/eaccelerator
次に、GUI画面であるcontrol.phpの場所を確認し、webアクセス時のIDとPWを編集します。
# locate control.php /usr/local/src/eaccelerator-0.9.6/control.php # vi /usr/local/src/eaccelerator-0.9.6/control.php $user = "*********"; $pw = "*********";
ここでは説明を割愛しますが、control.phpファイルにアクセスできるようにApache2の設定も実施して下さい。
上記作業が終わったら、php.iniの編集を行います。
編集するファイル:/etc/php5/cli/php.ini、/etc/php5/apache2/php.ini
上記2ファイルの末尾に以下を追記します。
[eaccelerator] zend_extension="/usr/lib/php5/20060613+lfs/eaccelerator.so" eaccelerator.shm_size="32" eaccelerator.cache_dir="/var/cache/apache2/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" eaccelerator.allowed_admin_path="/usr/local/src/eaccelerator-0.9.6/control.php"
eAcceleratorが認識されていることを確認します。
# php -v PHP 5.2.6-1+lenny8 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 14 2010 11:02:42) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with eAccelerator v0.9.6, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
最後にapache2を再起動してからサイトにアクセスしてみたところ、eAccelerator導入前に3~4秒かかっていたNucleusのトップページが、1.2秒にまで高速化されました。
GUI画面にアクセスすると、メモリ使用量やキャッシュされているスクリプトなどが分かります。