Mastodon是一个开源、去中心化的社交平台,属于Fediverse网络的一部分。与传统社交平台依赖单一服务器不同,Mastodon允许任何人托管自己的实例,同时仍可以与其他实例上的用户互动。你可以完全掌控自己的数据和社区规则。RackNerd提供高性能、稳定的VPS方案,适合托管Mastodon实例。下文主要介绍RackNerd VPS部署Mastodon详细过程。
一、购买RackNerd VPS
在开始之前,请先购买符合以下条件的RackNerd VPS:
- 4GB内存(建议8GB)
- 2个vCPU
- 40–60GB磁盘空间
购买RackNerd VPS优惠方案
| 方案 | CPU | 内存 | SSD存储 | 月流量 | 端口 | 价格 | 购买链接 |
| 1GB KVM VPS | 1核 | 1GB | 20GB SSD | 3TB | 1Gbps | $21.99/年 | 点击购买 |
| 2GB KVM VPS | 2核 | 2GB | 35GB SSD | 5TB | 1Gbps | $35.99/年 | 点击购买 |
| 4GB KVM VPS | 3核 | 4GB | 60GB SSD | 7TB | 1Gbps | $59.99/年 | 点击购买 |
| 6GB KVM VPS | 6核 | 6GB | 100GB SSD | 12TB | 1Gbps | $89.99/年 | 点击购买 |
| 8GB KVM VPS | 7核 | 8GB | 150GB SSD | 20TB | 1Gbps | $119.99/年 | 点击购买 |
评测参考:
- RackNerd美国纽约KVM VPS速度性能综合测评
- RackNerd美国VPS洛杉矶DC03机房性能和速度综合评测
- RackNerd洛杉矶DC-02机房速度和性能测评
- RackNerd美国KVM VPS达拉斯机房速度和性能综合评测
域名:一个可访问的域名,用于你的Mastodon实例
若还没有域名,推荐访问Gname官网注册,新客立享5张.com域名注册券,无需领取注册自动方法。
二、RackNerd VPS部署Mastodon步骤 1、更新服务器首先更新你的服务器系统及软件包:
sudo apt update && sudo apt upgrade -y
安装必要依赖:
2、安装PostgreSQLsudo apt install git curl nano gnupg apt-transport-https build-essential -y
PostgreSQL是Mastodon的数据库后端。
sudo apt install postgresql postgresql-contrib -y
创建数据库和用户:
sudo -u postgres psql
在PostgreSQL Shell内执行:
3、安装RedisCREATE USER mastodon WITH PASSWORD ‘yourpassword’; CREATE DATABASE mastodon_production OWNER mastodon;
\q
Redis用于缓存和后台任务队列。
4、安装Node.js和Yarnsudo apt install redis-server -y
sudo systemctl enable redis-server
sudo systemctl start redis-server
Mastodon前端依赖Node.js。
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash –
sudo apt install -y nodejs
安装Yarn:
5、安装Ruby(通过rbenv或RVM)corepack enable
corepack prepare yarn@stable –activate
示例使用rbenv:
6、安装Mastodongit clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc source ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
gitclonehttps://github.com/rbenv/ruby-build.git~/.rbenv/plugins/ruby-buildrbenv install 3.2.2
rbenv global 3.2.2
克隆Mastodon源码:
git clone https://github.com/mastodon/mastodon.git
cd mastodon
git checkout $(git tag | sort -V | tail -1)
安装Ruby gems:
bundle install
安装JavaScript依赖:
7、配置MastodonInstall JavaScript dependencies:
yarn install –production
创建环境配置文件:
cp .env.production.sample .env.production
vi .env.production
编辑关键配置项:
- LOCAL_DOMAIN:你的域名
- PostgreSQL用户名和密码
- Redis URL
- 邮件发送设置
- 媒体存储路径
然后运行数据库迁移和前端资源编译:
8、配置Nginx与SSLRAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails assets:precompile
安装Nginx:
sudo apt install nginx -y
创建Mastodon Nginx配置文件:
sudovi/etc/nginx/sites-available/mastodon
启用并重启Nginx:
sudo ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/
sudo systemctl restart nginx
启用HTTPS(Certbot自动获取证书):
9、设置Mastodon服务sudo apt install certbot python3-certbot-nginx -y
sudo certbot –nginx -d yourdomain.com
创建systemd服务文件:
mastodon-web
mastodon-streaming
mastodon-sidekiq
启用并启动服务:
10、访问你的Mastodon实例sudo systemctl enable –now mastodon-web mastodon-sidekiq mastodon-streaming
sudo systemctl status mastodon-web
完成后,打开浏览器访问:
https://yourdomain.com
注册管理员账号,即可开始管理和配置你的Mastodon社区。
相关推荐:
《RackNerd国外VPS安装和配置GitLab完整教程》
《RackNerd cPanel主机AI网站生成器快速搭建教程》
《RackNerd国外Ubuntu VPS通过WordOps安装WordPress教程》
(本文由美国主机侦探原创,转载请注明出处“美国主机侦探”和原文地址!)
微信扫码加好友进群
主机优惠码及时掌握
QQ群号:164393063
主机优惠发布与交流





