参考url
http://amon.64p.org/
http://search.cpan.org/perldoc?Amon2
gihyo.jpにもAmon2の記事がありますが、今回使用した Amon v2.6.10 と内容と比較して古いようですので、amon.64p.org を参照した方がよさそうです
第18回 Amon2によるWebアプリケーションの高速開発(1):Perl Hackers Hub|gihyo.jp … 技術評論社
第18回 Amon2によるWebアプリケーションの高速開発(2):Perl Hackers Hub|gihyo.jp … 技術評論社
第18回 Amon2によるWebアプリケーションの高速開発(3):Perl Hackers Hub|gihyo.jp … 技術評論社
amon2のinstall
configure; make ; make installする派ですが、フレームワークだと依存moduleが多く、手間なので、 http://amon.64p.org/install.html に記載されている通り cpanm コマンドで行いました。
$ su - # curl -L http://cpanmin.us | perl - Amon2
amon2のスケルトン作成
先程のamon2のインストールにより、amon2-setup.pl というツールもインストールされ、アプリケーションのスケルトン作成は、このツールで行います。
$ amon2-setup.pl --help Usage: % amon2-setup.pl MyApp --flavor=Basic basic flavour (default) --flavor=Lite Amon2::Lite flavour (need to install) --flavor=Minimum minimalistic flavour for benchmarking --flavor=Standalone CPAN uploadable web application(EXPERIMENTAL) --vc=Git setup the git repository (default) --list-flavors (or -l) Shows the list of flavors installed --help Show this help $ amon2-setup.pl --flavor=Basic TestAmon2App -- Running flavor: Basic -- <略> [Flavor::Basic] writing static/503.html There is no git command. -------------------------------------------------------------- Setup script was done! You are ready to run the skelton. You need to install the dependencies by: > carton install And then, run your application server: > carton exec perl -Ilib script/testamon2app-server -------------------------------------------------------------- [endo@colinux amon2]$ tree . `-- TestAmon2App |-- Build.PL |-- builder | `-- MyBuilder.pm |-- config | |-- development.pl | |-- production.pl | `-- test.pl |-- cpanfile |-- db |-- lib | |-- TestAmon2App | | |-- DB | | | |-- Row.pm | | | `-- Schema.pm | | |-- DB.pm | | |-- Web | | | |-- Dispatcher.pm | | | |-- Plugin | | | | `-- Session.pm | | | |-- View.pm | | | `-- ViewFunctions.pm | | `-- Web.pm | `-- TestAmon2App.pm |-- minil.toml |-- script | `-- testamon2app-server |-- sql | |-- mysql.sql | `-- sqlite.sql |-- static | |-- 404.html | |-- 500.html | |-- 502.html | |-- 503.html | |-- 504.html | |-- bootstrap | | |-- css | | | |-- bootstrap-theme.css | | | |-- bootstrap-theme.css.map | | | |-- bootstrap-theme.min.css | | | |-- bootstrap.css | | | |-- bootstrap.css.map | | | `-- bootstrap.min.css | | |-- fonts | | | |-- glyphicons-halflings-regular.eot | | | |-- glyphicons-halflings-regular.svg | | | |-- glyphicons-halflings-regular.ttf | | | `-- glyphicons-halflings-regular.woff | | `-- js | | |-- bootstrap.js | | `-- bootstrap.min.js | |-- css | | `-- main.css | |-- img | |-- js | | |-- es5-shim.min.js | | |-- jquery-2.1.1.min.js | | |-- main.js | | |-- micro-location.js | | |-- micro_dispatcher.js | | |-- micro_template.js | | |-- sprintf.js | | |-- strftime.js | | `-- xsrf-token.js | `-- robots.txt |-- t | |-- 00_compile.t | |-- 01_root.t | |-- 02_mech.t | |-- 03_assets.t | |-- 06_jshint.t | `-- Util.pm |-- tmpl | |-- include | | |-- layout.tx | | `-- pager.tx | `-- index.tx `-- xt |-- 01_pod.t `-- 02_perlcritic.t 23 directories, 58 files
スケルトン付属のスクリプトによるサーバ起動
先程のスケルトン作成により script/testamon2app-server というperlスクリプトも合わせて作成される為、次にように起動後、ブラウザでアクセスすると画面が表示されます。
$ pwd /home/endo/tmp/amon2/TestAmon2App $ /usr/local/bin/perl ./script/testamon2app-server -host colinux.a4.jp TestAmon2App: http://colinux.a4.jp:5000/
apache + reverse_proxyによるサーバ起動
※apache + mod_perlの環境へのamon2の組込みは、別エントリに記載しています
PSGI/PlackなAmon2 (ver.6.10)をapache2.2 + mod_perl2環境に組み込む - end0tknrのkipple - web写経開発
PSGI/Plack前提?である為、apache + reverse_proxyによるリバースプロキシでPSGIサーバへ連携することにしました。
以下、httpd.confの抜粋です
<Location /TestAmon2> ProxyPass http://127.0.0.1:5000/ ProxyPassReverse http://127.0.0.1:5000/ # http://d.hatena.ne.jp/end0tknr/20140612/1402570414 # RewriteEngine On # RewriteCond %{LA-U:REMOTE_USER} (.+) # RewriteRule . - [E=RU:%1,NS] # RequestHeader add X-Forwarded-User %{RU}e </Location> <Directory "/home/endo/tmp/amon2/TestAmon2App/static"> AllowOverride All Order allow,deny Allow from all </Directory> Alias /static /home/endo/tmp/amon2/TestAmon2App/static
または↓こちらの方がpathが変わらない気がします
<Location /smrthim > ProxyPass http://127.0.0.1:5000/smrthim ProxyPassReverse http://127.0.0.1:5000/smrthim AuthType BASIC AuthUserFile /home/endo/dev/htpasswd AuthName "COLINUX MEMBERS" require valid-user # RewriteEngine On # RewriteCond %{LA-U:REMOTE_USER} (.+) # RewriteRule . - [E=RU:%1,NS] # RequestHeader add X-Forwarded-User %{RU}e </Location> <Directory "/home/endo/dev/SmrtHim/static"> AllowOverride All Order allow,deny Allow from all </Directory> Alias /static /home/endo/dev/SmrtHim/static
尚、apacheからのリクエストを受けるPSGIサーバは、先程の「スケルトン付属のスクリプトによるサーバ起動」と異なり
$ /usr/local/bin/perl ./script/testamon2app-server
で起動します