Mastodon 是一个基于 ActivityPub 的免费开源社交网络服务器,用户可以在其中关注朋友并发现新朋友。在 Mastodon 上,用户可以发布他们想要的任何内容:链接、图片、文本、视频。所有 Mastodon 服务器都可以作为联合网络进行互操作(一台服务器上的用户可以与另一台服务器上的用户无缝通信,包括实现 ActivityPub 的非`Mastodon 软件)!
mastodon的github地址在这里。

也许一段视频以后,你会更懂得,他是什么东西。
【社交网络】什么是Mastodon?(中文字幕)
您将以 root 身份运行这些命令。如果您还不是 root,请切换到 root:
确保首先安装 curl、wget、gnupg、apt-transport-https、lsb-release 和 ca-certificates:
apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates
curl -sL https://deb.nodesource.com/setup_16.x | bash -
wget -O /usr/share/keyrings/postgresql.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb [signed-by=/usr/share/keyrings/postgresql.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/postgresql.list
为了获得最佳性能,您可以使用pgTune生成适当的配置并/etc/postgresql/14/main/postgresql.conf在重新启动 PostgreSQL 之前编辑值
systemctl restart postgresql
您需要创建一个 Mastodon 可以使用的 PostgreSQL 用户。在简单的设置中使用“ident”身份验证是最容易的,即 PostgreSQL 用户没有单独的密码,并且可以由具有相同用户名的 Linux 用户使用。
打开提示:
sudo -u postgres psql
在提示符下,执行:
CREATE USER mastodon CREATEDB;
完毕!
apt update
apt install -y \
imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \
g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf \
bison build-essential libssl-dev libyaml-dev libreadline6-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \
nginx redis-server redis-tools postgresql postgresql-contrib \
certbot python3-certbot-nginx libidn11-dev libicu-dev libjemalloc-dev
corepack enable
yarn set version stable
我们将使用 rbenv 来管理 Ruby 版本,因为更容易获得正确的版本并在新版本发布后进行更新。rbenv 必须为单个 Linux 用户安装,因此,首先我们必须创建用户 Mastodon 将运行为:
adduser --disabled-login mastodon
然后我们可以切换到用户:
su - mastodon
并继续安装 rbenv 和 rbenv-build:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec bash
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
完成后,我们可以安装正确的 Ruby 版本:
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.0.3
rbenv global 3.0.3
我们还需要安装捆绑器:
gem install bundler --no-document
返回root用户:
exit
是时候下载 Mastodon 代码了。切换到乳齿象用户:
su - mastodon
检查代码
使用 git 下载 Mastodon 的最新稳定版本:
git clone https://github.com/tootsuite/mastodon.git live && cd live
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
安装最后的依赖项
现在安装 Ruby 和 JavaScript 依赖项:
bundle config deployment 'true'
bundle config without 'development test'
bundle install -j$(getconf _NPROCESSORS_ONLN)
yarn install --pure-lockfile
bundle config仅在您第一次安装依赖项时才需要这两个命令。如果您稍后要更新或重新安装依赖项,就bundle install足够了。
运行交互式设置向导:
RAILS_ENV=production bundle exec rake mastodon:setup
这将:
配置文件保存为.env.production. 您可以根据自己的喜好查看和编辑它。请参阅有关配置的文档。
你现在已经完成了 mastodon 用户,所以切换回 root:
exit
#####设置 nginx
从 Mastodon 目录复制 nginx 的配置模板:
cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
然后编辑/etc/nginx/sites-available/mastodon以替换example.com为您自己的域名,并进行您可能需要的任何其他调整。
重新加载 nginx 以使更改生效:
#####获取 SSL 证书
我们将使用 Let’s Encrypt 获得免费的 SSL 证书:
certbot --nginx -d example.com
这将获取证书,自动更新/etc/nginx/sites-available/mastodon以使用新证书,并重新加载 nginx 以使更改生效。
此时您应该能够在浏览器中访问您的域,并看到大象撞到计算机屏幕错误页面。这是因为我们还没有开始 Mastodon 进程。
从 Mastodon 目录复制 systemd 服务模板:
cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
如果您在任何时候偏离默认值,请检查用户名和路径是否正确:
$EDITOR /etc/systemd/system/mastodon-*.service
最后,启动并启用新的 systemd 服务:
systemctl daemon-reload
systemctl enable --now mastodon-web mastodon-sidekiq mastodon-streaming
它们现在将在启动时自动启动。
欢呼!就是这个。您现在可以在浏览器中访问您的域!