Pleroma 踩坑记

从 Mastodon 跑路,很潦草的一个记录。如有问题欢迎在 Pleroma 联系我

Installation

Prerequisites: Ubuntu 20.04,from source

总体上来说,按官方 guide来安装还是较为顺利的,但这个 guide 对 Ubuntu 的支持很差,主要体现在 Elixir & Erlang 的安装上。

Elixir & Erlang 的安装

如果你是 Ubuntu 18.04 或 20.04 用户,请不要按官方 guide 说的直接 sudo apt install elixir erlang-dev erlang-nox,这样会装到错误的版本。如果已经不幸踩坑,可以按照这个 uninstall.

也不要用 asdf,asdf 对非 root 用户很不友好,若按其官方教程安装,则其安装的 dependencies 无法被非 root 的用户(在本例中是 pleroma 用户)使用。我按这个 issue 中说的配置之后也不能解决该问题,恳请读者赐教。

使用这个教程中的方法可以顺利安装 Elixir \u0026 Erlang. 复制命令如下:

# Install the Erlang Solutions apt key; Alternative way https://askubuntu.com/questions/1286545/what-commands-exactly-should-replace-the-deprecated-apt-key\nwget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc\nsudo apt-key add erlang_solutions.asc

# 'focal' is the latest available but an empty 'impish' directory exists and will probably be ready soon

sudo echo 'deb https://packages.erlang-solutions.com/ubuntu focal contrib' | sudo tee /etc/apt/sources.list.d/erlang-solutions.list
sudo apt update
sudo apt install esl-erlang elixir

如何将 Pleroma 和 Mastodon 安装在同一 server 上

Mastodon 默认占用 port 3000 和 4000 监听,Pleroma 的默认设置是 port 4000,解决方法是在配置文件(应为 /opt/pleroma/config/prod.secret.exs)中把

http: [ip: {127, 0, 0, 1}, port: 4000]

中的 4000 改成一个 3000 和 4000 之外的数。我在这里改的是 5000.

同时在 Nginx 配置中更改相应部分:

# this is explicitly IPv4 since Pleroma.Web.Endpoint binds on IPv4 only
# and `localhost.` resolves to [::0] on some systems: see issue #930
upstream phoenix {
    server 127.0.0.1:4000 max_fails=5 fail_timeout=60s;
} # 将这里的 4000 改掉

魔改

那么,怎么对 Pleroma 进行魔改呢?

GitLab

使用方法与 GitHub 相近,把源代码 fork 到自己的账号,然后进行改动即可。以下描述改完之后的操作。

Pleroma-BE

/opt/pleroma 下进行操作。

添加分支:

git remote add <你的魔改远程库在 server 中的代号,可以随便取一个> https://git.pleroma.social/<你的 GitLab 用户名>/pleroma.git
git remote -v

在服务器上将魔改的代码和本地代码进行合并:

git fetch <魔改库代号>
git merge <魔改库代号>/<魔改库中的 branch 名>

接下来参考升级时的操作:

sudo -Hu pleroma MIX_ENV=prod mix deps.get
sudo systemctl stop pleroma
sudo -Hu pleroma MIX_ENV=prod mix ecto.migrate
sudo systemctl restart pleroma

Pleroma-FE

参考了官方文档

先找个地儿把魔改的代码拉到 server 上,我选择了 /opt/pleromafe,在这里进行操作:

git init\ngit remote add <魔改库代号,再随便取一个> https://git.pleroma.social/<你的 GitLab 用户名>/pleroma-fe.git
git remote -v

下一步同上节,在服务器上将魔改的代码和本地代码进行合并:

git fetch<魔改库代号>
git merge <魔改库代号>/<魔改库中的 branch 名>

yarn 获取 dependencies:

yarn

编辑示例配置文件:

cp config/local.example.json config/local.json
nano config/local.json

将其中的 target 部分改成自己的域名。

yarn 编译:

yarn build

把编译生成的内容,即 dist 文件夹中的所有内容复制到后端的 static directory(通常为 /opt/pleroma/instance/static):

cp -r /opt/pleromafe/dist/* /opt/pleroma/instance/static

重启 Pleroma service:

sudo systemctl restart pleroma

结束。

致谢

感谢光哥在我建站的过程中对我提供的无私援助,没有她就没有 The Real Mammonteus.

#code #Pleroma #Fediverse