こんにちは,しまさん(@shimasan0x00)です.
先日,Mastodonをローカルに雑ではありますが構築しました.
https://murabitoleg.com/mastodon
今回は分散型SNSのひとつであるPleromaをMac+Dockerで雑に構築していきたいと思います.
今回の環境
・Mac OS High Sierra 10.13.5
・Docker for Mac : Version 18.06.1-ce-mac73
・nginx version: nginx/1.15.3
・Elixir : 1.7.3
Pleromaとは
PleromaとはElixirで書かれた分散型SNSのひとつ.
GNU SocialやMastodonとも連携することが可能.Pleromaによればラズパイでも動く軽さが特徴.
Mastodonはなんだかんだリソースを結構くうので軽いのは嬉しいです.
Docker for Macのインストール
https://murabitoleg.com/mastodon/
インストールについてはこちらに書いてあります.
Elixirのインストール(必要なら)

まずはElixirのページに行きましょう.
自分のOSに合ったインストール方法を選んでください. Macの場合はHomebrewでインストールできます.
brew update
brew install elixir
Pleromaのインストール

まずはPleromaをインストールするためのディレクトリを作成しましょう.
mkdir Pleroma && cd Pleroma
ではgit cloneで落としてきましょう.また,Dockerfileを落としてきます.
git clone https://git.pleroma.social/pleroma/pleroma.git
git clone git clone https://github.com/angristan/docker-pleroma.git
docker-pleromaからDockerファイルをpleromaに移動させてください. そうしたらvimでdocker-compose.ymlを作成します.
cd pleroma
vim docker-compose.yml
################docker-compose.yml#######################
version: '2.3'
services:
postgres:
image: postgres:9.6-alpine
container_name: pleroma_postgres
restart: always
environment:
POSTGRES_USER: pleroma
POSTGRES_PASSWORD: pleroma
POSTGRES_DB: pleroma
volumes:
- ./postgres:/var/lib/postgresql/data
web:
build: .
image: pleroma
container_name: pleroma_web
restart: always
ports:
- "127.0.0.1:4000:4000"
volumes:
- ./uploads:/pleroma/uploads
depends_on:
- postgres
次はconfigのディレクトリを作成&postgresの設定をします.
mkdir uploads config #ない場合
sudo chown -R 911:911 uploads
docker-compose up -d postgres
docker exec -i pleroma_postgres psql -U pleroma -c "CREATE EXTENSION IF NOT EXISTS citext;"
docker-compose down
設定が終わったら,./config/secret.exsに以下の内容を書き込みましょう.
use Mix.Config
config :pleroma, Pleroma.Web.Endpoint,
url: [host: "pleroma.domain.tld", scheme: "https", port: 443],
secret_key_base: "<use 'openssl rand -base64 48' to generate a key>"
config :pleroma, :instance,
name: "Pleroma",
email: "admin@email.tld",
limit: 5000,
registrations_open: true
config :pleroma, :media_proxy,
enabled: false,
redirect_on_failure: true,
base_url: "https://cache.domain.tld"
# Configure your database
config :pleroma, Pleroma.Repo,
adapter: Ecto.Adapters.Postgres,
username: "pleroma",
password: "pleroma",
database: "pleroma",
hostname: "postgres",
pool_size: 10
ただし,変更点がいくつかあります.
secret_key_baseとhost,email部分です.
secret_key_baseは以下のコマンドで実行した結果を貼り付けましょう.
openssl rand -base64 48
host部分は自分のドメインを代入してください.
私の場合はlocalhost:4000とします.
前回のMastodonと同じです.emailですが適当でいいです.
もちろん自分の持っているものでも構いません.
ではDockerイメージを作成しましょう.
時間がかかるので少々お待ち下さい.
docker-compose build
作成したらDatabaseのセットアップをしましょう.
docker-compose run --rm web mix ecto.migrate
ではPleromaのインスタンスを起動させましょう!!!!
docker-compose up -d
起動させるのはいいのですが,まだNginxの設定がまだなので行っていきます.
基本はMastodnonのときと同じです.
SSL証明書はオレオレ証明書でいきます.
SSL証明書を用意されてない人は前回のMastodonの記事をみてください.今回はlocalhost:4000で取得しました.
https://murabitoleg.com/mastodon/
ではNginxの設定をしていきましょう.
vim /usr/local/etc/nginx/nginx.conf
#nginx.connf
34: include /Users/shimadakyousuke/Pleroma/pleroma/installation/pleroma.nginx; #追加
pleroma.nginxの内容ですが,以下のサイトのものを一部改変します.
SSL証明書の部分やドメイン部分は自分のものに置き換えてください.
#pleroma.nginx
# default nginx site config for Pleroma
#
# Simple installation instructions:
# 1. Install your TLS certificate, possibly using Let's Encrypt.
# 2. Replace 'example.tld' with your instance's domain wherever it appears.
# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
# in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=10g
inactive=720m use_temp_path=off;
server {
listen 80;
server_name localhost:4000;
return 301 https://$server_name$request_uri;
# Uncomment this if you need to use the 'webroot' method with certbot. Make sure
# that you also create the .well-known/acme-challenge directory structure in pleroma/priv/static and
# that is is accessible by the webserver. You may need to load this file with the ssl
# server block commented out, run certbot to get the certificate, and then uncomment it.
#
# location ~ /\.well-known/acme-challenge {
# root /pleroma/priv/static/;
# }
}
# Enable SSL session caching for improved performance
ssl_session_cache shared:ssl_session_cache:10m;
server {
listen 443 ssl http2;
ssl_session_timeout 5m;
ssl_trusted_certificate /自分が作成した場所/localhost:4000.crt;
ssl_certificate /自分が作成した場所/localhost:4000.crt;
ssl_certificate_key /自分が作成した場所/localhost:4000.key;
# Add TLSv1.0 to support older devices
ssl_protocols TLSv1.2;
# Uncomment line below if you want to support older devices (Before Android 4.4.2, IE 8, etc.)
# ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_prefer_server_ciphers on;
# In case of an old server with an OpenSSL version of 1.0.2 or below,
# leave only prime256v1 or comment out the following line.
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
ssl_stapling on;
ssl_stapling_verify on;
server_name localhost:4000;
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 application/activity+json application/atom+xml;
# the nginx default is 1m, not enough for large media uploads
client_max_body_size 16m;
location / {
# if you do not want remote frontends to be able to access your Pleroma backend
# server, remove these lines.
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'POST, PUT, DELETE, GET, PATCH, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Idempotency-Key' always;
add_header 'Access-Control-Expose-Headers' 'Link, X-RateLimit-Reset, X-RateLimit-Limit, X-RateLimit-Remaining, X-Request-Id' always;
if ($request_method = OPTIONS) {
return 204;
}
# stop removing lines here.
add_header X-XSS-Protection "1; mode=block";
add_header X-Permitted-Cross-Domain-Policies none;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header Referrer-Policy same-origin;
add_header X-Download-Options noopen;
add_header Content-Security-Policy "default-src 'none'; base-uri 'self'; form-action 'self'; img-src 'self' data: https:; media-src 'self' https:; style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self'; connect-src 'self' wss://example.tld; upgrade-insecure-requests;";
# Uncomment this only after you get HTTPS working.
# add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_pass http://localhost:4000;
client_max_body_size 16m;
}
location /proxy {
proxy_cache pleroma_media_cache;
proxy_cache_lock on;
proxy_ignore_client_abort on;
proxy_pass http://localhost:4000;
}
}
ではNginxを起動させましょう.
sudo nginx
#停止させるには
sudo nginx -s stop
#再起動
sudo nginx -s reload
そしたら<https://localhost>にアクセスしてください.

おぉ〜〜〜〜〜.Pleromaが起動しました!!!!!!!!!!!
では起動したPleromaに参加するためにユーザー登録していきましょう.
docker-compose run --rm web mix register_user
パスワードをリセットする場合は次のコマンドを実行してください.
リセットしたユーザーにリンクが送られます.
ただし,今回はメールアドレスを適当に設定しているのでおすすめはしません.
docker-compose run --rm web mix generate_password_reset username
モデレーター(いわゆるアドミン)になりたい場合は次のコマンドを実行してください.
docker-compose run --rm web mix mix set_moderator username [true|false]
Pleromaでつぶやきますか.
今のPleromaでは「はねだくうこうに,つきました.」がデフォなのね… .

さいごに
今回はDocker+Macを用いて雑ではありますがPleromaを動かしました.
localhostで今回動かしましたが今後はちゃんとドメインとって動かしたいですね.
もっと日本語のドキュメントが増えるといいな.