Mastodonインスタンス(お一人様用)を作り方メモ
Mastodonは運営の存在を気にせず罵詈雑言吐けるの便利そう。
自分用のインスタンス作ったので、便所の落書きしておく。
用意するもの
- ドメイン(私はサブドメインを使った)
- サーバー(私はDigitalOceanの1番安いヤツを使った)
事前にやっておくこと
- DNSレコードの設定(やればできる)
- 手元のPCでDocker環境を作っておく(docker-machine,docker-composeを使う)
- Dockerの使い方を知っておく(知ってるよね)
Dockerで雑にMastodonを起動する方法 とか読めばOK
作り方
http://qiita.com/sawanoboly/items/c7d6b913fd5455fb0f36
https://github.com/tootsuite/mastodon#running-with-docker-and-docker-compose
↑この辺見れば終わり
流れをダラダラ書くと…
- docker-machineでリモート環境(今回はDigitalOcean)にDocker環境を整える
- docker-machine create –driver digitalocean –digitalocean-access-token=[あなたのアクセストークン] [任意のマシン名]
- しょぼいサーバーだとメモリ不足してちょいちょい困るのでswap作っておくと良いと思います
- mastodonをcloneする
- docker-compose build する
- .env.production を作る
- docker-compose run –rm web rake secret を3回やって、.env.productionのPAPERCLIP_SECRET、SECRET_KEY_BASE、OTP_SECRETを埋める
- LOCAL_DOMAINやらを自分用の値に変える
- RailsアプリのDB初期化やら、アセットのプリコンパイルをする
- docker-compose run –rm web rails db:migrate
- docker-compose run –rm web rails assets:precompile
- docker-compose up -d でコンテナたちを起動する
- http://[あなたのドメイン]:3000/about でサインアップする
- アカウントのメール認証は面倒なのでコマンドやる
- http://qiita.com/sawanoboly/items/c7d6b913fd5455fb0f36#%E3%83%A1%E3%83%BC%E3%83%AB%E5%BC%B7%E5%88%B6confirmation%E3%81%A8%E7%AE%A1%E7%90%86%E8%80%85%E3%81%AB%E6%98%87%E6%A0%BC を参照
- docker-compose run –rm web rails mastodon:confirm_email USER_EMAIL=anata@example.com
- docker-compose run –rm web rails mastodon:make_admin USERNAME=anata
- お一人様インスタンスにしたいので .env.production のSINGLE_USER_MODEってヤツをtrueにして再度、docker-compose up -d
- httpsできるようにする(今回はレッツエンクリプトでやったよ)
- nginxの設定をdocker-compose.ymlに追加する
と、上記の参考URLの通りやってるだけなので、なんの知見もない。
公式の解説だとnginxの設置だけリモートサーバーでお手製でやってた。
面倒なのでdockerで用意するようにした。
nginxの設定をdocker-compose.ymlに追加する
↓のようなカンジのヤツを追加する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
nginx: restart: always build: context: ./containers/nginx dockerfile: Dockerfile ports: - "80:80" - "443:443" volumes: - /etc/letsencrypt/live/toot.hogehuga.com:/etc/letsencrypt/live/toot.hogehuga.com - /etc/letsencrypt/archive/toot.hogehuga.com:/etc/letsencrypt/archive/toot.hogehuga.com links: - web - streaming |
コンテナ関係のファイルを何も考えずにダラダラ置いていくとコンテナ増えたときにカオスになる。
というわけでcontainersフォルダを作り、ミドルウェア毎にフォルダを作った。
↑こういうことをしてしまったので、contextを使ってnginxコンテナの設定が置いてある場所を明記する必要があるわけ。
dockerfileは省略してもOK
Dockerfileはこんなカンジ
1 2 3 |
FROM nginx ADD sites-enabled/production_project /etc/nginx/sites-enabled/project COPY nginx.conf /etc/nginx/nginx.conf |
production_projectはこんなカンジ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; server_name toot.hogehuga.com; charset utf-8; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name toot.hogehuga.com; ssl_certificate /etc/letsencrypt/live/toot.hogehuga.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/toot.hogehuga.com/privkey.pem; ssl_protocols TLSv1.2; ssl_ciphers EECDH+AESGCM:EECDH+AES; ssl_ecdh_curve prime256v1; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; keepalive_timeout 70; sendfile on; client_max_body_size 0; gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; add_header Strict-Transport-Security "max-age=31536000"; location / { try_files $uri @proxy; } location @proxy { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Proxy ""; proxy_pass_header Server; proxy_pass http://web:3000; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; tcp_nodelay on; } location /api/v1/streaming { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Proxy ""; proxy_pass http://web:4000; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; tcp_nodelay on; } error_page 500 501 502 503 504 /500.html; } |
nginx.confはこんなカンジ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
user www-data; worker_processes 4; error_log /var/log/nginx/error.log warn; pid /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 /dev/stdout main; sendfile on; #tcp_nopush on; keepalive_timeout 65; gzip on; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } daemon off; |