以记录踩坑为主的搭建笔记
参考教程
总体按照pullopen的 如何利用Docker搭建Mastodon实例(一):基础搭建篇,部分参考塔塔的 Mastodon | 小球飞象建站笔记
遇到的坑按教程顺序有以下几点:
- 
首次搭建成功后关闭服务器,再次打开的时候发现 ssh 密钥设置错误... 公钥需要把整个文本的所有内容都复制进去,缺一不可...我怎么也进不去服务器,最后只好炸站重装 
- 
Debian 系统的配置防火墙的指令不知道是什么,无法实现配置...最后换回了 Ubuntu 20.04 
- 
「安装docker和docker-compose」部分参考的塔塔教程,具体如下: - 
安装需要用到的软件包: 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
- 
之后检查一下是不是装好了: docker -v //检查Docker版本 Docker version 24.0.5, build ced0996 //返回内容 docker-compose --version //检查Docker-compose docker-compose version 1.27.4, build 40524192 //返 回内容
 
- 
- 
「拉取Mastodon镜像」部分使用git拉取: // 因为官方最新版是beta版,所以此部分我拉取我自己库的v4.1.6版本了 git clone https://github.com/brsu148/mastodon.git
要说学到了些什么的话...至少 Linux 系统的操作比之前熟练了好多
常用指令
- 
编辑 docker-compose 配置文件 cd /home/mastodon/mastodon nano docker-compose.yml
- 
docker 重启 docker-compose down docker-compose up -d
- 
docker image 镜像操作 // 镜像列表 docker images // 检索镜像, 从镜像仓库中检索 docker search xxx // 下载镜像 docker pull xxx // 删除镜像 docker rmi xxx // 重命名镜像 TAG docker tag IMAGEID(镜像id) REPOSITORY:TAG(仓库:标签)
- 
docker 容器操作 // 查看容器列表, 列出所有的容器 docker ps -a // 启动容器,start后面可以跟上容器名,或者容器id docker start xxx # (这里的xxx可以是容器名:yhh_centos 也可以是容器 id:f57398ab22c5) // 关闭容器 docker stop xxx // 重启 docker restart xxx // 删除 docker rm xxx
- 
本地媒体文件位置 public/system
- 
魔改操作方法 本地编辑后push到Github进行编译并推送到Dockerhub,若无错误则在服务器输入 cd /home/mastodon/mastodon docker pull brsu/mastodon:edge // edge为最新编码的tag,如果需要创建特定版本的tag,则将edge改成tag名 docker-compose down docker-compose up -d // 重启docker-compose
后续魔改
-  全文搜索
- 中文搜索优化
 
- tootctl 管理命令行脚本设置
- 如何备份
-  如何清理媒体文件
- 接入云存储
 
- 是否需要Cloudflare提高网站速度
-  是否可以将数据库git
- 使用了docker,所以没必要git
 
- 如何在本地编译预览
- 根据进阶魔改2依次修改
-  Markdown
- 折腾麻烦+升级麻烦,毛象都是短消息,也不太需要通过markdown来调整格式
 
- 中继站
- 头图(随缘)
- 吉祥物(随缘)
- 主题制作(学css)
开启全文搜索
根据pullopen的如何利用Docker搭建Mastodon实例(一):基础搭建篇配置 Docker 的 Mastodon 的全文搜索后,再通过Mastodon官方文档教程安装 Elasticsearch 再 大致步骤如下:
1. Docker 配置 Mastodon:
cd /home/mastodon/mastodon
nano docker-compose.yml // 编辑docker-compose.yml
编辑docker-compose.yml,去掉es部分前所有的#号,并且去掉web部分中es前面的#号,ctrl + x保存并退出
nano .env.production // 编辑.env.production
加上
ES_ENABLED=true
ES_HOST=es
ES_PORT=9200
重启 docker-compose
docker-compose down
docker-compose up -d
文件夹中出现elasticsearch文件夹后,赋权
chown 1000:1000 -R elasticsearch
再次重启
docker-compose down
docker-compose up -d
最后建立之前嘟文的搜索索引
docker-compose run --rm web bin/tootctl search deploy
2. 安装 Elasticsearch:
安装 Java,默认为root用户
apt install openjdk-8-jre-headless
添加Elasticsearch官方软件仓库至apt
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
apt update
安装 Elasticsearch
apt install elasticsearch
启动 Elasticsearch
systemctl enable elasticsearch
systemctl start elasticsearch
我是先配置 Mastodon 后发现全文搜索启动不了,然后再去安装 Elasticsearch,按照先2后1顺序真的不行...java会占用9200端口...
可以使用lsof -i:9200查看是什么东西占用了9200端口,再使用kill -9 PID输入对应的PID,杀掉对应进程后再重新建立索引docker-compose run --rm web bin/tootctl search deploy
中文搜索优化
如果在重新部署搜索的时候出现了以下类似报错:
/opt/mastodon/vendor/bundle/ruby/3.0.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/progress.rb:76:in total=': You can't set the item's total value to less than the current progress. (ProgressBar::InvalidProgressError)
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/base.rb:178:in block in update_progress'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/output.rb:43:in with_refresh'         from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/base.rb:177:in update_progress'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/base.rb:101:in total='         from /opt/mastodon/lib/mastodon/search_cli.rb:67:in deploy'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor/command.rb:27:in run'         from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in invoke_command'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor.rb:392:in dispatch'         from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:116:in invoke'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor.rb:243:in block in subcommand'         from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor/command.rb:27:in run'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in invoke_command'         from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor.rb:392:in dispatch'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/thor-1.2.2/lib/thor/base.rb:485:in start'         from bin/tootctl:9:in block in <main>'
from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/chewy-7.2.4/lib/chewy/strategy.rb:57:in wrap'         from /opt/mastodon/vendor/bundle/ruby/3.0.0/gems/chewy-7.2.4/lib/chewy.rb:154:in strategy'
from bin/tootctl:8:in `<main>'
可以参考Issue#18625,以及我的commit,本体修改后重新建立镜像文件,再在服务器上进行重新部署搜索操作
docker-compose run --rm web bin/tootctl search deploy
吉祥物
修改吉祥物宽度:app/javascript/styles/mastodon/components.scss
.drawer__inner__mastodon {
  ...
  > img {
    display: block;
    object-fit: contain;
    object-position: bottom left;
--  width: 85%;
++  width: 100%
    height: 100%;
    pointer-events: none;
    user-drag: none;
    user-select: none;
  }
删除吉祥物旁边的波浪:

app/javascript/styles/mastodon/components.scss
// Mastondon 暗色主题
.drawer__inner__mastodon {
--  background: lighten($ui-base-color, 13%) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 234.80078 31.757813" width="234.80078" height="31.757812"><path d="M19.599609 0c-1.05 0-2.10039.375-2.90039 1.125L0 16.925781v14.832031h234.80078V17.025391l-16.5-15.900391c-1.6-1.5-4.20078-1.5-5.80078 0l-13.80078 13.099609c-1.6 1.5-4.19883 1.5-5.79883 0L179.09961 1.125c-1.6-1.5-4.19883-1.5-5.79883 0L159.5 14.224609c-1.6 1.5-4.20078 1.5-5.80078 0L139.90039 1.125c-1.6-1.5-4.20078-1.5-5.80078 0l-13.79883 13.099609c-1.6 1.5-4.20078 1.5-5.80078 0L100.69922 1.125c-1.600001-1.5-4.198829-1.5-5.798829 0l-13.59961 13.099609c-1.6 1.5-4.200781 1.5-5.800781 0L61.699219 1.125c-1.6-1.5-4.198828-1.5-5.798828 0L42.099609 14.224609c-1.6 1.5-4.198828 1.5-5.798828 0L22.5 1.125C21.7.375 20.649609 0 19.599609 0z" fill="#{hex-color($ui-base-color)}"/></svg>') no-repeat bottom / 100% auto;
++  // background: lighten($ui-base-color, 13%) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 234.80078 31.757813" width="234.80078" height="31.757812"><path d="M19.599609 0c-1.05 0-2.10039.375-2.90039 1.125L0 16.925781v14.832031h234.80078V17.025391l-16.5-15.900391c-1.6-1.5-4.20078-1.5-5.80078 0l-13.80078 13.099609c-1.6 1.5-4.19883 1.5-5.79883 0L179.09961 1.125c-1.6-1.5-4.19883-1.5-5.79883 0L159.5 14.224609c-1.6 1.5-4.20078 1.5-5.80078 0L139.90039 1.125c-1.6-1.5-4.20078-1.5-5.80078 0l-13.79883 13.099609c-1.6 1.5-4.20078 1.5-5.80078 0L100.69922 1.125c-1.600001-1.5-4.198829-1.5-5.798829 0l-13.59961 13.099609c-1.6 1.5-4.200781 1.5-5.800781 0L61.699219 1.125c-1.6-1.5-4.198828-1.5-5.798828 0L42.099609 14.224609c-1.6 1.5-4.198828 1.5-5.798828 0L22.5 1.125C21.7.375 20.649609 0 19.599609 0z" fill="#{hex-color($ui-base-color)}"/></svg>') no-repeat bottom / 100% auto;
  flex: 1;
  min-height: 47px;
  display: none;
app/javascript/styles/mastodon-light/diff.scss
// Mastondon 亮色主题
.drawer__inner__mastodon {
--  background: $white url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 234.80078 31.757813" width="234.80078" height="31.757812"><path d="M19.599609 0c-1.05 0-2.10039.375-2.90039 1.125L0 16.925781v14.832031h234.80078V17.025391l-16.5-15.900391c-1.6-1.5-4.20078-1.5-5.80078 0l-13.80078 13.099609c-1.6 1.5-4.19883 1.5-5.79883 0L179.09961 1.125c-1.6-1.5-4.19883-1.5-5.79883 0L159.5 14.224609c-1.6 1.5-4.20078 1.5-5.80078 0L139.90039 1.125c-1.6-1.5-4.20078-1.5-5.80078 0l-13.79883 13.099609c-1.6 1.5-4.20078 1.5-5.80078 0L100.69922 1.125c-1.600001-1.5-4.198829-1.5-5.798829 0l-13.59961 13.099609c-1.6 1.5-4.200781 1.5-5.800781 0L61.699219 1.125c-1.6-1.5-4.198828-1.5-5.798828 0L42.099609 14.224609c-1.6 1.5-4.198828 1.5-5.798828 0L22.5 1.125C21.7.375 20.649609 0 19.599609 0z" fill="#{hex-color($ui-base-color)}"/></svg>') no-repeat bottom / 100% auto;
++  // background: $white url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 234.80078 31.757813" width="234.80078" height="31.757812"><path d="M19.599609 0c-1.05 0-2.10039.375-2.90039 1.125L0 16.925781v14.832031h234.80078V17.025391l-16.5-15.900391c-1.6-1.5-4.20078-1.5-5.80078 0l-13.80078 13.099609c-1.6 1.5-4.19883 1.5-5.79883 0L179.09961 1.125c-1.6-1.5-4.19883-1.5-5.79883 0L159.5 14.224609c-1.6 1.5-4.20078 1.5-5.80078 0L139.90039 1.125c-1.6-1.5-4.20078-1.5-5.80078 0l-13.79883 13.099609c-1.6 1.5-4.20078 1.5-5.80078 0L100.69922 1.125c-1.600001-1.5-4.198829-1.5-5.798829 0l-13.59961 13.099609c-1.6 1.5-4.200781 1.5-5.800781 0L61.699219 1.125c-1.6-1.5-4.198828-1.5-5.798828 0L42.099609 14.224609c-1.6 1.5-4.198828 1.5-5.798828 0L22.5 1.125C21.7.375 20.649609 0 19.599609 0z" fill="#{hex-color($ui-base-color)}"/></svg>') no-repeat bottom / 100% auto;
}
放上自己画的吉祥物,很喜欢


踩坑
1
不知道为什么build的时候疯狂报错,查了好几天也没找到问题所在...
x Run docker/build-push-action@v4
#36 exporting to image
#36 pushing manifest for docker.io/***/mastodon:edge@sha256:3099be7812d1cb845e80b143dff574c75ac6eefd4579e53536c4edab2458c6da 1.0s done
#36 pushing layers 0.5s done
#36 ERROR: failed to push ghcr.io/***148/mastodon:edge: unexpected status from POST request to https://ghcr.io/v2/***148/mastodon/blobs/uploads/: 403 Forbidden
#18 [linux/amd64 build 2/5] COPY --link --from=ruby /opt/ruby /opt/ruby
------
 > exporting to image:
------
ERROR: failed to solve: failed to push ghcr.io/***148/mastodon:edge: unexpected status from POST request to https://ghcr.io/v2/***148/mastodon/blobs/uploads/: 403 Forbidden
Error: buildx failed with: ERROR: failed to solve: failed to push ghcr.io/***148/mastodon:edge: unexpected status from POST request to https://ghcr.io/v2/***148/mastodon/blobs/uploads/: 403 Forbidden
解决办法:在/mastodon/.github/workflows/build-image.yml中把ghcr.io的部分删掉
// 删除以下部分
- name: Log in to the Github Container registry
  uses: docker/login-action@v2
  with:
    registry: ghcr.io
    username: ${{ github.actor }}
    password: ${{ secrets.GITHUB_TOKEN }}
  if: github.repository == 'Brsu148/mastodon' && github.event_name != 'pull_request'
// 以及 - uses: docker/metadata-action@v4 中的
- uses: docker/metadata-action@v4
  id: meta
  with:
    images: |
      brsu/mastodon 
      ghcr.io/brsu148/mastodon  // 删除这一行,其余保留
    flavor: |
      latest=auto
    tags: |
      type=edge,branch=main
      type=pep440,pattern={{raw}}
      type=pep440,pattern=v{{major}}.{{minor}}
      type=ref,event=pr
2
Github Actions 中有一个检查 Ruby 代码的 workflows 经常报错,怎么改都报错。问了GPT,GPT说是误报,我又去看了看别人的毛象文件是什么配置的,结果发现别人压根就没有lint-ruby.yml这个文件...于是我把这个文件删掉后重新上传,之后就不再报错了
3
服务器上的文件是会和我本地提交上去的不是同步一致,是因为Docker的镜像原因吗?
解答: docker 运行的是镜像文件,比方说我在本地 vscode 上编辑的内容是食材,通过 Github Desktop push上去后由 Github Action 进行烹饪,做好的菜再传到 Docker Hub。而我服务器则从 Docker Hub 上把菜拿下来,因为我docker-compose.yml设置的是edge,也就是默认启动最新的 tag,所以重启后就会自行使用最新的菜。菜被放在盘子当中(也就是被放在容器)来给用户上菜
而我在服务器上进行修改的食材,并未进行烹饪和上菜,所以修改后的结果不会显示出来()
- docker-compose.yml:「是一个用于定义和运行多个 Docker 容器的工具,它允许您通过一个配置文件来定义和管理多个容器的关系和设置。」也就是说 不会受到镜像文件和容器影响,反倒是用来管理容器的配置文件