読者です 読者をやめる 読者になる 読者になる

臥薪嘗胆

インフラエンジニアのあれこれ

mod_mruby install してみた

mod_mruby

なぜやるのか?

インフラエンジニアをやっていて、かゆいところに手が届かないことがたくさんあって
もどかしい思いをずっとしてきた。
でもいまは時代が変わったようで、自分でmoduleを作らなくても
チョイチョイっとかゆいところに手が届くそうだ
そうmrubyならね!
この流れ(あってる?)に乗り遅れるな!

で、matsumoto-r さん作の mod_mrubyを使ってみよう

親切にここに書かれていたので、この通りにする。

結果、test.rbが動くまではサクッとできる。 あとは何をしたいか。 ちょっとこれから考えてみよう。

以下やったログ

apacheいれとく

sudo yum install httpd.x86_64
sudo yum install httpd-devel.x86_64

mod_mrubyのsrcをもってくる

git clone git://github.com/matsumoto-r/mod_mruby.git

テストとビルド

cd mod_mruby
sh test.sh
sh build.sh

私はvagrant環境で試した 以下にビルド後の.soファイルができてた

ls -la /home/vagrant/mod_mruby/src/.libs/mod_mruby.so

これをコピってあげた。

cp /home/vagrant/mod_mruby/src/.libs/mod_mruby.so /usr/lib64/httpd/modules/
chown root: /usr/lib64/httpd/modules/mod_mruby.so

コンフもマニュアルのとおりに

[root@localhost mod_mruby]# cat /etc/httpd/conf.d/mruby.conf
LoadModule mruby_module modules/mod_mruby.so
<Location /mruby-test>
    mrubyHandlerMiddle /etc/httpd/conf.d/test.rb cache
</Location>

予め準備されているものを読み込むべくコピー

cp -p test/test.rb /etc/httpd/conf.d/
chown root: /etc/httpd/conf.d/test.rb

apacheを起動

systemctl status httpd.service
systemctl start httpd.service

curl してみた結果

[root@localhost mod_mruby]# curl http://127.0.0.1/mruby-test
# mod_mruby Test Page
__mod_mruby test start.__
## Apache Class Test
- Server: Apache
- Apache version: Apache/2.4.6 (CentOS)
- Apache build: Nov 19 2015 21:43:13
- module name: mod_mruby
- module version: 1.13.10
- syslogger function: OK
- errlogger function: OK
- OK status = 0
- DECLINED status = -1
- HTTP_OK status = 200
- HTTP_SERVICE_UNAVAILABLE status = 503
## Request Class Test
- filename = /var/www/html/mruby-test
- uri = /mruby-test
- ---- request_rec changed ----
- filename = /var/www/html/index.html
- uri = /index.html
r.document_root: /var/www/html
r.document_root: /tmp
## Server Class Test
- document_root = /var/www/html
- error_fname = logs/error_log
- hostname = localhost.localdomain
- timeout = 60000000
## Connection Class Test
- remote_ip 127.0.0.1
- local_ip 127.0.0.1
- keepalives = 0
##Notes Class Test
- memo = hello
## Env Class Test
- AUTHOR = matsumoto_r
- SERVER_SOFTWARE = Apache/2.4.6 (CentOS)
- env hash size = 25
- env key = UNIQUE_ID val = VsMsFszCek7oPhdkOOPzNAAAAAM
- env key = HTTP_USER_AGENT val = curl/7.29.0
- env key = HTTP_HOST val = 127.0.0.1
- env key = HTTP_ACCEPT val = */*
- env key = PATH val = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
- env key = SERVER_SIGNATURE val =
- env key = SERVER_SOFTWARE val = A p a c h e
- env key = SERVER_NAME val = 127.0.0.1
- env key = SERVER_ADDR val = 127.0.0.1
- env key = SERVER_PORT val = 80
- env key = REMOTE_ADDR val = 127.0.0.1
- env key = DOCUMENT_ROOT val = /var/www/html
- env key = REQUEST_SCHEME val = http
- env key = CONTEXT_PREFIX val =
- env key = CONTEXT_DOCUMENT_ROOT val = /var/www/html
- env key = SERVER_ADMIN val = root@localhost
- env key = SCRIPT_FILENAME val = /var/www/html/index.html
- env key = REMOTE_PORT val = 57100
- env key = GATEWAY_INTERFACE val = CGI/1.1
- env key = SERVER_PROTOCOL val = HTTP/1.1
- env key = REQUEST_METHOD val = GET
- env key = QUERY_STRING val =
- env key = REQUEST_URI val = /mruby-test
- env key = SCRIPT_NAME val = /index.html
- env key = AUTHOR val = matsumoto_r
## Headers_in Class Test
- Accept-Encoding = nil
- Accept-Encoding = gzip
- headers_in hash size = 4
- headers_in key = User-Agent val = curl/7.29.0
- headers_in key = Host val = 127.0.0.1
- headers_in key = Accept val = */*
- headers_in key = Accept-Encoding val = gzip
## Headers_out Class Test
- headers_out hash size = 0
## Scoreboard Class Test
- child pid = 15737
- thread limit    = 1
- server limit    = 256
- cpu load        = 792739788800
- load avereage   = [0, 0.0099999997764826, 0.090000003576279]
- total kbyte     = 3
- total access    = 1
- restart time    = 1.4556306719778e+15
- idle worker     = 4
- busy worker     = 1
- uptime          = 710
- access counter  = -1
- scoreboard status hash size = 1
- scoreboard key = 127.0.0.1 val = SERVER_GRACEFUL
- scoreboard counter hash size = 11
- scoreboard key = SERVER_READY val = 4
- scoreboard key = SERVER_STARTING val = 0
- scoreboard key = SERVER_BUSY_READ val = 0
- scoreboard key = SERVER_BUSY_WRITE val = 1
- scoreboard key = SERVER_BUSY_KEEPALIVE val = 0
- scoreboard key = SERVER_BUSY_LOG val = 0
- scoreboard key = SERVER_BUSY_DNS val = 0
- scoreboard key = SERVER_CLOSING val = 0
- scoreboard key = SERVER_DEAD val = 251
- scoreboard key = SERVER_GRACEFUL val = 0
- scoreboard key = SERVER_IDLE_KILL val = 0
## Finfo Class Test
- permission = 1877
- filetype regular file = false
- user = 0
- group = 0
- device = 64768
- inode = 35205976
- nlink = 2
- size = 6
- csize = 0
- atime = 1.447969437e+15
- mtime = 1.447969437e+15
- ctime = 1.4556292035898e+15
__Test Complete. Wellcome to mod_mruby world!!__