Mastodon/Setup: Difference between revisions

From neuromatch
(add SMTP configuration)
 
(→‎Discord: new section)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Up to [[Part Of::Mastodon]]
In this case we are using [[Documents::glitch-soc]] to run a [[Implements::Mastodon]] server.
* '''Neuromatch Fork:''' [[Has Git Repository::https://github.com/NeuromatchAcademy/mastodon]]
We will make:
* One "default" instance at neuromatch.social
* One [[Mastodon/Dev Instance|Dev Instance]] at dev.neuromatch.social
We will be following the official Mastodon setup docs (except cloning [https://github.com/NeuromatchAcademy/mastodon our fork] of [[glitch-soc]] instead of the base masto repo):
* [https://docs.joinmastodon.org/admin/prerequisites/ Prereqs]
* [https://docs.joinmastodon.org/admin/install/ Installing from Source]
* [https://docs.joinmastodon.org/admin/config/ Configuring Environment]
* [https://docs.joinmastodon.org/admin/setup/ Setup]
== Prereqs ==
https://docs.joinmastodon.org/admin/prerequisites/
See also: [[Linode/Setup]]
<markdown>
- [x] Turn off password SSH access
- [x] Install fail2ban
- [x] Configure iptables to only allow SSH and HTTP/HTTPS
</markdown>
=== DNS ===
Set up the domain name!
<markdown>
- [x] Add an `A` record pointing at the linode's IP Address
- [ ] Set up rDNS pointing back at the domain
</markdown>
== Installation ==
https://docs.joinmastodon.org/admin/install/
<markdown>
- [x] Add apt repositories
- [x] Install apt packages
- [x] Make `mastodon` user
- [x] Install Ruby
- [x] Configure postgresql
- [ ] Configure nginx (config below)
- [x] Get SSL Cert
- [x] Install & Enable systemd services
</markdown>
Once DNS is set up, you can run the following as root:<syntaxhighlight lang="shell">
certbot certonly --standalone
</syntaxhighlight>to get SSL certs. Then restart nginx to load them.
=== Services ===
* mastodon-web
* mastodon-sidekiq
* mastodon-streaming
== Configuration ==
=== nginx ===


=== Configure the email server ===
=== Configure the email server ===
Create a SendGrid account, go to Settings > API Keys, and generate an API key.
Create a SendGrid account, go to Settings > API Keys, and generate an API key.


Then set up the config like this:
Then set up the config in mastodon/live/.env.production like this:
  <code>SMTP_SERVER=smtp.sendgrid.net
  <code>SMTP_SERVER=smtp.sendgrid.net
  SMTP_PORT=587
  SMTP_PORT=587
  SMTP_LOGIN=apikey
  SMTP_LOGIN=apikey
  SMTP_PASSWORD=<your-api-key>
  SMTP_PASSWORD=<your-api-key>
  SMTP_FROM_ADDRESS=youremail@gmail.com</code>
  SMTP_FROM_ADDRESS=noreply@neuromatch.social</code>
(for SMTP_LOGIN literally just use "apikey")
(for SMTP_LOGIN literally just use "apikey")
=== Restart services ===
Restart all 3 services after each change to .evn.production or config/settings.yml and you need to have root access for this to work<syntaxhighlight lang="bash">
sudo su
cd /etc/systemd/system
for service in mastodon-{web,sidekiq,streaming}; do service $service restart; done
for service in mastodon-{web,sidekiq,streaming}; do service $service status; done
</syntaxhighlight>
== Setting up an admin account from CLI w/ email confirmation ==
Note that you need to be logged in as the mastodon user for this to work.
<OPTIONAL> If you did not create that user account and don't know the password, then you should do the following:
sudo su - mastodon
The following command will work if the username and email have been registered from the UI. Very useful if SMTP server hasn't been setup yet.
cd /home/mastodon/live
RAILS_ENV=production ./bin/tootctl accounts modify <username> --role Admin --email <email-address> --confirm
* [[Category:Guide]]
* [[Category:Mastodon]]
== Discord ==
{{Message
|Author=mannazsci
|Avatar=https://cdn.discordapp.com/avatars/540104559079456770/12ce492294d6a3cd6f1ea00cbe8edb04.png?size=1024
|Date Sent=23-08-16 04:11:30
|Channel=technical-wg
|Text=[[Mastodon/Setup]] useful commands to improve disk usage:
`# Prune remote accounts that never interacted with a local user
RAILS_ENV=production /home/mastodon/live/bin/tootctl accounts prune;
# Remove remote statuses that local users never interacted with older than 4 days
RAILS_ENV=production /home/mastodon/live/bin/tootctl statuses remove --days 4;
# Remove media attachments older than 4 days
RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --days 4;
# Remove all headers (including people I follow)
RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --remove-headers --include-follows --days 0;
# Remove link previews older than 4 days
RAILS_ENV=production /home/mastodon/live/bin/tootctl preview_cards remove --days 4;
# Remove files not linked to any post
RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove-orphans;`
|Link=https://discord.com/channels/1049136631065628772/1049184335514828860/1141222683388956812
}}

Latest revision as of 00:11, 16 August 2023

Up to Mastodon

In this case we are using glitch-soc to run a Mastodon server.

We will make:

  • One "default" instance at neuromatch.social
  • One Dev Instance at dev.neuromatch.social

We will be following the official Mastodon setup docs (except cloning our fork of glitch-soc instead of the base masto repo):

Prereqs

https://docs.joinmastodon.org/admin/prerequisites/

See also: Linode/Setup

  • Turn off password SSH access
  • Install fail2ban
  • Configure iptables to only allow SSH and HTTP/HTTPS

DNS

Set up the domain name!

  • Add an A record pointing at the linode's IP Address
  • Set up rDNS pointing back at the domain

Installation

https://docs.joinmastodon.org/admin/install/

  • Add apt repositories
  • Install apt packages
  • Make mastodon user
  • Install Ruby
  • Configure postgresql
  • Configure nginx (config below)
  • Get SSL Cert
  • Install & Enable systemd services


Once DNS is set up, you can run the following as root:

certbot certonly --standalone

to get SSL certs. Then restart nginx to load them.

Services

  • mastodon-web
  • mastodon-sidekiq
  • mastodon-streaming

Configuration

nginx

Configure the email server

Create a SendGrid account, go to Settings > API Keys, and generate an API key.

Then set up the config in mastodon/live/.env.production like this:

SMTP_SERVER=smtp.sendgrid.net
SMTP_PORT=587
SMTP_LOGIN=apikey
SMTP_PASSWORD=<your-api-key>
SMTP_FROM_ADDRESS=noreply@neuromatch.social

(for SMTP_LOGIN literally just use "apikey")

Restart services

Restart all 3 services after each change to .evn.production or config/settings.yml and you need to have root access for this to work

sudo su
cd /etc/systemd/system
for service in mastodon-{web,sidekiq,streaming}; do service $service restart; done
for service in mastodon-{web,sidekiq,streaming}; do service $service status; done

Setting up an admin account from CLI w/ email confirmation

Note that you need to be logged in as the mastodon user for this to work.

<OPTIONAL> If you did not create that user account and don't know the password, then you should do the following:

sudo su - mastodon

The following command will work if the username and email have been registered from the UI. Very useful if SMTP server hasn't been setup yet.

cd /home/mastodon/live
RAILS_ENV=production ./bin/tootctl accounts modify <username> --role Admin --email <email-address> --confirm

Discord

mannazsci#technical-wg23-08-16 04:11:30

Mastodon/Setup useful commands to improve disk usage:

`# Prune remote accounts that never interacted with a local user RAILS_ENV=production /home/mastodon/live/bin/tootctl accounts prune;

  1. Remove remote statuses that local users never interacted with older than 4 days

RAILS_ENV=production /home/mastodon/live/bin/tootctl statuses remove --days 4;

  1. Remove media attachments older than 4 days

RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --days 4;

  1. Remove all headers (including people I follow)

RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove --remove-headers --include-follows --days 0;

  1. Remove link previews older than 4 days

RAILS_ENV=production /home/mastodon/live/bin/tootctl preview_cards remove --days 4;

  1. Remove files not linked to any post

RAILS_ENV=production /home/mastodon/live/bin/tootctl media remove-orphans;`