8

Mastodon Docker 部署

 3 years ago
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 Docker 部署
This website uses cookies to improve your experience. 本站使用 Cookies 以提升您的用户体验。 Learn More
Skip to content

接上篇 去中心化社交平台Mastodon(v2.7.3)的部署

  • SMTP邮件服务(重要,安装完毕后需要发送邮件来注册管理员账户)
  • Ubuntu 18.04
  • Nginx
  • Docker CE 以及 Docker-compose
  1. 安装Nginx、Docker CE 以及 Docker-compose
    1. Nginx
      apt install nginx
      apt install nginx
    2. Docker 安装详见 多平台安装Docker 这里直接给出指令
      wget -qO- https://get.docker.com/ | sh
      wget -qO- https://get.docker.com/ | sh
    3. 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-compose
      chmod +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版本。

  2. 分配交换空间(已有可跳过)
    1. 详见 Increase Ubuntu Swap partition,这里直接给出指令
      fallocate -l 1G /swap
      chmod 600 /swap
      mkswap /swap
      swapon /swap
      # check
      free -m
      fallocate -l 1G /swap
      chmod 600 /swap
      mkswap /swap
      swapon /swap
      # check
      free -m
  3. 新建用户并赋予root权限
    adduser mastodon
    usermod -aG sudo mastodon
    # 切换到mastodon用户
    su - mastodon
    adduser mastodon
    usermod -aG sudo mastodon
    # 切换到mastodon用户
    su - mastodon
  4. 安装Mastodon
    1. 进入mastodon用户主目录
      cd /home/mastodon
      cd /home/mastodon
    2. 克隆仓库
      git clone https://github.com/tootsuite/mastodon.git
      # 进入目录
      cd mastodon
      git clone https://github.com/tootsuite/mastodon.git
      # 进入目录
      cd mastodon
    3. 复制生产环境配置文件
      cp .env.production.sample .env.production
      cp .env.production.sample .env.production
    4. 构建Docker镜像
      docker-compose build
      docker-compose build

      这一步耗时很长,中间报错可以不理会,最后提示成功构建即可。

    5. 生成密钥
      docker-compose run --rm web rake secret
      docker-compose run --rm web rake secret

      运行上述指令三次,记录每次输出的密钥。

    6. 编辑生产环境配置文件
      1. 将密钥分别分配给PAPERCLIP_SECRET, SECRET_KEY_BASE 和 OTP_SECRET变量
        PAPERCLIP_SECRET=密钥1
        SECRET_KEY_BASE=密钥2
        OTP_SECRET=密钥3
        PAPERCLIP_SECRET=密钥1
        SECRET_KEY_BASE=密钥2
        OTP_SECRET=密钥3

        顺序不必固定,保证三个变量密钥不同即可。

        配置文件中可能没有 PAPERCLIP_SECRET 这个变量,需要手动输入(不添加PAPERCLIP_SECRET变量的后果不确定)。

      2. 更改文件中的LOCAL_DOMAIN变量,将其值改为自己的域名
        LOCAL_DOMAIN=[your domain]
        LOCAL_DOMAIN=[your domain]
      3. 设置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 the SMTP_PASSWORD

        • Change the SMTP_FROM_ADDRESS value to something like notifications@

      4. 保存,退出编辑器。
    7. 收尾工作,运行Mastodon
      1. 再次生成镜像
        docker-compose build
        docker-compose build
      2. 迁移数据库
        docker-compose run --rm web rails db:migrate
        docker-compose run --rm web rails db:migrate
      3. 预编译assets
        docker-compose run --rm web rails assets:precompile
        docker-compose run --rm web rails assets:precompile
      4. 运行容器
        docker-compose up -d
        docker-compose up -d
  5. Nginx以及SSL证书的配置详见 上篇 和 通过certbot获取Let‘s Encrypt证书
  6. 访问域名即可看到注册/登录页面,点击注册。验证邮箱后回到控制台,运行
    # 回到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]
  7. Mastodon Docker 部署完毕。

相关

所有, 网站mastodon

3 thoughts on “Mastodon Docker 部署”

  1. shitsumonn说道:

    大佬,问一下这个 nginx 怎么配置

  2. 欧阳说道:

    跟着你的步骤,服务已经启动了,但是访问不了网页

    1. azhuge233说道:

      确定配置并开启了nginx服务,用netstat -plnt 指令查看一下系统开启的端口

发表评论 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论

显示名称 *

电子邮箱地址 *

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK