原文地址:https://lala.im/7634.html,請支持原作者!該處僅作轉載。
最近打算记录自己一些零碎的信息,所以想来想去还是去弄个mastodon好了,反正正好有一台吃灰机器有2G内存,刚刚好。
说快速其实也不快速,只是我把坑都基本踩完了。。当然比起手动部署的话还是要快一点的,我之前也写过手动部署的方法。
官方其实不推荐用Docker,我也不知道为啥。。所以也没啥比较好的文档。
下面的步骤取自我目前的生产环境,有需要的可以参考参考。。
安装需要用到的软件包:
apt -y update
apt -y install curl git nginx python-certbot-nginx
安装docker:
curl -sSL https://get.docker.com/ | sh
systemctl enable --now nginx docker
安装docker-compose:
curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
拉取项目文件:
cd /opt
git clone https://github.com/tootsuite/mastodon.git
cd mastodon/
复制一份配置文件:
cp .env.production.sample .env.production
把项目内自带的docker-compose.yml重命名或者删了都可以,你直接用这个配置是肯定跑不起来的,有很多问题,这里就不细说了。
mv docker-compose.yml docker-compose.yml.bak
新建一个docker-compose.yml:
nano docker-compose.yml
这里我把自己目前在用的配置放上来:
version: '3.5'
services:
mastodon-db:
image: postgres:9.6-alpine
shm_size: 256mb
environment:
POSTGRES_DB: mastodon
POSTGRES_USER: imlala
POSTGRES_PASSWORD: password
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
volumes:
- ./postgres:/var/lib/postgresql/data
restart: unless-stopped
mastodon-redis:
image: redis:6.0-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
volumes:
- ./redis:/data
restart: unless-stopped
mastodon-web:
image: tootsuite/mastodon
env_file: .env.production
command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"
depends_on:
- mastodon-db
- mastodon-redis
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:3000/health || exit 1"]
ports:
- "127.0.0.1:3000:3000"
volumes:
- ./public/system:/mastodon/public/system
restart: unless-stopped
mastodon-streaming:
image: tootsuite/mastodon
env_file: .env.production
command: node ./streaming
depends_on:
- mastodon-db
- mastodon-redis
healthcheck:
test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:4000/api/v1/streaming/health || exit 1"]
ports:
- "127.0.0.1:4000:4000"
restart: unless-stopped
mastodon-sidekiq:
image: tootsuite/mastodon
env_file: .env.production
command: bundle exec sidekiq
depends_on:
- mastodon-db
- mastodon-redis
volumes:
- ./public/system:/mastodon/public/system
restart: unless-stopped
接下来运行这个命令,进入配置向导:
docker-compose run --rm mastodon-web bundle exec rake mastodon:setup
按照下面的来即可:
Domain name: # 填写你的域名
Do you want to enable single user mode? # Yes
Are you using Docker to run Mastodon? # Yes
PostgreSQL host: # mastodon-db
PostgreSQL port: # 5432
Name of PostgreSQL database: # mastodon
Name of PostgreSQL user: # imlala
Password of PostgreSQL user: # 填你在compose内设置的密码
Redis host: # mastodon-redis
Redis port: # 6379
Redis password: # 留空,直接回车
Do you want to store uploaded files on the cloud? # No
Do you want to send e-mails from localhost? # Yes
Send a test e-mail with this configuration right now? # No
Save configuration? Yes
注:这个配置的是单用户模式,也就是默认不开放注册。其次没有配置SMTP,因为我就一个人用,所以就偷懒啦。
接下来它会把你填写的这些配置打印出来,现在你需要把你之前填的这些配置复制下来。
注意到了一个非常坑的地方,接下来你会看到下面这个提示:
Prepare the database now? (Y/n)
不要选择Y或者N,直接按键盘组合键Ctrl+C退出来。然后清空如下配置文件内的默认配置:
echo > .env.production
编辑它:
nano .env.production
把你之前通过向导复制的配置粘贴到里面保存。之后重新运行一次向导:
docker-compose run --rm mastodon-web bundle exec rake mastodon:setup
这次的配置和之前务必保持一致。再次来到下面这个位置的时候,就可以Yes了:
Prepare the database now? (Y/n) # Yes
Compile the assets now? (Y/n) # Yes
接下来的步骤就是创建管理员账户了,继续跟着这个向导走就OK了。
全部完成之后,up起来其他的服务:
docker-compose up -d
现在你还需要把public的目录所有者改为容器内的,不然后续不能上传头像:
chown -R 991:991 public
现在来复制一份nginx的站点配置文件:
cp /opt/mastodon/dist/nginx.conf /etc/nginx/conf.d/mastodon.conf
编辑mastodon.conf:
nano /etc/nginx/conf.d/mastodon.conf
在这个配置文件内,官方都写好了模板,你只需要改动两个server块下面的位置:
server {
listen 80;
listen [::]:80;
server_name imlala.best; # 换成你的域名
root /opt/mastodon/public; # public目录的绝对路径
...
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name imlala.best; # 换成你的域名
root /opt/mastodon/public; # public目录的绝对路径
...
}
使用certbot签发SSL证书:
certbot --nginx
OK,到这里就大功告成了。
后续如果你要搬家,直接打包/opt/mastodon这个目录就好了,传到别的机器内解压后直接up起来就可以了。
要改动.env.production内的配置也是一样,改完之后up一次就可以。
更新的话参考官方的release发布页面,我这才装的最新版也没得更,不知道会不会有啥坑。