![](/style/images/good.png)
![](/style/images/bad.png)
Mastodon Docker 部署
source link: https://azhuge233.com/mastodon-docker-%e9%83%a8%e7%bd%b2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
接上篇 去中心化社交平台Mastodon(v2.7.3)的部署
- SMTP邮件服务(重要,安装完毕后需要发送邮件来注册管理员账户)
- Ubuntu 18.04
- Nginx
- Docker CE 以及 Docker-compose
- Running a Mastodon instance on Ubuntu 16.04 with Docker & nginx
- 还有一篇官方仓库的文档 Docker-Guide.md,但按照其步骤最后无法正常显示页面——运行向导时构建数据库出错,编译assets出错,导致docker run后web container处于不健康状态。
- 安装Nginx、Docker CE 以及 Docker-compose
- Nginx
apt install nginx
apt install nginx
- Docker 安装详见 多平台安装Docker 这里直接给出指令
wget -qO- https://get.docker.com/ | sh
wget -qO- https://get.docker.com/ | sh
- Docker 安装完毕后再安装 Docker-compose,详见 Github发布页,同样给出指令
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-composechmod +x /usr/local/bin/docker-compose
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose # 权限 chmod +x /usr/local/bin/docker-compose
注意第一条指令中url的版本号,选择Latest release版本。
- Nginx
- 分配交换空间(已有可跳过)
- 详见 Increase Ubuntu Swap partition,这里直接给出指令
fallocate -l 1G /swapchmod 600 /swapmkswap /swapswapon /swap# checkfree -m
fallocate -l 1G /swap chmod 600 /swap mkswap /swap swapon /swap # check free -m
- 详见 Increase Ubuntu Swap partition,这里直接给出指令
- 新建用户并赋予root权限
adduser mastodonusermod -aG sudo mastodon# 切换到mastodon用户su - mastodon
adduser mastodon usermod -aG sudo mastodon # 切换到mastodon用户 su - mastodon
- 安装Mastodon
- 进入mastodon用户主目录
cd /home/mastodon
cd /home/mastodon
- 克隆仓库
git clone https://github.com/tootsuite/mastodon.git# 进入目录cd mastodon
git clone https://github.com/tootsuite/mastodon.git # 进入目录 cd mastodon
- 复制生产环境配置文件
cp .env.production.sample .env.production
cp .env.production.sample .env.production
- 构建Docker镜像
docker-compose build
docker-compose build
这一步耗时很长,中间报错可以不理会,最后提示成功构建即可。
- 生成密钥
docker-compose run --rm web rake secret
docker-compose run --rm web rake secret
运行上述指令三次,记录每次输出的密钥。
- 编辑生产环境配置文件
- 将密钥分别分配给PAPERCLIP_SECRET, SECRET_KEY_BASE 和 OTP_SECRET变量
PAPERCLIP_SECRET=密钥1SECRET_KEY_BASE=密钥2OTP_SECRET=密钥3
PAPERCLIP_SECRET=密钥1 SECRET_KEY_BASE=密钥2 OTP_SECRET=密钥3
顺序不必固定,保证三个变量密钥不同即可。
配置文件中可能没有 PAPERCLIP_SECRET 这个变量,需要手动输入(不添加PAPERCLIP_SECRET变量的后果不确定)。
- 更改文件中的LOCAL_DOMAIN变量,将其值改为自己的域名
LOCAL_DOMAIN=[your domain]
LOCAL_DOMAIN=[your domain]
- 设置SMTP邮件服务。
我的部署过程中没有配置SMTP邮件服务,直接导致无法注册管理员账户。
具体步骤可见参考链接,这里贴出原文:(Required) Email settings:
-
Setup a Mailgun account (make sure to enter your CC details for the 10k/mo free email tier)
-
Go through the domain verification process and make sure the domain is listed as green and “active”
-
From the domains page click your domain and then copy/paste the “Default SMTP Login” into your config file as the
SMTP_LOGIN
value and the “Default Password” as theSMTP_PASSWORD
-
Change the
SMTP_FROM_ADDRESS
value to something like notifications@
-
- 保存,退出编辑器。
- 将密钥分别分配给PAPERCLIP_SECRET, SECRET_KEY_BASE 和 OTP_SECRET变量
- 收尾工作,运行Mastodon
- 再次生成镜像
docker-compose build
docker-compose build
- 迁移数据库
docker-compose run --rm web rails db:migrate
docker-compose run --rm web rails db:migrate
- 预编译assets
docker-compose run --rm web rails assets:precompile
docker-compose run --rm web rails assets:precompile
- 运行容器
docker-compose up -d
docker-compose up -d
- 再次生成镜像
- 进入mastodon用户主目录
- Nginx以及SSL证书的配置详见 上篇 和 通过certbot获取Let‘s Encrypt证书。
- 访问域名即可看到注册/登录页面,点击注册。验证邮箱后回到控制台,运行
# 回到Mastodon仓库目录cd /home/mastodon/mastodon# 将刚才注册的用户提升为管理员docker-compose run --rm web rails mastodon:make_admin USERNAME=[your username]
# 回到Mastodon仓库目录 cd /home/mastodon/mastodon # 将刚才注册的用户提升为管理员 docker-compose run --rm web rails mastodon:make_admin USERNAME=[your username]
- Mastodon Docker 部署完毕。
相关
3 thoughts on “Mastodon Docker 部署”
-
shitsumonn说道:
大佬,问一下这个 nginx 怎么配置
-
欧阳说道:
跟着你的步骤,服务已经启动了,但是访问不了网页
-
azhuge233说道:
确定配置并开启了nginx服务,用netstat -plnt 指令查看一下系统开启的端口
-
此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK