Update install.md

This commit is contained in:
Jiean Ru 2023-12-06 21:39:11 +08:00 committed by GitHub
parent f2b3dfb70a
commit cb4876f2a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 50 additions and 34 deletions

View File

@ -1,6 +1,6 @@
--- ---
title: 从源中安装 title: 从源代码中安装
description: 创建你自己的Mastodon站点的教学指献。 description: 创建你自己的 Mastodon 站点的教学指献。
menu: menu:
docs: docs:
weight: 20 weight: 20
@ -9,27 +9,31 @@ menu:
## 前提条件 {#pre-requisites} ## 前提条件 {#pre-requisites}
* 一台你有root访问权限的运行 **Ubuntu 18.04** 的机器 * 一台你有root访问权限的,运行 **Ubuntu 20.04****Debian 11** 的机器
* 一个用于Mastodon站点的**域名**(或一个子域名),例如:`example.com` * 一个用于Mastodon站点的**域名**(或一个子域名),例如:`example.com`
* 一个电子邮件发送服务提供商,或其他**SMTP服务器** * 一个电子邮件发送服务提供商,或其他**SMTP服务器**
你需要使用root用户运行命令。如果你现在不是root用户请切换至root用户 你需要使用root用户运行命令。如果你现在不是root用户请切换至root用户``sudo su - ``
### 软件仓库 {#system-repositories} ### 软件仓库 {#system-repositories}
首先确保已经安装curl 首先确保已经安装curl, wget, gnupg, apt-transport-https, lsb-release 和 ca-certificates
```
apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates
```
#### Node.js {#node-js} #### Node.js {#node-js}
```bash ```bash
curl -sL https://deb.nodesource.com/setup_12.x | bash - curl -sL https://deb.nodesource.com/setup_16.x | bash -
``` ```
#### Yarn {#yarn} #### PostgreSQL {#postgresql}
```bash ```bash
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - wget -O /usr/share/keyrings/postgresql.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list echo "deb [signed-by=/usr/share/keyrings/postgresql.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/postgresql.list
``` ```
### 软件包 {#system-packages} ### 软件包 {#system-packages}
@ -40,9 +44,16 @@ apt install -y \
imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \ imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \
g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf \ g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf \
bison build-essential libssl-dev libyaml-dev libreadline6-dev \ bison build-essential libssl-dev libyaml-dev libreadline6-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev \ zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \
nginx redis-server redis-tools postgresql postgresql-contrib \ nginx redis-server redis-tools postgresql postgresql-contrib \
certbot python-certbot-nginx yarn libidn11-dev libicu-dev libjemalloc-dev certbot python3-certbot-nginx libidn11-dev libicu-dev libjemalloc-dev
```
#### Yarn {#yarn}
```bash
corepack enable
yarn set version classic
``` ```
### 安装 Ruby {#installing-ruby} ### 安装 Ruby {#installing-ruby}
@ -53,7 +64,7 @@ apt install -y \
adduser --disabled-login mastodon adduser --disabled-login mastodon
``` ```
切换到mastodon用户 切换到 mastodon 用户:
```bash ```bash
su - mastodon su - mastodon
@ -63,7 +74,6 @@ su - mastodon
```bash ```bash
git clone https://github.com/rbenv/rbenv.git ~/.rbenv git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec bash exec bash
@ -73,8 +83,8 @@ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
上述操作完成,我们便可以安装正确的 Ruby 版本: 上述操作完成,我们便可以安装正确的 Ruby 版本:
```bash ```bash
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.6.6 RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.2.2
rbenv global 2.6.6 rbenv global 3.2.2
``` ```
我们同样需要安装 bundler 我们同样需要安装 bundler
@ -130,7 +140,7 @@ su - mastodon
```bash ```bash
git clone https://github.com/mastodon/mastodon.git live && cd live git clone https://github.com/mastodon/mastodon.git live && cd live
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1) git checkout $(git tag -l | grep '^v[0-9.]*$' | sort -V | tail -n 1)
``` ```
#### 安装依赖 {#installing-the-last-dependencies} #### 安装依赖 {#installing-the-last-dependencies}
@ -170,6 +180,16 @@ RAILS_ENV=production bundle exec rake mastodon:setup
exit exit
``` ```
### Acquiring a SSL certificate {#acquiring-a-ssl-certificate}
使用 Lets Encrypt 获取免费的 SSL 证书:
```bash
certbot certonly --nginx -d example.com
```
这将获取证书,并保存到 `/etc/letsencrypt/live/example.com/`
### 配置 nginx {#setting-up-nginx} ### 配置 nginx {#setting-up-nginx}
从Mastodon目录复制配置文件模版到nginx 从Mastodon目录复制配置文件模版到nginx
@ -181,18 +201,14 @@ ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
编辑 `/etc/nginx/sites-available/mastodon`,替换 `example.com` 为你自己的域名,你可以根据自己的需求做出其它的一些调整。 编辑 `/etc/nginx/sites-available/mastodon`,替换 `example.com` 为你自己的域名,你可以根据自己的需求做出其它的一些调整。
取消注释 `ssl_certificate``ssl_certificate_key` 开头的行 , 将路径改为对应的域名
重载 nginx 以使变更生效: 重载 nginx 以使变更生效:
### 获取SSL证书 {#acquiring-a-ssl-certificate}
我们将使用 Lets Encrypt 获取一个免费的SSL证书
```bash ```bash
certbot --nginx -d example.com systemctl reload nginx
``` ```
这个命令将获取一个证书,自动更新 `/etc/nginx/sites-available/mastodon` 以使用新证书并重载nginx以使变更生效。
现在你应该能够通过浏览器访问你的域名然后看到一只大象锤击电脑屏幕的错误页面。这是因为我们还没有启动Mastodon进程。 现在你应该能够通过浏览器访问你的域名然后看到一只大象锤击电脑屏幕的错误页面。这是因为我们还没有启动Mastodon进程。
### 配置 systemd 服务 {#setting-up-systemd-services} ### 配置 systemd 服务 {#setting-up-systemd-services}
@ -203,20 +219,20 @@ certbot --nginx -d example.com
cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/ cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
``` ```
然后修改以下文件,以保证用户名与路径是正确的 如果在任何时候偏离了默认值,请检查用户名和路径是否正确
* `/etc/systemd/system/mastodon-web.service` ```sh
* `/etc/systemd/system/mastodon-sidekiq.service` $EDITOR /etc/systemd/system/mastodon-*.service
* `/etc/systemd/system/mastodon-streaming.service`
最后启动新systemd服务并将该服务设为开机自动激活
```bash
systemctl daemon-reload
systemctl start mastodon-web mastodon-sidekiq mastodon-streaming
systemctl enable mastodon-*
``` ```
最后,启动并启用新的 systemd 服务:
```sh
systemctl daemon-reload
systemctl enable --now mastodon-web mastodon-sidekiq mastodon-streaming
```
他们将在开机启动时自动开始运行。 他们将在开机启动时自动开始运行。
{{< hint style="success" >}} {{< hint style="success" >}}