Mastodon bei Hostsharing: Unterschied zwischen den Versionen

Aus Hostsharing Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Zeile 31: Zeile 31:
Anlegen einer Datei ''/home/pacs/xyz00/users/mastodon/redis/etc/redis.conf'' mit folgendem Inhalt:
Anlegen einer Datei ''/home/pacs/xyz00/users/mastodon/redis/etc/redis.conf'' mit folgendem Inhalt:


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


== Installation von NodeJS ==
== Installation von NodeJS ==
Zeile 55: Zeile 57:
Installation von ''yarn'' mit:
Installation von ''yarn'' mit:


    npm install -g yarn
<syntaxhighlight lang="bash">
npm install -g yarn
</syntaxhighlight>


== Installation von Ruby ==
== Installation von Ruby ==
Zeile 63: Zeile 67:
Zunächst ''rbenv'' and ''ruby-build'':
Zunächst ''rbenv'' and ''ruby-build'':


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


starte neue Shell:
starte neue Shell:


    exec bash
<syntaxhighlight lang="bash">
exec bash
</syntaxhighlight>


Überprüfe rbenv-Installation
Überprüfe rbenv-Installation


    type rbenv
<syntaxhighlight lang="bash"><
type rbenv
</syntaxhighlight>


Installiere ruby-build als rbenv-Plugin
Installiere ruby-build als rbenv-Plugin


    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
<syntaxhighlight lang="bash">
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
</syntaxhighlight>


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


    rbenv install 3.2.3
<syntaxhighlight lang="bash">
rbenv install 3.2.3
</syntaxhighlight>


== Installation der Mastodon Software ==
== Installation der Mastodon Software ==
Zeile 88: Zeile 102:
Weiterhin Als User ''xyz00-mastodon'':   
Weiterhin Als User ''xyz00-mastodon'':   


    cd ~
<syntaxhighlight lang="bash">
    git clone https://github.com/tootsuite/mastodon.git live
cd ~
    cd ~/live
git clone https://github.com/tootsuite/mastodon.git live
cd ~/live
</syntaxhighlight>


Die stabile Version auschecken:
Die stabile Version auschecken:


    git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
<syntaxhighlight lang="bash">
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
</syntaxhighlight>


Ruby Pakete installieren:
Ruby Pakete installieren:


    gem install bundler
<syntaxhighlight lang="bash">
    bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
gem install bundler
bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
</syntaxhighlight>


Node.js Pakete installieren:
Node.js Pakete installieren:


    yarn install --pure-lockfile
<syntaxhighlight lang="bash">
yarn install --pure-lockfile
</syntaxhighlight>


== Konfiguration der Mastodon Software ==
== Konfiguration der Mastodon Software ==
Zeile 134: Zeile 156:
Die Zufallswerte für die Variablen SECRET_KEY_BASE und OTP_SECRET erzeugt man durch zwei Aufrufe des Kommandos
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
<syntaxhighlight lang="bash">
RAILS_ENV=production bundle exec rake secret
</syntaxhighlight>


Die Werte für VAPID_PRIVATE_KEY und VAPID_PUBLIC_KEY erzeugt das Kommando
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
<syntaxhighlight lang="bash">
 
RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key
</syntaxhighlight>


Initialisieren der Datenbank:
Initialisieren der Datenbank:


    export SAFETY_ASSURED=1
<syntaxhighlight lang="bash">
    RAILS_ENV=production bundle exec rails db:schema:load
export SAFETY_ASSURED=1
    RAILS_ENV=production bundle exec rails db:seed
RAILS_ENV=production bundle exec rails db:schema:load
RAILS_ENV=production bundle exec rails db:seed
</syntaxhighlight>


Erzeugen der Web-Resourcen
Erzeugen der Web-Resourcen


    yarn set version classic
<syntaxhighlight lang="bash">
    RAILS_ENV=production bundle exec rails assets:precompile
yarn set version classic
RAILS_ENV=production bundle exec rails assets:precompile
</syntaxhighlight>


== Starten der Dienste  ==
== Starten der Dienste  ==
Zeile 302: Zeile 331:
Auf der Kommandozeile:
Auf der Kommandozeile:


RAILS_ENV=production bin/tootctl accounts create \
<syntaxhighlight lang="bash">
  alice \
RAILS_ENV=production bin/tootctl accounts create \
  --email alice@example.com \
  alice \
  --confirmed \
  --email alice@example.com \
  --role Admin
  --confirmed \
  --role Admin
</syntaxhighlight>


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


    cd ~/.rbenv
<syntaxhighlight lang="bash">
    git pull
cd ~/.rbenv
    cd ~/.rbenv/plugins/ruby-build
git pull
    git pull
cd ~/.rbenv/plugins/ruby-build
    cd
git pull
    rbenv install -l
cd
    rbenv install 3.2.3
rbenv install -l
    rbenv global 3.2.3
rbenv install 3.2.3
rbenv global 3.2.3
</syntaxhighlight>


=== Mastodon ===
=== Mastodon ===


    cd ~/mastodon/live
<syntaxhighlight lang="bash">
    git fetch
cd ~/mastodon/live
    git checkout v4.2.9
git fetch
    gem update --system
git checkout v4.2.9
    bundle install
gem update --system
    yarn install
bundle install
    RAILS_ENV=production bundle exec rails db:migrate
yarn install
    yarn set version classic
RAILS_ENV=production bundle exec rails db:migrate
    RAILS_ENV=production bundle exec rails assets:precompile
yarn set version classic
RAILS_ENV=production bundle exec rails assets:precompile
</syntaxhighlight>


Restart Mastodon!
Restart Mastodon!

Version vom 14. Juni 2024, 10:31 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. Redis: localhost:32002
  2. Mastodon-Web: localhost:32003
  3. 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 20) 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 3.2.3

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

yarn set version classic
RAILS_ENV=production bundle exec rails assets:precompile

Starten der Dienste

Zum Start aller notwendigen Dienste wird in dieser Anleitung systemctl benutzt.

Die Datei ~/.config/systemd/user/redis.service kann so aussehen:

[Unit]
Description=Redis User Service

[Service]
WorkingDirectory=%h/var/redis
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
ExecStart=/usr/bin/redis-server %h/etc/redis.conf
Restart=always
PrivateTmp=true
NoNewPrivileges=true

[Install]
WantedBy=default.target

Die Datei ~/.config/systemd/user/puma.service kann so aussehen:

[Unit]
Description=Mastodon Web Service Puma
After=redis.service

[Service]
WorkingDirectory=%h/live
Environment="RAILS_ENV=production"
ExecStart=%h/.rbenv/shims/bundle exec puma -C config/puma.rb -e production -b tcp://127.0.0.1:32003
StandardError=append:%h/var/log/puma.log
StandardOutput=append:%h/var/log/puma.log
Restart=always
PrivateTmp=true
NoNewPrivileges=true

[Install]
WantedBy=default.target

Die Datei ~/.config/systemd/user/sidekiq.service kann so aussehen:

[Unit]
Description=Mastodon Sidekiq Service
After=redis.service

[Service]
WorkingDirectory=%h/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=5"
ExecStart=%h/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push -q scheduler
StandardError=append:%h/var/log/sidekiq.log
StandardOutput=append:%h/var/log/sidekiq.log
Restart=always
PrivateTmp=true
NoNewPrivileges=true

[Install]
WantedBy=default.target

Die Datei ~/.config/systemd/user/streaming.service kann so aussehen:

[Unit]
Description=Mastodon Streaming Service
After=redis.service

[Service]
WorkingDirectory=%h/live
Environment="NVM_DIR=%h/.nvm"
Environment="NVM_BIN=%h/.nvm/versions/node/v20.14.0/bin"
Environment="NODE_ENV=production"
Environment="PORT=32004"
Environment="BIND=127.0.0.1"

ExecStart=%h/.nvm/versions/node/v20.14.0/bin/node streaming/index.js
StandardError=append:%h/var/log/streaming.log
StandardOutput=append:%h/var/log/streaming.log
Restart=always
PrivateTmp=true
NoNewPrivileges=true

[Install]
WantedBy=default.target

Die Dienste werden dann aktiviert und gestartet:

systemctl --user enable redis --now
systemctl --user enable puma --now
systemctl --user enable streaming --now
systemctl --user enable sidekiq --now

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 folgende Aufgabe genutzt:

  • 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
    
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 v4.2.9 mit Ruby 3.2.3)

Ruby

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

Mastodon

cd ~/mastodon/live
git fetch
git checkout v4.2.9
gem update --system
bundle install
yarn install
RAILS_ENV=production bundle exec rails db:migrate
yarn set version classic
RAILS_ENV=production bundle exec rails assets:precompile

Restart Mastodon!

Links