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.
1 2 3 4 5 6 |
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.
1 2 |
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.
1 |
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:
1 2 3 4 5 6 |
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:
1 2 3 4 |
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:
1 2 3 |
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:
1 2 |
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:
1 |
test@social:~$ sudo vim.tiny /etc/systemd/system/mastodon-web.service |
und mit folgenden Inhalt befüllen, danach speichern:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[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:
1 |
test@social:~$ sudo vim.tiny /etc/systemd/system/mastodon-sidekiq.service |
und mit folgenden Inhalt befüllen, danach speichern:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[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:
1 |
test@social:~$ sudo vim.tiny /etc/systemd/system/mastodon-streaming.service |
und mit folgenden Inhalt befüllen, danach speichern:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[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:
1 2 3 |
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:
1 2 3 |
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:
1 |
test@social:~$ sudo vim.tiny /etc/apache2/sites-available/social.test.local.conf |
und nachfolgenden Inhalt einfügen:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<VirtualHost *:80> ServerAdmin contact@test.local ServerName social.test.local Redirect Permanent / https://social.test.local/ </VirtualHost> <VirtualHost *:443> 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 <LocationMatch "^/(assets|avatars|emoji|headers|packs|sounds|system)> Header always set Cache-Control "public, max-age=31536000, immutable" Require all granted </LocationMatch> 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 </VirtualHost> |
Zum Abschluss die Konfoguration speichern, aktivieren und den Webserver neu starten:
1 2 |
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:
1 2 3 |
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?