AmazonLinuxにCaveman2をHostingする
- Apr 09, 2019
- AWS
takeokunn/portoflio を作ったので実際にAWSにホスティングしたのでそのやり方についてメモしていく。
実際のサイトはこちら portfolio.takeokunn.xyz
Caveman2
のHostingをしてる記事が全然見当たらなかったので結構苦労した。
とりあえず適当に EC2
を立てて、 ssh
で入る。
~ (*´ω`*) < ssh portfolio
The authenticity of host '54.248.214.96 (54.248.214.96)' can't be established.
ECDSA key fingerprint is SHA256:LC35gz4Hs1/FyX8mXbtHQ1DYYEQSQLkYcBumhDzRJCI.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '54.248.214.96' (ECDSA) to the list of known hosts.
__| __|_ )
_| ( / Amazon Linux 2 AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-2/
1 package(s) needed for security, out of 1 available
Run "sudo yum update" to apply all updates.
必要なものをとりあえず突っ込む。
$ sudo yum update
$ sudo yum upgrade
$ sudo yum install -y git zlib-devel automake libcurl-devel nginx
roswellを入れる。
公式ドキュメント: https://github.com/roswell/roswell/wiki/Installation
$ git clone -b release https://github.com/roswell/roswell.git
$ cd roswell
$ sh bootstrap
$ ./configure --prefix=$HOME/.local
$ make
$ make install
$ echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.profile
$ PATH=$HOME/.local/bin:$PATH ros setup
自分のrepoをinstall
$ ros install takeokunn/portfolio
clackを入れて動くかどうか試してみる。
$ ros install clack
$ cd /path/to/takeokunn/portoflio
$ APP_ENV=production clackup ~/.roswell/local-projects/takeokunn/portfolio/app.lisp --server woo --debug nil
次にnginxの設定をする。だいたいこんな感じ。 proxy_pass
に突っ込むだけ。(静的コンテンツは別途routingしても良い)
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name portfolio.takeokunn.xyz;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5000/;
}
}
}
次に、 clack
を自動起動設定する。
起動コマンドを /opt/portfolio.sh
に作る。
#!/bin/bash
APP_ENV=production /home/ec2-user/.roswell/bin/clackup /home/ec2-user/.roswell/local-projects/takeokunn/portfolio/app.lisp --server woo --debug nil
次にserviceに登録するためのfileを作る。
/etc/systemd/system/portfolio.service
を作った。
ポイントは User
や Group
がroswellと同じものを使うこと。
[Unit]
Description = portfolio daemon
[Service]
ExecStart = /opt/portfolio.sh
Restart = always
Type = simple
User = ec2-user
Group = ec2-user
[Install]
WantedBy = multi-user.target
あとは以下を実行して自動起動するようにする。
$ sudo systemctl enable portfolio
$ sudo systemctl start portfolio
これでできた。
思ったよりも詰まってしまった。
特に、 systemctl
から roswell
の処理を呼ぶ部分のpermissionなどが知見がなく苦労した。
MySQLとうまく接続が未だできていない状態なので今後調整していきたい。