在 Debian 10 上安装 Pleroma

7 minute read

本文完全按照官网文档,无脑安装,Installing on Linux using OTP releases。安装系统Linux 版本: Debian 10

What is OTP Releases

OTP releases are as close as you can get to binary releases with Erlang/Elixir. The release is self-contained, and provides everything needed to boot it

按照我的理解 OTP releases就是一个已经编译好的程序包,下载安装就可以运行,省略了编译这一步。

Pre-requisites

Installing the required packages

  1. curl (下载安装包)
  2. unzip (解压安装包)
  3. ncurses (ERTS 运行需要)
  4. PostgreSQL (also utilizes extensions in postgresql-contrib)
  5. nginx (反代需要,可以选其他)
  6. certbot (SSL 证书需要,可以选其他)
  7. libmagic/file
1apt install curl unzip libncurses5 postgresql postgresql-contrib nginx certbot libmagic-dev

Installing optional packages

  1. imagemagick (图像处理)
  2. ffmpeg (音频视频处理)
  3. exiftool (媒体文件元数据处理)
1apt install imagemagick ffmpeg libimage-exiftool-perl

Setup

Detecting flavour

1arch="$(uname -m)";if [ "$arch" = "x86_64" ];then arch="amd64";elif [ "$arch" = "armv7l" ];then arch="arm";elif [ "$arch" = "aarch64" ];then arch="arm64";else echo "Unsupported arch: $arch">&2;fi;if getconf GNU_LIBC_VERSION>/dev/null;then libc_postfix="";elif [ "$(ldd 2>&1|head -c 9)" = "musl libc" ];then libc_postfix="-musl";elif [ "$(find /lib/libc.musl*|wc -l)" ];then libc_postfix="-musl";else echo "Unsupported libc">&2;fi;echo "$arch$libc_postfix"

检测系统后面会用到,如果没有显示结果,说明 Pleroma 没有提供相应平台的OTP安装包,请从源文件安装。

Installing Pleroma

 1# Create a Pleroma user
 2adduser --system --shell  /bin/false --home /opt/pleroma pleroma
 3
 4# Set the flavour environment variable to the string you got in Detecting flavour section.
 5# For example if the flavour is `amd64-musl` the command will be
 6export FLAVOUR="amd64-musl"
 7
 8# Clone the release build into a temporary directory and unpack it
 9su pleroma -s $SHELL -lc "
10curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job=$FLAVOUR' -o /tmp/pleroma.zip
11unzip /tmp/pleroma.zip -d /tmp/
12"
13
14# Move the release to the home directory and delete temporary files
15su pleroma -s $SHELL -lc "
16mv /tmp/release/* /opt/pleroma
17rmdir /tmp/release
18rm /tmp/pleroma.zip
19"
20# Create uploads directory and set proper permissions (skip if planning to use a remote uploader)
21# Note: It does not have to be `/var/lib/pleroma/uploads`, the config generator will ask about the upload directory later
22
23mkdir -p /var/lib/pleroma/uploads
24chown -R pleroma /var/lib/pleroma
25
26# Create custom public files directory (custom emojis, frontend bundle overrides, robots.txt, etc.)
27# Note: It does not have to be `/var/lib/pleroma/static`, the config generator will ask about the custom public files directory later
28mkdir -p /var/lib/pleroma/static
29chown -R pleroma /var/lib/pleroma
30
31# Create a config directory
32mkdir -p /etc/pleroma
33chown -R pleroma /etc/pleroma
34
35# Run the config generator
36su pleroma -s $SHELL -lc "./bin/pleroma_ctl instance gen --output /etc/pleroma/config.exs --output-psql /tmp/setup_db.psql"
37
38# Create the postgres database
39su postgres -s $SHELL -lc "psql -f /tmp/setup_db.psql"
40
41# Create the database schema
42su pleroma -s $SHELL -lc "./bin/pleroma_ctl migrate"
43
44# If you have installed RUM indexes uncommend and run
45# su pleroma -s $SHELL -lc "./bin/pleroma_ctl migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
46
47# Start the instance to verify that everything is working as expected
48su pleroma -s $SHELL -lc "./bin/pleroma daemon"
49
50# Wait for about 20 seconds and query the instance endpoint, if it shows your uri, name and email correctly, you are configured correctly
51sleep 20 && curl http://localhost:4000/api/v1/instance
52
53# Stop the instance
54su pleroma -s $SHELL -lc "./bin/pleroma stop"

Configuration of instance and postgreSQL

在安装过程中需要完成一些基本的设置。

 1What domain will your instance use? (e.g pleroma.soykaf.com) []  
 2你的网站的网址是什么?[填写域名]
 3  
 4What is the name of your instance? (e.g. Pleroma/Soykaf) []
 5你的网站叫什么名字?[会显示在站点标题栏]  
 6  
 7What is your admin email address? []
 8网站管理员的电子邮箱地址是什么?  
 9  
10What email address do you want to use for sending email notifications?   
11[]    
12你想要用哪个电子邮件地址来发送邮件通知?
13
14What is the hostname of your database? [localhost]
15数据库主机名称? [localhost]
16
17What is the name of your database? [pleroma]
18数据库名称? [pleroma]
19
20What is the user used to connect to your database? [pleroma]
21连接数据库的用户? [pleroma] # 在安装第一步创建的用户
22
23What is the password used to connect to your database? [autogenerated]
24用来连接数据库的密码? [autogenerated] # 自动创建
25
26Would you like to use RUM indices? [n] n
27要用 `RUM` 索引吗? [n] # 可选安装,本文不涉及
28
29What port will the app listen to (leave it if you are using the default setup with nginx)? [4000]
30希望应用监听的端口? [4000] # 默认4000,注意不要和别的服务冲突
31
32What ip will the app listen to (leave it if you are using the default setup with nginx)? [127.0.0.1]
33希望应用监听的ip? [127.0.0.1]
34
35What directory should media uploads go in (when using the local uploader)? [/var/lib/pleroma/uploads]
36希望上传媒体文件存放的路径? [/var/lib/pleroma/uploads]
37
38What directory should custom public files be read from (custom emojis, frontend bundle overrides, robots.txt, etc.)? [/var/lib/pleroma/static]
39希望自定义文件存放路径? [/var/lib/pleroma/static]
40
41Do you want search engines to index your site? (y/n) [n]   
42你希望搜索引擎收录你的网站吗?[建议选否]  
43  
44Do you want to store the configuration in the database (allows controlling it from admin-fe)? (y/n) [n] y  
45你希望将配置信息存入数据库吗(开启管理控制台)?[建议选是]  
46  
47Do you want to strip location (GPS) data from uploaded images? (y/n) [y]  
48是否要从上传的图像中删除地理位置(GPS)数据?[建议选是]  
49  
50Do you want to anonymize the filenames of uploads? (y/n) [n]  
51是否对上传的文件名进行匿名化处理?[建议选是]  
52  
53Do you want to deduplicate uploaded files? (y/n) [n]  
54是否避免上传重复的文件?[建议选是]

Setting up Nginx

复制 nginx 配置文件到相应路径。

1cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/conf.d/pleroma.conf

测试配置文件是否正确。

1nginx -t

重启 Nginx

1nginx -s reload

Setting up a system service

 1# Copy the service into a proper directory
 2cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
 3
 4# Start pleroma and enable it on boot
 5systemctl start pleroma
 6systemctl enable pleroma
 7
 8# Stop pleroma
 9systemctl stop pleroma
10
11# Restart pleroma 
12# Job type reload is not applicable for unit pleroma.service
13systemctl restart pleroma

Create your first user and set as admin

1cd /opt/pleroma
2su pleroma -s $SHELL -lc "./bin/pleroma_ctl user new joeuser [email protected] --admin"

创建成功后会获得一个网址,点击链接后跳转到创建密码的页面,注册就完成了。

Further reading

  1. back up instance
  2. updating instance
  3. hardening instance
  4. configuration cheat sheet
  5. theming instance
  6. customer emoji
  7. 修改css(?)