Da die Dokumentation zu Mastodon doch eher sehr spärlich ist, versuche hier nun auf deutsch eine kleine Installationsanleitung für Mastodon auf Debian 8 (Jessie) zu geben. Diese Anleitung sollte sich auch recht schnell für andere Distributionen adaptieren lassen.
Benötigte Pakete
Bitte folgende Befehle ausführen:
sudo apt-get install imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev nodejs file git curl curl -sL https://deb.nodesource.com/setup_4.x | sudo bash - sudo apt-get install nodejs sudo npm install -g yarn sudo apt-get install redis-server redis-tools sudo apt-get install postgresql postgresql-contrib
Hiermit werden imagemagick, ffmpeg, Node.js, git, curl, yarn, redis und PostgreSQL installiert. zusätzlich noch einige Bibliotheken, die benötigt werden.
Nach der Installation der Basis Pakete, wird nun die PostgreSQL Datenbank angelegt.
Datenbank anlegen
Zunächst legen wir einen Benutzer und eine Datenbank für Mastodon an:
sudo su - postgres psql
Im PostgreSQL Prompt dann
CREATE USER mastodon CREATEDB; \q
Damit wäre die Datenbank angelegt und der User auch. (Datenbank: mastodon, User: mastodon. Namledung erfolgt über den lokalen Linux Account)
Benutzer für Mastodon anlegen
Mittels
adduser mastodon
Wir der Nutzer mastodon
angelegt. Dieser hat sein Heimverzeichnis unter /home/mastodon
und wird anschließend noch der Gruppe www-data
(für apache2
) hinzugefügt.
usermod -aG www-data mastodon
Nun installieren wir RVM.
Installation von RVM
Zunächst wechseln wir zum User mastodon
und installieren anschließend RVM (Ruby Version Manager). Durch diese Installation können wir jeder Zeit sicher stellen, dass wir das aktuell benötigte Ruby für Mastodon haben. Sollte es hier bei zu Schwierigkeiten kommen, hilft es oft, RVM einmal als root
zu installieren. (Fehlende Pakete zum Beispiel).
su - mastodon gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \curl -sSL https://get.rvm.io | bash -s stable rvm install 2.4.1 rvm use 2.4.1
Danach sollte ein ruby -v
die Version 2.4.1 anzeigen.
Klonen von Mastodon
Da Mastodon auf GitHub liegt, klonen wir nun den Quellcode als User mastodon
.
cd ~ git clone https://github.com/tootsuite/mastodon.git live cd live git checkout $(git tag | tail -n 1)
Im live Verzeichnis angekommen, installieren wir nun die Abhängigkeiten von Mastodon
Installation von Mastodon
gem install bundler bundle install --deployment --without development test yarn install
Sollte es hier zu Problemen kommen, kann es an fehlenden Paketen liegen. Hier hilft eine Google Suche.
Konfiguration von Mastodon
Damit Mastodon richtig läuft, muss es nun konfiguriert werden. Dazu kopiert ihr die .env.production.sample
unter /home/mastodon/live
und passt die Werte an:
cp .env.production.sample .env.production vim .env.production
# Service dependencies REDIS_HOST=redis REDIS_PORT=6379 # REDIS_DB=0 DB_HOST=db DB_USER=postgres DB_NAME=postgres DB_PASS= DB_PORT=5432 # Federation LOCAL_DOMAIN=example.com LOCAL_HTTPS=true # Use this only if you need to run mastodon on a different domain than the one used for federation. # Do not use this unless you know exactly what you are doing. # WEB_DOMAIN=mastodon.example.com # Application secrets # Generate each with the `rake secret` task (`docker-compose run --rm web rake secret` if you use docker compose) PAPERCLIP_SECRET= SECRET_KEY_BASE= OTP_SECRET= # Registrations # Single user mode will disable registrations and redirect frontpage to the first profile # SINGLE_USER_MODE=true # Prevent registrations with following e-mail domains # EMAIL_DOMAIN_BLACKLIST=example1.com|example2.de|etc # Only allow registrations with the following e-mail domains # EMAIL_DOMAIN_WHITELIST=example1.com|example2.de|etc # Optionally change default language # DEFAULT_LOCALE=de # E-mail configuration # Note: Mailgun and SparkPost (https://sparkpo.st/smtp) each have good free tiers # If you want to use an SMTP server without authentication (e.g local Postfix relay) # then set SMTP_AUTH_METHOD to 'none' and *comment* SMTP_LOGIN and SMTP_PASSWORD. # Leaving them blank is not enough for authentication method 'none'. SMTP_SERVER=smtp.mailgun.org SMTP_PORT=587 SMTP_LOGIN= SMTP_PASSWORD= SMTP_FROM_ADDRESS=notifications@example.com #SMTP_DOMAIN= # defaults to LOCAL_DOMAIN #SMTP_DELIVERY_METHOD=smtp # delivery method can also be sendmail #SMTP_AUTH_METHOD=plain #SMTP_OPENSSL_VERIFY_MODE=peer #SMTP_ENABLE_STARTTLS_AUTO=true # Optional user upload path and URL (images, avatars). Default is :rails_root/public/system. If you set this variable, you are responsible for making your HTTP server (eg. nginx) serve these files. # PAPERCLIP_ROOT_PATH=/var/lib/mastodon/public-system # PAPERCLIP_ROOT_URL=/system # Optional asset host for multi-server setups # CDN_HOST=assets.example.com # S3 (optional) # S3_ENABLED=true # S3_BUCKET= # AWS_ACCESS_KEY_ID= # AWS_SECRET_ACCESS_KEY= # S3_REGION= # S3_PROTOCOL=http # S3_HOSTNAME=192.168.1.123:9000 # S3 (Minio Config (optional) Please check Minio instance for details) # S3_ENABLED=true # S3_BUCKET= # AWS_ACCESS_KEY_ID= # AWS_SECRET_ACCESS_KEY= # S3_REGION= # S3_PROTOCOL=https # S3_HOSTNAME= # S3_ENDPOINT= # S3_SIGNATURE_VERSION= # Optional alias for S3 if you want to use Cloudfront or Cloudflare in front # S3_CLOUDFRONT_HOST= # Streaming API integration # STREAMING_API_BASE_URL= # Advanced settings # If you need to use pgBouncer, you need to disable prepared statements: # PREPARED_STATEMENTS=false # Cluster number setting for streaming API server. # If you comment out following line, cluster number will be `numOfCpuCores - 1`. STREAMING_CLUSTER_NUM=1
Die Datei ist ausreichend dokumentiert. Für die SMTP_DELIVERY_METHOD
habe ich sendmail
gewählt, da ich einen lokalen Mailserver habe.
Nach der Konfiguration fehlen nur noch zwei Befehle:
RAILS_ENV=production bundle exec rails db:setup RAILS_ENV=production bundle exec rails assets:precompile
Danach ist das Setup von Mastodon erledigt. Es fehlen nun nur noch die Konfiguration für den Apache Webserver und die System Dienste.
Systemd Skripte
Um Mastodon starten, stoppen und neustarten zu können, benötigt Debian 8 Systemd Skripte. Mit den Bedingungen von oben sehen diese nun so aus:
/etc/systemd/system/mastodon-web.service
[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.4.1/wrappers/bundle exec puma -C config/puma.rb TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target
/etc/systemd/system/mastodon-sidekiq.service
[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.4.1/wrappers/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target
/etc/systemd/system/mastodon-streaming.service
[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/local/bin/npm run start TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target
Nun kann Mastodon durch systemctl start mastodon-*
gestartet werden.
Apache Webserver Konfiguration
Damit nun Mastodon erreichbar ist, braucht ihr noch die Apache Konfiguration. Zunächst einmal müssen einige Module aktiviert werden:
a2enmod proxy a2enmod proxy_wstunnel
Danach unter /etc/apache2/sites-available
eine VHost Konfiguration für euren Virtuellen Host anlegen. Beispiel für meine Instanz:
toot.krinetzki.de.conf
<VirtualHost *:80> ServerName toot.krinetzki.de Redirect permanent / https://toot.krinetzki.de </VirtualHost> <VirtualHost *:443> ServerAdmin stephan@krinetzki.de ServerName toot.krinetzki.de Use SSLSettings toot.krinetzki.de DocumentRoot /home/mastodon/live/public ProxyPreserveHost On ProxyRequests Off RequestHeader set X_FORWARDED_PROTO 'https' ProxyPass /api/v1/streaming ws://localhost:4000 ProxyPassReverse /api/v1/streaming ws://localhost:4000 ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ # Logfiles CustomLog /var/log/apache2/toot.krinetzki.de_access_log combined ErrorLog /var/log/apache2/toot.krinetzki.de_error_log <Directory /home/mastodon/live/public> Require all granted AllowOverride None Options -MultiViews +FollowSymLinks Order allow,deny Allow from all </Directory> ServerSignature Off </VirtualHost>
Noch die Seite aktivieren
a2ensite toot.krinetzki.de.conf
Und fertig ist die Installation.
Danke für die Anleitung 🙂