Installation von Mastodon auf Debian (Stretch) mit Apache
Was ist Mastodon??? Mastodon ist ein freies und dezentrales soziales Netzwerk, als Alternative zu Twitter. Es basiert auf offenen Web-Protokollen und freier, quelloffener Software. Mit diesem Leitfaden kann man eine Mastodon Instanz auf Debian 9 (Stretch) mit Apache-Proxy einrichten.
Hinweis: Ich verwende social.test.local als Domain-Namen, der für die Mastodon-Instanz verwendet wird. Ersetzen Sie alle Vorkommen von social.test.local durch Ihren tatsächlichen Domain-Namen, den Sie für Ihre Mastodon-Anwendung verwenden möchten.
Installation Abhängigkeiten
Mastodon benötigt mehrere Abhängigkeiten um zu funktionieren. Mit den nachfolgenden Befehlen werden die benötigten Pakete installiert bzw. aktualisiert.
test@social:~$ sudo apt -y install curl
test@social:~$ curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
test@social:~$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
test@social:~$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
test@social:~$ sudo apt update
test@social:~$ sudo apt -y install nodejs yarn imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git curl g++ libprotobuf-dev protobuf-compiler pkg-config build-essential libreadline-dev libicu-dev libidn11-dev libssl-dev libjemalloc-dev tmux postgresql postgresql-client libpq-dev postgresql-contrib redis-server dirmngr gawk autoconf automake bison libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool libyaml-dev sqlite3 libgmp-dev
Mastodon Benutzer anlegen
Im nächsten Schritt wird der Benutzer angelegt, unter dem die Mastodon.Instanz später laufen wird.
test@social:~$ sudo adduser --gecos "Mastodon" --home /home/mastodon mastodon
test@social:~$ sudo usermod -aG www-data mastodon
Konfiguration Datenbank
Nachdem der Systembenutzer angelegt wurde, wird nun der Benutzer für den Datenbankzugriff angelegt und ein Kennwort für den Benutzer vergeben.
test@social:~$ sudo -u postgres createuser mastodon -d -P -R
Installation RVM
Nun wechseln Sie zum User „mastodon“ und installieren RVM (Ruby Version Manager) in der Version 2.5.1 wie folgt:
test@social:~$ sudo su - mastodon
mastodon@social:~$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
mastodon@social:~$ curl -sSL https://get.rvm.io | bash -s stable
mastodon@social:~$ source /home/mastodon/.rvm/scripts/rvm
mastodon@social:~$ rvm install 2.5.1
mastodon@social:~$ rvm use 2.5.1
Mastodon clonen
Der Sourcecode von Mastodon lauf GitHub, darum klonen Sie nun den Quellcode als User mastodon in das „/home/mastondon/live/“ Verzeichnis wie folgt:
mastodon@social:~$ cd ~
mastodon@social:~$ git clone https://github.com/tootsuite/mastodon.git live
mastodon@social:~$ cd live
mastodon@social:~/live$ git checkout v2.4.3
Installation Mastodon
Nachdem alle Vorbereitungen für die Mastodon-Installation abgeschlossen sind, kann mastodon wie folgt installiert werden:
mastodon@social:~/live$ gem install bundler
mastodon@social:~/live$ bundle install --deployment --without development test
mastodon@social:~/live$ yarn install
Konfiguration Mastodon
Abschließend muss die Instanz noch initial konfiguriert werden. Dabei werden Fragen zu den Datenbankeinstellungen, Mailversand und Standardwerte abgefragt. Diese, falls nötig, anpassen bzw. bestätigen. Das Setup wird wie folgt gestartet:
mastodon@social:~/live$ RAILS_ENV=production bundle exec rake mastodon:setup
mastodon@social:~/live$ exit
Konfiguration Systemdienste
Damit die Mastodon-Instanz auch gestartet und gestoppt werden kann müssen nun die erforderlichen System-Dienste eingerichtet werden.
Neue Konfiguration für den „mastodon-web.service“ anlegen:
test@social:~$ sudo vim.tiny /etc/systemd/system/mastodon-web.service
und mit folgenden Inhalt befüllen, danach speichern:
[Unit]
Description=mastodon-web
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="PORT=3000"
ExecStart=/home/mastodon/.rvm/gems/ruby-2.5.1/wrappers/bundle exec puma -C config/puma.rb
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
Neue Konfiguration für den „mastodon-sidekiq.service“ anlegen:
test@social:~$ sudo vim.tiny /etc/systemd/system/mastodon-sidekiq.service
und mit folgenden Inhalt befüllen, danach speichern:
[Unit]
Description=mastodon-sidekiq
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=5"
ExecStart=/home/mastodon/.rvm/gems/ruby-2.5.1/wrappers/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
Neue Konfiguration für den „mastodon-streaming.service“ anlegen:
test@social:~$ sudo vim.tiny /etc/systemd/system/mastodon-streaming.service
und mit folgenden Inhalt befüllen, danach speichern:
[Unit]
Description=mastodon-streaming
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/home/mastodon/live
Environment="NODE_ENV=production"
Environment="PORT=4000"
ExecStart=/usr/bin/npm run start
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
Die neu angelegten System-Dienste wie folgt aktivieren:
test@social:~$ sudo ln -s /etc/systemd/system/mastodon-web.service /etc/systemd/system/multi-user.target.wants/mastodon-web.service
test@social:~$ sudo ln -s /etc/systemd/system/mastodon-sidekiq.service /etc/systemd/system/multi-user.target.wants/mastodon-sidekiq.service
test@social:~$ sudo ln -s /etc/systemd/system/mastodon-streaming.service /etc/systemd/system/multi-user.target.wants/mastodon-streaming.service
Installation Apache
Für diese Art der Mastodon-Installation wird der Apache-Webserver als Proxy genutzt und muss wie folgt installiert werden:
test@social:~$ sudo apt -y install apache2
test@social:~$ sudo a2enmod ssl proxy proxy_wstunnel proxy_http headers
test@social:~$ sudo service apache2 restart
Konfiguration Apache
Im letzten Schritt wird eine neue vHost Konfiguration für die Mastodon-Instanz angelegt und wie folgt eingerichtet:
Neue vhost Konfiguartion erstellen:
test@social:~$ sudo vim.tiny /etc/apache2/sites-available/social.test.local.conf
und nachfolgenden Inhalt einfügen:
ServerAdmin contact@test.local
ServerName social.test.local
Redirect Permanent / https://social.test.local/
ServerAdmin contact@test.local
ServerName social.test.local
DocumentRoot /home/mastodon/live/public/
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Strict-Transport-Security "max-age=31536000"
SSLEngine on
SSLProtocol -all +TLSv1.2
SSLHonorCipherOrder on
SSLCipherSuite EECDH+AESGCM:AES256+EECDH:AES128+EECDH
SSLCompression off
SSLSessionTickets off
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLUseStapling off
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
Header always set Cache-Control "public, max-age=31536000, immutable"
Require all granted
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
ProxyPass /500.html !
ProxyPass /sw.js !
ProxyPass /robots.txt !
ProxyPass /manifest.json !
ProxyPass /browserconfig.xml !
ProxyPass /mask-icon.svg !
ProxyPassMatch ^(/.*\.(png|ico)$) !
ProxyPassMatch ^/(assets|avatars|emoji|headers|packs|sounds|system|.well-known/acme-challenge) !
ProxyPass /api/v1/streaming/ ws://localhost:4000/
ProxyPassReverse /api/v1/streaming/ ws://localhost:4000/
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ErrorDocument 500 /500.html
ErrorDocument 501 /500.html
ErrorDocument 502 /500.html
ErrorDocument 503 /500.html
ErrorDocument 504 /500.html
Zum Abschluss die Konfoguration speichern, aktivieren und den Webserver neu starten:
test@social:~$ sudo a2ensite social.test.local.conf
test@social:~$ sudo systemctl reload apache2
Mastondon-Instanz starten
Nun sind alle Voarbeiten abgeschlossen und die eigene Mastodon-Instanz kann gestartet werden:
test@social:~$ sudo systemctl start mastodon-web.service
test@social:~$ sudo systemctl start mastodon-sidekiq.service
test@social:~$ sudo systemctl start mastodon-streaming.service
Eine tolle Anleitung. Wie müsste der Virtual Host für Apache aussehen, wenn man statt der klassischen Installation zur Docker-Variante von Mastodon greift?