在AWS上创建Mastodon的第三天

经过

这是关于在AWS上搭建Mastodon的第二天的续篇,之前我写过。

大约半年前,从完全不懂AWS和Docker开始,我们设法建立了实例并进行了运维工作。

我以前在EC2上使用Docker进行生产运营,但随着时间推移变得越来越困难,所以决定从Docker中卸载它。以下是操作日志。

环境 / 工具

macOS Mojave 10.14.6
亚马逊网络服务 (AWS)

我所参考的

以下是对原文的中国化改写:

Mastodon GitHub
https://github.com/tootsuite/mastodon
官方文档
https://docs.joinmastodon.org/admin/install/

在服务器上的操作工作

首先,我们需要通过SSH登录到服务器。

$ ssh ubuntu@3.112.***.*** -i ~/.ssh/hoge.pem

在开始工作之前,先暂时切换到root用户。

sudo su -

Nginx的安装配置

我将复制Mastodon上的示例。

$ cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon

更改符号链接。

$ ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
$ vi /etc/nginx/sites-available/mastodon

编辑server_name等内容,并将文件名改为自己的域名。

$ mv mastodon don.suwa3.me

当我重新加载Nginx时,出现了错误。

$ service nginx reload
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

我将使用service命令测试config。

$ service nginx configtest
 * Testing nginx configuration                                                                                       [fail] 

通过 nginx 命令进行原因调查。
据说是找不到文件或目录。

$ nginx -t
nginx: [emerg] open() "/etc/nginx/sites-enabled/mastodon" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed

搬迁

$ cd ../sites-enabled/

确认符号链接的目标方向。

$ ls -l
total 0
lrwxrwxrwx 1 root root 34 Jan 13 10:03 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 35 Jan 28 05:22 mastodon -> /etc/nginx/sites-available/mastodon

将Mastodon的部分更改为don.suwa3.me。

$ ln -sf /etc/nginx/sites-available/don.suwa3.me mastodon

我成功重新加载了。

$ service nginx reload

为了确认一下情况,我要检查一下状态。
活动:状态是活动(正在运行),所以没问题。

$ service nginx status
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) (Result: exit-code) since Tue 2020-01-28 05:16:57 CET; 31min ago
(略)

申请SSL证书

我们使用Let’s Encrypt来获取免费的SSL证书。
将example.com替换为您自己的域名。

$ certbot --nginx -d example.com

设置systemd服务

从Mastodon目录中复制systemd服务模板。

$ cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/

为了谨慎起见,请确认用户名和密码是否正确。

    • /etc/systemd/system/mastodon-web.service

 

    • /etc/systemd/system/mastodon-sidekiq.service

 

    /etc/systemd/system/mastodon-streaming.service

启动并启用新的systemd服务。

$ systemctl daemon-reload
$ systemctl start mastodon-web mastodon-sidekiq mastodon-streaming
$ systemctl enable mastodon-*

下次告诉你

第四天的任务是搬迁数据库和连接媒体服务器,完成后我想在Qiita上留下工作记录。