Virutalbox上のUbuntu 16.04ltsだと信じてる
以下に出てくる設定ファイル中の文字列「your_rootfs」は文字通り、この名称のディレクトリで試した。
以下、関係ないかもだが、やってた。
echo 1 > /proc/sys/net/ipv4/ip_forward
よく分ってないからReadme.mdを参考につくったやつ。たぶんlxcをつかってるっぽい。
Haconiwa::Base.define do |config|
config.name = "new-haconiwa001" # to be hostname
config.bootstrap do |b|
b.strategy = "lxc"
b.os_type = "ubuntu"
end
config.provision do |p|
p.run_shell "apt install -y git"
end
config.cgroup["cpu.shares"] = 2048
config.cgroup["memory.limit_in_bytes"] = 256 * 1024 * 1024
config.cgroup["pids.max"] = 1024
config.add_mount_point "/var/another/root/etc", to: "/var/your_rootfs/etc", readonly: true
config.add_mount_point "/var/another/root/home", to: "/var/your_rootfs/home"
config.mount_independent "procfs"
config.mount_independent "sysfs"
config.chroot_to "/var/your_rootfs"
config.namespace.unshare "ipc"
config.namespace.unshare "uts"
config.namespace.unshare "mount"
config.namespace.unshare "pid"
config.capabilities.allow :all
config.capabilities.drop "cap_sys_admin"
end
# h2oのビルド
ubuntu16.04だとlibuvが古く(h2oが期待しているバージョンに比べて)、git cloneして入れる必要がった。
libuv.aをリンクするので、haconiwa側でとくに考慮する必要はない。
mkdir build
cd build
PKG_CONFIG_PATH=/var/another/root/home/local/lib/pkgconfig cmake -DCMAKE_INSTALL_PREFIX=/var/another/root/home/local -DWITH_BUNDLED_SSL=on ..
コンテナにユーザー管理のリソース入れるのも手間かかりそうだったので、rootで動かす方法が有ったのでこれで試した。
user: root
listen: 8080
listen:
port: 8081
ssl:
certificate-file: examples/h2o/server.crt
key-file: examples/h2o/server.key
hosts:
"127.0.0.1.xip.io:8080":
paths:
/:
file.dir: examples/doc_root
mruby.handler-file: examples/h2o_mruby/hello.rb
access-log: /dev/stdout
"alternate.127.0.0.1.xip.io:8081":
listen:
port: 8081
ssl:
certificate-file: examples/h2o/alternate.crt
key-file: examples/h2o/alternate.key
paths:
/:
file.dir: examples/doc_root.alternate
access-log: /dev/stdout
いろいろ、文句言われるので、/etc配下を中心にファイルをなんとか置くなりする。
haconiwaのコンテナ内からこれらを埋め込まれたパス(/var/another/root/home/local)で読み込めるようにする必要があった。
mkdir -p /var/another/root/home
cd /var/another/root/home/
ln -s /home/local .
/home/local/bin/h2o -c examples/h2o_mruby/h2o.conf
動き出すと
[INFO] raised RLIMIT_NOFILE to 65536
h2o server (pid:157) is ready to serve requests
fetch-ocsp-response (using OpenSSL 1.0.2g 1 Mar 2016)
failed to extract ocsp URI from examples/h2o/server.crt
fetch-ocsp-response (using OpenSSL 1.0.2g 1 Mar 2016)
[OCSP Stapling] disabled for certificate file:examples/h2o/server.crt
failed to extract ocsp URI from examples/h2o/server.crt
[OCSP Stapling] disabled for certificate file:examples/h2o/server.crt
fetch-ocsp-response (using OpenSSL 1.0.2g 1 Mar 2016)
failed to extract ocsp URI from examples/h2o/alternate.crt
[OCSP Stapling] disabled for certificate file:examples/h2o/alternate.crt
fetch-ocsp-response (using OpenSSL 1.0.2g 1 Mar 2016)
failed to extract ocsp URI from examples/h2o/alternate.crt
[OCSP Stapling] disabled for certificate file:examples/h2o/alternate.crt
10.0.3.1 - - [15/Feb/2017:03:45:11 +0000] "GET / HTTP/2" 200 177 "-" "nghttp2/1.7.1"
10.0.3.1 - - [15/Feb/2017:03:46:18 +0000] "GET /hge.rb HTTP/2" 200 147 "-" "nghttp2/1.7.1"
nghttp https://10.0.3.1:8081/hge.rb
hello from h2o_mruby. User-Agent:nghttp2/1.7.1 New User-Agent:new-nghttp2/1.7.1-h2o_mruby path:/hge.rb host:10.0.3.1:8081 method:GET query: input:
使っていません^^ mrubyでコンテナ関連のmgemをそれぞれ作っています。
中身についてはちょっと前に日本語で発表しております https://speakerdeck.com/udzura/the-haconiwa-internals