ChumbyをWebサーバとして使う
出典: Chumby日本語まとめWiki
このページは http://wiki.chumby.com/mediawiki/index.php/Chumby_as_a_web_server を翻訳したものです。
Chumby 向けに lighttpd をビルドする手順を解説します。この lighttpd は USB 上で実行させます。
目次 |
[編集] Linux 開発環境を準備
私たちは Kubuntu DapperDrake を使用する傾向がありますが、どの Linux システムでもほとんどは動作します。また、通常の GNU toolchain をあらかじめインストールしておいてください。Ubuntu や Debian ベースのシステムでは、sudo apt-get install build-essential でインストールできます。
[編集] ARM toolchain をインストール
chumby で使われている ARM9 プロセッサ用にビルドするため、http://wiki.chumby.com/mediawiki/index.php/GNU_Toolchain に従って GNU Toolchain をインストールしてください。
注意: ファームウェアのバージョン1.7からEABIに変更となりました。以前のバージョンのtoolchainでビルドされたlighttpdは動作しないため、最新のtoolchainでビルドし直してください。
[編集] lighttpd のソースをダウンロード ・ 展開
# wget http://www.lighttpd.net/download/lighttpd-1.4.16.tar.gz # tar xzvf lighttpd-1.4.16.tar.gz
[編集] ビルド
# cd lighttpd-1.4.16 # ./configure --build=i386-linux --host=arm-linux --prefix=/mnt/usb/lighty # make
Ubuntu では通常、USB メモリ等を /media 以下へマウントするため、あらかじめ空の /mnt/usb を作成する必要があります。
- Note: 一部の環境では、下記のようなエラーでビルドに失敗することがあります。
configfile.c: In function 'config_parse_cmd': configfile.c:919: error: 'PATH_MAX' undeclared (first use in this function) configfile.c:919: error: (Each undeclared identifier is reported only once configfile.c:919: error: for each function it appears in.) configfile.c:919: warning: unused variable 'oldpwd' make[2]: *** [configfile.o] Error 1 make[2]: Leaving directory `/home/user/lighttpd-1.4.16/src' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/user/lighttpd-1.4.16' make: *** [all] Error 2
このような場合は、lighttpd-1.4.16/src/configfile.c の先頭に #include <linux/limits.h> を書き加えてください。
[編集] インストール
# make install
この時点で、/mnt/usb/lighty 以下に bin と lib と sbin ディレクトリがあるはずです。このディレクトリを、USB のルートに lighty ディレクトリが配置されるようコピーしてください。
[編集] ドキュメントルートを作成
まず、lighty ディレクトリ内に html と cgi-bin ディレクトリを作成してください。
HTML ファイルは html 内に、CGI スクリプトは cgi-bin 内に入れます。
また html 内には index.html を置いておくと良いかもしれません。
[編集] 簡単な lighttpd.conf ファイルを作成する
次に、lighttpd の設定をするため lighttpd.conf を lighty 内に作成する必要があります。
server.modules = ( "mod_cgi", "mod_accesslog" ) server.document-root = "/mnt/usb/lighty/html" server.errorlog = "/tmp/logs/lighttpd.error.log" accesslog.filename = "/tmp/logs/lighttpd.access.log" index-file.names = ( "index.php", "index.html", "index.htm", "default.htm" ) cgi.assign = ( "/mnt/usb/lighty/cgi-bin") mimetype.assign = ( ".pdf" => "application/pdf", ".sig" => "application/pgp-signature", ".spl" => "application/futuresplash", ".class" => "application/octet-stream", ".ps" => "application/postscript", ".torrent" => "application/x-bittorrent", ".dvi" => "application/x-dvi", ".gz" => "application/x-gzip", ".pac" => "application/x-ns-proxy-autoconfig", ".swf" => "application/x-shockwave-flash", ".tar.gz" => "application/x-tgz", ".tgz" => "application/x-tgz", ".tar" => "application/x-tar", ".zip" => "application/zip", ".mp3" => "audio/mpeg", ".m3u" => "audio/x-mpegurl", ".wma" => "audio/x-ms-wma", ".wax" => "audio/x-ms-wax", ".ogg" => "application/ogg", ".wav" => "audio/x-wav", ".gif" => "image/gif", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".png" => "image/png", ".xbm" => "image/x-xbitmap", ".xpm" => "image/x-xpixmap", ".xwd" => "image/x-xwindowdump", ".css" => "text/css", ".html" => "text/html", ".htm" => "text/html", ".js" => "text/javascript", ".asc" => "text/plain", ".c" => "text/plain", ".cpp" => "text/plain", ".log" => "text/plain", ".conf" => "text/plain", ".text" => "text/plain", ".txt" => "text/plain", ".dtd" => "text/xml", ".xml" => "text/xml", ".mpeg" => "video/mpeg", ".mpg" => "video/mpeg", ".mov" => "video/quicktime", ".qt" => "video/quicktime", ".avi" => "video/x-msvideo", ".asf" => "video/x-ms-asf", ".asx" => "video/x-ms-asf", ".wmv" => "video/x-ms-wmv", ".bz2" => "application/x-bzip", ".tbz" => "application/x-bzip-compressed-tar", ".tar.bz2" => "application/x-bzip-compressed-tar" )
これはあくまでも最低限必要な設定だけであるということに注意してください。実際、私たちは結局 lighttpd モジュール (lib ディレクトリ内にあります) の大部分をビルドすることになったので、あなたも lighttpd の機能を有効にするためにオンラインドキュメントを見直す必要があるかもしれません。
[編集] debugchumby ファイルを作成して起動時にサーバを起動
USB のルートディレクトリに debugchumby を下記の内容で作成します。
#!/bin/sh # kill the built-in web server killall httpd # create the log directory mkdir /tmp/logs # start lighttpd LD_LIBRARY_PATH=/mnt/usb/lighty/lib /mnt/usb/lighty/sbin/lighttpd -f /mnt/usb/lighty/lighttpd.conf
[編集] chumby を再起動
これで chumby の IPアドレスへ接続すれば web サーバが応答するはずです。chumby の IP アドレスはコントロールパネルの 設定->Chumby情報 で調べることができます。
以後ログファイルは、RAM 上の /tmp 内に容量が足りなくなるまで書き込まれます。もしログファイルを USB 内に書き込みたい場合、あるいはログファイルが不要な場合 (/dev/null へ書き込む) は、lighttpd.conf を編集してください。
[編集] ものぐさな人に
このリンク先で配布されているlighttpdは古いバージョンのtoolchainでビルドされたもので、最新バージョンのChumbyでは動作しません。
心配する必要はありません。既にビルドされたものを用意してあります。
- chumby_lighttpd.tar.gz をダウンロードする
- USB 上へ解凍する
- USB を chumby の裏側へ差し込み、あとは再起動するだけです!
