Mastodon bei Hostsharing: Unterschied zwischen den Versionen

Aus Hostsharing Wiki
Zur Navigation springen Zur Suche springen
(Konfiguration der Mastodon Software)
K (→‎Starten der Dienste: mastodon -> live)
(40 dazwischenliegende Versionen von 7 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
{{Baustelle}}
Mastodon ist ein verteilter Microblogging Dienst, der das ActivityPub-Protokoll verwendet.
 
Wenn man nur wenige Nutzer oder gar nur für sich selbst einen Einstiegspunkt ins "Fediverse" schaffen will, kann sich auch die Ressourcen-schonende Alternative [[Pleroma]] anbieten.
 
Diese Anleitung beschreibt, wie man Mastodon auf der Managed Hosting Plattform von Hostsharing installieren kann.
 
Hostsharing selbst nutzt die Hosting Plattform und betreibt zwei Mastodon Instanzen:
* https://geno.social
* https://hostsharing.coop
 
Der Autor dieser Seite betreibt:
* https://krefeld.life


{{Textkasten|gelb|Für Managed Server|Ein funktionierender Mastodon-Server erfordert mehrere laufende Server-Dienste. Für den Betrieb ist ein Managed Server sinnvoll.}}
{{Textkasten|gelb|Für Managed Server|Ein funktionierender Mastodon-Server erfordert mehrere laufende Server-Dienste. Für den Betrieb ist ein Managed Server sinnvoll.}}
Zeile 10: Zeile 21:
# Einen Postgresql-User ''xyz00_mastuser'' mit Passwort ''meinPasswort''
# Einen Postgresql-User ''xyz00_mastuser'' mit Passwort ''meinPasswort''
# Eine Postgresql-Datenbank ''xyz00_mastdb'' mit Datenbank-Owner ''xyz00_mastuser''
# Eine Postgresql-Datenbank ''xyz00_mastdb'' mit Datenbank-Owner ''xyz00_mastuser''
Verwendete IP-Ports der Server-Dienste:
# Monit: localhost:32001
# Redis: localhost:32002
# Mastodon-Web: localhost:32003
# Mastodon-Streaming: localhost:32004


== Konfiguration des Redis Server ==
== Konfiguration des Redis Server ==
Zeile 17: Zeile 34:
     daemonize yes
     daemonize yes
     pidfile /home/pacs/xyz00/users/mastodon/redis/var/redis-server.pid
     pidfile /home/pacs/xyz00/users/mastodon/redis/var/redis-server.pid
     port 32201
    requirepass <hierhin-gehoert-ein-redis-passwort>
     port 32002
     tcp-backlog 128
     tcp-backlog 128
     bind 127.0.0.1
     bind 127.0.0.1
Zeile 34: Zeile 52:
== Installation von NodeJS ==
== Installation von NodeJS ==


Als User 'xyz00-mastodon'': Installation von ''nvm'' und ''nodejs'' (Version 6) nach der Anleitung [[NodeJS]]
Als User 'xyz00-mastodon'': Installation von ''nvm'' und ''nodejs'' (Version 12) nach der Anleitung [[NodeJS]]


Installation von ''yarn'' mit:
Installation von ''yarn'' mit:
Zeile 63: Zeile 81:
     git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
     git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build


Nun kann die benötigte Ruby-Bersion installiert werden:
Nun kann die benötigte Ruby-Version installiert werden:


     rbenv install 2.5.1
     rbenv install 2.7.2


== Installation der Mastodon Software ==
== Installation der Mastodon Software ==
Zeile 90: Zeile 108:
== Konfiguration der Mastodon Software ==
== Konfiguration der Mastodon Software ==


Anlegen einer Datei ''/home/pacs/xyz00/users/mastodon/mystodon/live/.env.production'' mit dem folgenden Inhalt:
Anlegen einer Datei ''/home/pacs/xyz00/users/mastodon/live/.env.production'' mit dem folgenden Inhalt:


     REDIS_HOST=localhost
     REDIS_HOST=localhost
     REDIS_PORT=32168
     REDIS_PORT=32002
    REDIS_PASSWORD=<hierhin-gehoert-ein-redis-passwort>
     DB_HOST=localhost
     DB_HOST=localhost
     DB_USER=peh16_krlife
     DB_USER=xyz00_mastuser
     DB_NAME=peh16_krlife
     DB_NAME=xyz00_mastdb
     DB_PASS=MgHiw+knw
     DB_PASS=meinPasswort
     DB_PORT=5432
     DB_PORT=5432
     LOCAL_DOMAIN=krefeld.life
     LOCAL_DOMAIN=beispiel.social
     SECRET_KEY_BASE=12ab..
     SECRET_KEY_BASE=12ab..
     OTP_SECRET=34ef..
     OTP_SECRET=34ef..
Zeile 107: Zeile 126:
     SMTP_SERVER=localhost
     SMTP_SERVER=localhost
     SMTP_PORT=25
     SMTP_PORT=25
     SMTP_FROM_ADDRESS=notifications@krefeld.life
     SMTP_FROM_ADDRESS=notifications@beispiel.social
     SMTP_AUTH_METHOD=none
     SMTP_AUTH_METHOD=none
     SMTP_OPENSSL_VERIFY_MODE=none
     SMTP_OPENSSL_VERIFY_MODE=none
Zeile 126: Zeile 145:
     RAILS_ENV=production bundle exec rails db:schema:load
     RAILS_ENV=production bundle exec rails db:schema:load
     RAILS_ENV=production bundle exec rails db:seed
     RAILS_ENV=production bundle exec rails db:seed
Erzeugen der Web-Resourcen
    RAILS_ENV=production bundle exec rails assets:precompile
== Starten der Dienste  ==
Zum Start aller notwendigen Dienste wird in dieser Anleitung ''monit'' benutzt. Hier ein Beispiel für eine Datei ''.monitrc'' (überlange Zeilen werden hier im Wiki umgebrochen)
    set daemon 60
        with start delay 120
    set logfile /home/pacs/xyz00/users/mastodon/monit/var/monit.log
    set idfile /home/pacs/xyz00/users/mastodon/monit/var/monit.id
    set statefile /home/pacs/xyz00/users/mastodon/monit/var/monit.state
    set mailserver localhost
    set mail-format { from: monit@beispiel.social }
    set alert mastodon@beispiel.social
    set httpd port 32001 address xyz00.hostsharing.net
        allow mostodon:monitpassword
    check process redis with pidfile /home/pacs/xyz00/users/mastodon/redis/var/redis-server.pid
        start program "/usr/bin/redis-server /home/pacs/xyz00/users/mastodon/redis/etc/redis.conf"
        stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/redis/var/redis-server.pid )'"
    check process mstdn_web with pidfile /home/pacs/xyz00/users/mastodon/live/var/puma.pid
        depends redis
        start program "/bin/bash -c 'export RAILS_ENV=production && export HOME=/home/pacs/xyz00/users/mastodon && cd $HOME/live && ( $HOME/.rbenv/shims/bundle exec puma -C config/puma.rb -e production -b tcp://127.0.0.1:32003 >$HOME/live/var/puma.log 2>&1 &  echo $! > $HOME/live/var/puma.pid  )'"
        stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/live/var/puma.pid )'"
    check process mstdn_sidekiq with pidfile /home/pacs/xyz00/users/mastodon/live/var/sidekiq.pid
        depends redis
        start program "/bin/bash -c 'export RAILS_ENV=production && export DB_POOL=5 && export HOME=/home/pacs/xyz00/users/mastodon && cd $HOME/live && ( $HOME/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push -q scheduler >$HOME/live/var/sidekiq.log 2>&1 &  echo $! > $HOME/live/var/sidekiq.pid  )'"
        stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/live/var/sidekiq.pid )'"
    check process mstdn_streaming with pidfile /home/pacs/xyz00/users/mastodon/live/var/streaming.pid
        depends redis
        start program "/bin/bash -c 'export HOME=/home/pacs/xyz00/users/mastodon && export NVM_DIR="$HOME/.nvm" && export NVM_BIN=/home/pacs/xyz00/users/mastodon/.nvm/versions/node/v12.22.1/bin && export NODE_ENV=production && export PORT=32004 && export BIND=127.0.0.1 && cd $HOME/live && ( $HOME/.nvm/versions/node/v12.22.1/bin/node streaming/index.js >$HOME/live/var/streaming.log 2>&1 &  echo $! > $HOME/live/var/streaming.pid  )'"
        stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/live/var/streaming.pid )'"


== Einrichten des Apache VHost ==
== Einrichten des Apache VHost ==
Zeile 141: Zeile 194:
     RewriteBase /
     RewriteBase /
     RewriteCond %{REQUEST_URI}  ^/api/v1/streaming    [NC]
     RewriteCond %{REQUEST_URI}  ^/api/v1/streaming    [NC]
     RewriteRule .* ws://localhost:4000%{REQUEST_URI}  [proxy]
     RewriteRule .* ws://localhost:32004%{REQUEST_URI}  [proxy]
     RequestHeader set X-Forwarded-Proto "https"
     RequestHeader set X-Forwarded-Proto "https"
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-l
     RewriteCond %{REQUEST_FILENAME} !-l
     RewriteRule .* http://localhost:3000%{REQUEST_URI} [proxy]
     RewriteRule .* http://localhost:32003%{REQUEST_URI} [proxy]
     RequestHeader set X-Forwarded-Proto "https"
     RequestHeader set X-Forwarded-Proto "https"


Die Ports 3000 und 4000 sind die Voreinstellung von Mastodon und sollten angepasst werden.
== Cronjobs ==
 
''Cron'' wird für zwei Aufgaben genutzt:
* Start von monit nach einem Server Reboot
* Aufräumen von alten Resourcen
 
Einrichten der crontab mit ''cronttab -e''
 
    HOME=/home/pacs/xyz00/users/mastodon
    MAILTO=mastodon@beispiel.social
    RAILS_ENV=production
    NUM_DAYS=31
   
    @reboot /usr/bin/monit -c $HOME/.monitrc
    18 4 * * * cd $HOME/live && $HOME/live/bin/tootctl media remove
 
== Volltextsuche ==
 
In der installierten Version gibt es noch keine Volltextsuche. Es kann lediglich nach Nutzerkennungen und Hastags gesucht werden. Für die Volltextsuche kann optional Elasticsearch installiert werden.
 
* [[Elasticsearch]] bei Hostsharing
* https://docs.joinmastodon.org/admin/optional/elasticsearch/
 
== Instanz einrichten ==
Nach der Installation kann man sich auf https://beispiel.social einen Benutzer einrichten.
 
Auf der Kommandozeile:
 
RAILS_ENV=production bin/tootctl accounts create \
  alice \
  --email alice@example.com \
  --confirmed \
  --role admin
 
Weitere Einrichtung sollte vorgenommen werden, z.B. eine Beschreibung der Instanz hinterlegen, siehe https://docs.joinmastodon.org/admin/setup/
 
== Mastodon Updates ==
 
siehe:
* https://github.com/tootsuite/mastodon/releases
 
(hier für das Update auf die Mastodon Version v2.8.0 mit Ruby 2.6.1)
 
=== Ruby ===
 
    cd ~/.rbenv
    git pull
    cd ~/.rbenv/plugins/ruby-build
    git pull
    cd
    rbenv install -l
    rbenv install 2.6.1
    rbenv global 2.6.1
 
=== Mastodon ===
 
    cd ~/mastodon/live
    git fetch
    git checkout v2.8.0
    gem update --system
    bundle install
    yarn install
    RAILS_ENV=production bundle exec rails db:migrate
    RAILS_ENV=production bundle exec rails assets:precompile
 
Restart Mastodon!


== Links ==
== Links ==


* https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Production-guide.md
* [https://joinmastodon.org/ Offizielle Webseite von Mastodon]
* im Archiv: https://github.com/mastodon/documentation/blob/archive/Running-Mastodon/Production-guide.md
* aktuell: https://docs.joinmastodon.org/admin/install/
* https://krinetzki.de/2017/04/installation-von-mastodon-auf-debian-8-jessie/
* https://krinetzki.de/2017/04/installation-von-mastodon-auf-debian-8-jessie/
* [https://github.com/tpokorra/Hostsharing-Ansible-Mastodon Ansible Playbook für Hostsharing]
[[Kategorie:Installationsanleitungen]]
[[Kategorie:Installationsanleitungen]]
[[Kategorie:Fediverse]]
[[Kategorie:Activitypub]]
[[Kategorie:Ansible Playbook]]

Version vom 21. November 2022, 11:50 Uhr

Mastodon ist ein verteilter Microblogging Dienst, der das ActivityPub-Protokoll verwendet.

Wenn man nur wenige Nutzer oder gar nur für sich selbst einen Einstiegspunkt ins "Fediverse" schaffen will, kann sich auch die Ressourcen-schonende Alternative Pleroma anbieten.

Diese Anleitung beschreibt, wie man Mastodon auf der Managed Hosting Plattform von Hostsharing installieren kann.

Hostsharing selbst nutzt die Hosting Plattform und betreibt zwei Mastodon Instanzen:

Der Autor dieser Seite betreibt:

Für Managed Server

Ein funktionierender Mastodon-Server erfordert mehrere laufende Server-Dienste. Für den Betrieb ist ein Managed Server sinnvoll.


Vorbereitungen

Mit Hilfe von HSAdmin wird angelegt:

  1. Ein User als Service-User mit /bin/bash als Shell, zum Beispiel Beispiel: xyz00-mastodon
  2. Eine Domain mit xyz00-mastodon als Domain-Administrator, zum Beispiel beispiel.social
  3. Einen Postgresql-User xyz00_mastuser mit Passwort meinPasswort
  4. Eine Postgresql-Datenbank xyz00_mastdb mit Datenbank-Owner xyz00_mastuser

Verwendete IP-Ports der Server-Dienste:

  1. Monit: localhost:32001
  2. Redis: localhost:32002
  3. Mastodon-Web: localhost:32003
  4. Mastodon-Streaming: localhost:32004

Konfiguration des Redis Server

Anlegen einer Datei /home/pacs/xyz00/users/mastodon/redis/etc/redis.conf mit folgendem Inhalt:

   daemonize yes
   pidfile /home/pacs/xyz00/users/mastodon/redis/var/redis-server.pid
   requirepass <hierhin-gehoert-ein-redis-passwort>
   port 32002
   tcp-backlog 128
   bind 127.0.0.1
   timeout 300
   loglevel notice
   logfile /home/pacs/xyz00/users/mastodon/redis/var/redis.log
   databases 16
   save 900 1
   save 300 10
   save 60 10000
   slave-serve-stale-data yes
   appendonly no
   dbfilename dump.rdb
   dir /home/pacs/xyz00/users/mastodon/redis/var

Installation von NodeJS

Als User 'xyz00-mastodon: Installation von nvm und nodejs (Version 12) nach der Anleitung NodeJS

Installation von yarn mit:

   npm install -g yarn

Installation von Ruby

Als User xyz00-mastodon: Installation von Ruby mit rbenv mit folgenden Befehlen:

Zunächst rbenv and ruby-build:

   git clone https://github.com/rbenv/rbenv.git ~/.rbenv
   cd ~/.rbenv && src/configure && make -C src
   echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
   echo 'eval "$(rbenv init -)"' >> ~/.profile

starte neue Shell:

   exec bash

Überprüfe rbenv-Installation

   type rbenv

Installiere ruby-build als rbenv-Plugin

   git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

Nun kann die benötigte Ruby-Version installiert werden:

   rbenv install 2.7.2

Installation der Mastodon Software

Weiterhin Als User xyz00-mastodon:

   cd ~
   git clone https://github.com/tootsuite/mastodon.git live
   cd ~/live

Die stabile Version auschecken:

   git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)

Ruby Pakete installieren:

   gem install bundler
   bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test

Node.js Pakete installieren:

   yarn install --pure-lockfile

Konfiguration der Mastodon Software

Anlegen einer Datei /home/pacs/xyz00/users/mastodon/live/.env.production mit dem folgenden Inhalt:

   REDIS_HOST=localhost
   REDIS_PORT=32002
   REDIS_PASSWORD=<hierhin-gehoert-ein-redis-passwort>
   DB_HOST=localhost
   DB_USER=xyz00_mastuser
   DB_NAME=xyz00_mastdb
   DB_PASS=meinPasswort
   DB_PORT=5432
   LOCAL_DOMAIN=beispiel.social
   SECRET_KEY_BASE=12ab..
   OTP_SECRET=34ef..
   VAPID_PRIVATE_KEY=ABCD..
   VAPID_PUBLIC_KEY=EFGH..
   DEFAULT_LOCALE=de
   SMTP_SERVER=localhost
   SMTP_PORT=25
   SMTP_FROM_ADDRESS=notifications@beispiel.social
   SMTP_AUTH_METHOD=none
   SMTP_OPENSSL_VERIFY_MODE=none
   STREAMING_CLUSTER_NUM=1

Die Zufallswerte für die Variablen SECRET_KEY_BASE und OTP_SECRET erzeugt man durch zwei Aufrufe des Kommandos

   RAILS_ENV=production bundle exec rake secret

Die Werte für VAPID_PRIVATE_KEY und VAPID_PUBLIC_KEY erzeugt das Kommando

   RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key


Initialisieren der Datenbank:

   export SAFETY_ASSURED=1
   RAILS_ENV=production bundle exec rails db:schema:load
   RAILS_ENV=production bundle exec rails db:seed

Erzeugen der Web-Resourcen

   RAILS_ENV=production bundle exec rails assets:precompile

Starten der Dienste

Zum Start aller notwendigen Dienste wird in dieser Anleitung monit benutzt. Hier ein Beispiel für eine Datei .monitrc (überlange Zeilen werden hier im Wiki umgebrochen)

   set daemon 60
       with start delay 120
   set logfile /home/pacs/xyz00/users/mastodon/monit/var/monit.log
   set idfile /home/pacs/xyz00/users/mastodon/monit/var/monit.id
   set statefile /home/pacs/xyz00/users/mastodon/monit/var/monit.state
   set mailserver localhost
   set mail-format { from: monit@beispiel.social }
   set alert mastodon@beispiel.social
   set httpd port 32001 address xyz00.hostsharing.net 
       allow mostodon:monitpassword
   check process redis with pidfile /home/pacs/xyz00/users/mastodon/redis/var/redis-server.pid
       start program "/usr/bin/redis-server /home/pacs/xyz00/users/mastodon/redis/etc/redis.conf"
       stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/redis/var/redis-server.pid )'"
   check process mstdn_web with pidfile /home/pacs/xyz00/users/mastodon/live/var/puma.pid
       depends redis
       start program "/bin/bash -c 'export RAILS_ENV=production && export HOME=/home/pacs/xyz00/users/mastodon && cd $HOME/live && ( $HOME/.rbenv/shims/bundle exec puma -C config/puma.rb -e production -b tcp://127.0.0.1:32003 >$HOME/live/var/puma.log 2>&1 &  echo $! > $HOME/live/var/puma.pid  )'"
       stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/live/var/puma.pid )'"
   check process mstdn_sidekiq with pidfile /home/pacs/xyz00/users/mastodon/live/var/sidekiq.pid
       depends redis
       start program "/bin/bash -c 'export RAILS_ENV=production && export DB_POOL=5 && export HOME=/home/pacs/xyz00/users/mastodon && cd $HOME/live && ( $HOME/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push -q scheduler >$HOME/live/var/sidekiq.log 2>&1 &  echo $! > $HOME/live/var/sidekiq.pid  )'"
       stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/live/var/sidekiq.pid )'"
   check process mstdn_streaming with pidfile /home/pacs/xyz00/users/mastodon/live/var/streaming.pid
       depends redis
       start program "/bin/bash -c 'export HOME=/home/pacs/xyz00/users/mastodon && export NVM_DIR="$HOME/.nvm" && export NVM_BIN=/home/pacs/xyz00/users/mastodon/.nvm/versions/node/v12.22.1/bin && export NODE_ENV=production && export PORT=32004 && export BIND=127.0.0.1 && cd $HOME/live && ( $HOME/.nvm/versions/node/v12.22.1/bin/node streaming/index.js >$HOME/live/var/streaming.log 2>&1 &  echo $! > $HOME/live/var/streaming.pid  )'"
       stop program "/bin/bash -c '/bin/kill $( cat /home/pacs/xyz00/users/mastodon/live/var/streaming.pid )'"

Einrichten des Apache VHost

   cd ~/doms/beispiel.social
   rm -rf htdocs-ssl subs/www subs-ssl/www
   ln -s ~/live/public htdocs-ssl
   touch htdocs-ssl/.htaccess

Dann die htdocs-ssl/.htaccess mit dem Editor der Wahl öffnen und folgende Konfiguration einfügen:

   DirectoryIndex disabled
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_URI}  ^/api/v1/streaming    [NC]
   RewriteRule .* ws://localhost:32004%{REQUEST_URI}  [proxy]
   RequestHeader set X-Forwarded-Proto "https"
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule .* http://localhost:32003%{REQUEST_URI} [proxy]
   RequestHeader set X-Forwarded-Proto "https"

Cronjobs

Cron wird für zwei Aufgaben genutzt:

  • Start von monit nach einem Server Reboot
  • Aufräumen von alten Resourcen

Einrichten der crontab mit cronttab -e

   HOME=/home/pacs/xyz00/users/mastodon
   MAILTO=mastodon@beispiel.social
   RAILS_ENV=production
   NUM_DAYS=31
   
   @reboot /usr/bin/monit -c $HOME/.monitrc
   18 4 * * * cd $HOME/live && $HOME/live/bin/tootctl media remove

Volltextsuche

In der installierten Version gibt es noch keine Volltextsuche. Es kann lediglich nach Nutzerkennungen und Hastags gesucht werden. Für die Volltextsuche kann optional Elasticsearch installiert werden.

Instanz einrichten

Nach der Installation kann man sich auf https://beispiel.social einen Benutzer einrichten.

Auf der Kommandozeile:

RAILS_ENV=production bin/tootctl accounts create \
  alice \
  --email alice@example.com \
  --confirmed \
  --role admin

Weitere Einrichtung sollte vorgenommen werden, z.B. eine Beschreibung der Instanz hinterlegen, siehe https://docs.joinmastodon.org/admin/setup/

Mastodon Updates

siehe:

(hier für das Update auf die Mastodon Version v2.8.0 mit Ruby 2.6.1)

Ruby

   cd ~/.rbenv
   git pull
   cd ~/.rbenv/plugins/ruby-build
   git pull
   cd
   rbenv install -l
   rbenv install 2.6.1
   rbenv global 2.6.1

Mastodon

   cd ~/mastodon/live
   git fetch
   git checkout v2.8.0
   gem update --system
   bundle install
   yarn install
   RAILS_ENV=production bundle exec rails db:migrate
   RAILS_ENV=production bundle exec rails assets:precompile

Restart Mastodon!

Links