h2o構築作業メモ
http2を理解するためにh2oをインストール・起動しました。
構築する環境
h2oをインストール
# root ユーザで実行 # https://github.com/h2o/h2o/releases の tarファイルのURLから wget https://github.com/h2o/h2o/archive/v1.6.3.tar.gz tar xzf v1.6.3.tar.gz cd h20-1.6.3 cmake . make sudo make install
h2oを設定する
最終的な設定ファイル郡
root@precise64:/usr/local/etc# tree h2o/ h2o/ |-- access-log |-- cert.csr |-- cert.key |-- cert.pem |-- error-log |-- h2o.conf |-- index.html `-- pid-file
自己証明書の作成
$ mkdir /usr/local/etc/h2o/ $ cd /usr/local/etc/h2o/ $ openssl genrsa 2048 > cert.key $ openssl req -new -key cert.key > cert.csr $ openssl x509 -days 3650 -req -signkey cert.key < cert.csr > cert.pem
各種起動に必要なファイルを作成
$ touch /usr/local/etc/h2o/access-log $ touch /usr/local/etc/h2o/error-log $ touch /usr/local/etc/h2o/pid-file
confファイルの作成
$ cd /usr/local/etc/h2o/ $ vi h2o.conf #---------------------- 1 user: root 2 hosts: 3 "*": 4 listen: 5 port: 443 6 ssl: 7 certificate-file: /usr/local/etc/h2o/cert.pem 8 key-file: /usr/local/etc/h2o/cert.key 9 paths: 10 "/": 11 file.dir: /usr/local/etc/h2o/ 12 13 access-log: /usr/local/etc/h2o/access-log 14 error-log: /usr/local/etc/h2o/error-log 15 pid-file: /usr/local/etc/h2o/pid-file
index.htmlの作成
$ cd /usr/local/etc/h2o $ vi index.html ----------------------------- <html> <head> <title>hello, h2o! </title> </head> <body> hello, h2o! </body> <html>
起動と終了
# 起動前のテスト $ sudo /usr/local/bin/h2o -m test -c /usr/local/etc/h2o/h2o.conf # Backgroundプロセスとして起動 $ sudo /usr/local/bin/h2o -m daemon -c /usr/local/etc/h2o/h2o.conf # 停止 $ sudo kill -TERM `cat /usr/local/etc/h2o/pid-file`
アクセス
その他にやったこと
cmake をソースからインストール
apt-getでインストールしたcmakeのバージョンが古かったためソースコードからインストール
# rootユーザで実行 sudo apt-get install build-essential wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz --no-check-certificate tar xf cmake-3.2.2.tar.gz cd cmake-3.2.2 ./configure make make install
参考
Log Jenkins+nginx+AWS NAT Gateway
全体のイメージ
CIツールサーバを以下のような構成で構築してみました。
Subnet,NACL
これは作成しただけで、特に制限はしていません。 後に設定していきます。
Jenkinsサーバの作成
■ jenkinsインストール
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key sudo yum install jenkins sudo service jenkins start
■ 自動起動設定
sudo chkconfig jenkins on sudo chkconfig --list | grep "jenkins" jenkins 0:off 1:off 2:on 3:on 4:on 5:on 6:off
NAT Gatewayの作成・関連付け
参考ページとほぼおなじ内容を設定 JenkinsをおくサーバのSubnet(Private)にひも付けました。 参考: http://dev.classmethod.jp/cloud/aws/introduce-to-amazon-vpc-nat-gateway/
nginx サーバ作成
■ conf設定 とりあえず動いた設定
sudo cp /etc/nginx/conf.d/virtual.conf /etc/nginx/conf.d/jenkins.conf sudo vim /etc/nginx/conf.d/jenkins.conf --------------------------------------- server { listen 80; location / { proxy_pass http://{ip}:8080; } } --------------------------------------- sudo service nginx reload
■ 自動起動設定
sudo chkconfig nginx on sudo chkconfig --list | grep "nginx" nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
アクセスできました!
HTTPS設定
自己証明書によるHTTPS設定を行います。 少しでもセキュリティレベルをあげたいからです。 もちろん現時点ではhttpsでアクセスすると表示されません。
証明書の作成と設定
[ec2-user@ip-172-31-16-156 ~]$ sudo su [root@ip-172-31-16-156 ec2-user]# mkdir /etc/nginx/cert [root@ip-172-31-16-156 ec2-user]# cd /etc/nginx/cert [root@ip-172-31-16-156 cert]# openssl genrsa -des3 -out server.key 1024 Generating RSA private key, 1024 bit long modulus .....++++++ ......................................................++++++ e is 65537 (0x10001) Enter pass phrase for server.key: Verifying - Enter pass phrase for server.key: [root@ip-172-31-16-156 cert]# openssl req -new -key server.key -out server.csr Enter pass phrase for server.key: You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:Japan string is too long, it needs to be less than 2 bytes long Country Name (2 letter code) [XX]:JP State or Province Name (full name) []: Locality Name (eg, city) [Default City]: Organization Name (eg, company) [Default Company Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:ci-server Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
jenkins.confの変更
/etc/nginx/conf.d/jenkins.confを以下のように修正
server { #listen 80; #server_name somename alias another.alias; listen 443 default ssl; ssl on; ssl_certificate /etc/nginx/cert/server.crt; ssl_certificate_key /etc/nginx/cert/server.key; location / { proxy_pass http://{ip}:8080; } access_log /var/log/nginx/jenkins_access.log; error_log /var/log/nginx/jenkins_error.log; }
できました!
参考: http://qiita.com/narumi888/items/da664ce0aca5373fd9aa#2-18