GNU/Linux >> LINUX-Kenntnisse >  >> Cent OS

So installieren Sie Mastodon unter CentOS 7

Mastodon ist ein kostenloses soziales Open-Source-Netzwerk, das auf einem offenen Webprotokoll basiert. Es verwendete Ruby on Rails für das Backend und React.js und Redux für das Frontend. In diesem Tutorial zeigen wir Ihnen, wie Sie Mastodon auf einem CentOS 7-Server installieren.

1. Aktualisieren Sie Ihren CentOS 7-Server und installieren Sie die erforderlichen Pakete

Melden Sie sich über SSH als sudo-Benutzer bei Ihrem VPS an:

ssh userame@IP_Address

Führen Sie nach der Anmeldung die folgenden Befehle aus, um sicherzustellen, dass alle installierten Pakete auf dem neuesten Stand sind:

sudo yum update

Installieren Sie als Nächstes die erforderlichen Pakete, die zum Erstellen von Mastodon erforderlich sind, mit dem folgenden Befehl:

sudo yum install curl git gpg gcc git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make autoconf automake libtool bison curl sqlite-devel ImageMagick libxml2-devel libxslt-devel gdbm-devel ncurses-devel glibc-headers glibc-devel libicu-devel libidn-devel protobuf-devel protobuf

2. Installieren Sie Node.js und Yarn

Wir werden Node.js v8 LTS aus dem NodeSource-Repository installieren, das davon abhängt, dass das EPEL-Repository aktiviert ist.

Um das EPEL-Repository auf Ihrem CentOS 7 VPS zu aktivieren, geben Sie den folgenden Befehl ein:

sudo yum install epel-release curl

Sobald das EPEL-Repository aktiviert ist, führen Sie den folgenden Befehl aus, um das Node.js v8 LTS-Repository hinzuzufügen:

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -

Sobald das NodeSource-Repository aktiviert ist, installieren Sie Node.js mit dem folgenden Befehl:

sudo yum install nodejs

Aktivieren Sie das Yarn-RPM-Repository mit:

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo

Installieren Sie die neueste Yarn-Version mit:

sudo yum install yarn

3. Installieren Sie PostgreSQL

Aktivieren Sie das PostgreSQL-Repository:

sudo rpm -Uvh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

Um den PostgreSQL-Server zu installieren, führen Sie den folgenden Befehl aus:

sudo yum install postgresql96-server postgresql96-contrib postgresql96-devel

Erstellen Sie nach Abschluss der Installation einen neuen Datenbankcluster mit:

sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb

Starten Sie den PostgreSQL-Dienst und aktivieren Sie ihn für den Start beim Booten:

sudo systemctl enable postgresql-9.6
sudo systemctl start postgresql-9.6

Melden Sie sich bei der PostgreSQL-Shell an:

sudo -u postgres psql

Erstellen Sie einen neuen Benutzer für die Mastodon-Instanz:

CREATE USER mastodon CREATEDB;

4. Installieren Sie Redis

Die Installation von Redis ist ziemlich einfach, führen Sie einfach den folgenden Befehl aus:

sudo yum install redis

5. Erstellen Sie einen neuen Systembenutzer

Führen Sie den folgenden Befehl aus, um einen neuen Systembenutzer für Mastodon zu erstellen:

sudo adduser mastodon

6. Installieren Sie Ruby

Wir werden Ruby mit dem Rbenv-Skript installieren.

Wechseln Sie vor dem Klonen des rbenv-Repositorys zum neuen mastodon-Benutzer:

sudo su - mastodon

Richten Sie rbenv und ruby-build mit den folgenden Befehlen ein:

cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
exec $SHELL

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
exec $SHELL

Sobald sowohl rbenv als auch ruby-build eingerichtet sind, installieren Sie die neueste Ruby-Version mit „

rbenv install 2.5.1
rbenv global 2.5.1

Um zu überprüfen, ob alles richtig gemacht wurde, verwenden Sie den Befehl ruby --version .

Die Ausgabe sollte ungefähr so ​​aussehen:

ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

7. Klonen Sie das Mastodon-Git-Repository und installieren Sie Abhängigkeiten

Die folgenden Befehle werden auch als Mastodon-Benutzer ausgeführt.

Klonen Sie das Mastodon-Git-Repository in ~/live Verzeichnis und Auschecken zum neuesten stabilen Mastodon-Zweig:

cd
git clone https://github.com/tootsuite/mastodon.git live
cd ~/live
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)

Installieren Sie Bundler- und Ruby-Abhängigkeiten mit den folgenden Befehlen:

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

Installieren Sie die node.js-Abhängigkeiten mit:

yarn install --pure-lockfile

8. Mastodon konfigurieren

Die folgenden Befehle werden als Mastodon-Benutzer ausgeführt.

Wechseln Sie in das Installationsverzeichnis von Mastodon und führen Sie den folgenden Befehl aus, um das Setup zu starten:

cd ~/live
RAILS_ENV=production bundle exec rake mastodon:setup

Das Installationsprogramm stellt Ihnen mehrere Fragen, generiert ein neues App-Secret, richtet das Datenbankschema ein und kompiliert die Assets.

Your instance is identified by its domain name. Changing it afterward will break things.
Domain name: your-domain.com

Single user mode disables registrations and redirects the landing page to your public profile.
Do you want to enable single user mode? No

Are you using Docker to run Mastodon? no

PostgreSQL host: /var/run/postgresql
PostgreSQL port: 5432
Name of PostgreSQL database: mastodon_production
Name of PostgreSQL user: mastodon
Password of PostgreSQL user:
Database configuration works! 🎆

Redis host: localhost
Redis port: 6379
Redis password:
Redis configuration works! 🎆

Do you want to store uploaded files on the cloud? No

Do you want to send e-mails from localhost? yes
E-mail address to send e-mails "from": Mastodon <[email protected]>
Send a test e-mail with this configuration right now? no

This configuration will be written to .env.production
Save configuration? Yes

Now that configuration is saved, the database schema must be loaded.
If the database already exists, this will erase its contents.
Prepare the database now? Yes
Running `RAILS_ENV=production rails db:setup` ...


Created database 'mastodon_production'

...

Done!

The final step is compiling CSS/JS assets.
This may take a while and consume a lot of RAM.
Compile the assets now? Yes
Running `RAILS_ENV=production rails assets:precompile` ...


yarn install v1.9.4

...

Using /home/mastodon/live/config/webpacker.yml file for setting up webpack paths
Compiling…
  Compiled all packs in /home/mastodon/live/public/packs
  Rendering errors/500.html.haml within layouts/error
  Rendered errors/500.html.haml within layouts/error (2596.9ms)
Done!

All done! You can now power on the Mastodon server 🐘

Do you want to create an admin user straight away? Yes
Username: admin
E-mail: [email protected]
You can login with the password: 80b4aA233adaeS86d095Scbf79302f81
You can change your password once you login.

9. Erstellen Sie Mastodon-Systemeinheiten

Die folgenden Befehle werden als Root- oder Sudo-Benutzer ausgeführt.

Öffnen Sie Ihren Texteditor und erstellen Sie die folgenden systemd-Unit-Dateien:

sudo nano /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/.rbenv/shims/bundle exec puma -C config/puma.rb
ExecReload=/bin/kill -SIGUSR1 $MAINPID
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target
sudo nano /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/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q push -q mailers -q pull
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target
sudo nano /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/bin/npm run start
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

Alle Dienste aktivieren und starten:

sudo systemctl enable mastodon-web.service
sudo systemctl enable mastodon-sidekiq.service
sudo systemctl enable mastodon-streaming.service

sudo systemctl start mastodon-web.service
sudo systemctl start mastodon-sidekiq.service
sudo systemctl start mastodon-streaming.service

10. Nginx installieren und konfigurieren

Um Nginx zu installieren, führen Sie den folgenden Befehl aus:

sudo yum install nginx

Erstellen Sie nach der Installation von nginx einen Serverblock für Ihre Domain. Vergessen Sie nicht, den korrekten Pfad zum SSL-Zertifikat und privaten Schlüssel festzulegen.

sudo nano /etc/nginx/conf.d/your-domain.com.conf
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
  listen 80;
  listen [::]:80;
  server_name your-domain.com;
  root /home/mastodon/live/public;
  # Useful for Let's Encrypt
  location /.well-known/acme-challenge/ { allow all; }
  location / { return 301 https://$host$request_uri; }
}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name your-domain.com;

  ssl_protocols TLSv1.2;
  ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:10m;

  ssl_certificate     /etc/ssl/certs/certificate.crt;
  ssl_certificate_key /etc/ssl/private/certificate.key;

  keepalive_timeout    70;
  sendfile             on;
  client_max_body_size 80m;

  root /home/mastodon/live/public;

  gzip on;
  gzip_disable "msie6";
  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

  add_header Strict-Transport-Security "max-age=31536000";

  location / {
    try_files $uri @proxy;
  }

  location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) {
    add_header Cache-Control "public, max-age=31536000, immutable";
    try_files $uri @proxy;
  }
  
  location /sw.js {
    add_header Cache-Control "public, max-age=0";
    try_files $uri @proxy;
  }

  location @proxy {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Proxy "";
    proxy_pass_header Server;

    proxy_pass http://127.0.0.1:3000;
    proxy_buffering off;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    tcp_nodelay on;
  }

  location /api/v1/streaming {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Proxy "";

    proxy_pass http://127.0.0.1:4000;
    proxy_buffering off;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    tcp_nodelay on;
  }

  error_page 500 501 502 503 504 /500.html;
}

Speichern Sie die Datei und starten Sie den nginx-Dienst neu:

sudo systemctl restart nginx

Sie können jetzt Ihren Browser öffnen, Ihre Domain eingeben und Ihnen wird das Mastodon-Anmeldeformular angezeigt.

Natürlich müssen Sie Mastodon nicht unter CentOS 7 installieren, wenn Sie einen unserer verwalteten Hosting-Dienste verwenden. In diesem Fall können Sie einfach unsere erfahrenen Linux-Administratoren bitten, Mastodon für Sie zu installieren. Sie sind 24×7 erreichbar und kümmern sich umgehend um Ihr Anliegen.

PS . Wenn Ihnen dieser Beitrag gefallen hat, lesen Sie weiter unter How to Install Mastodon on CentOS 7 Bitte teilen Sie es mit Ihren Freunden in den sozialen Netzwerken über die Schaltflächen auf der linken Seite oder hinterlassen Sie einfach unten eine Antwort. Danke.


Cent OS
  1. So installieren Sie PHP 7, 7.2 und 7.3 auf CentOS 7

  2. So installieren Sie Java 11 und 12 unter CentOS 7

  3. So installieren Sie Wine 4.0 unter CentOS 7

  4. So installieren Sie Vim 8.2 unter CentOS 7

  5. So installieren Sie VirtualBox unter CentOS 7

So installieren Sie Ruby unter CentOS 7

So installieren Sie PostgreSQL unter CentOS 7

So installieren Sie Go unter CentOS 7

So installieren Sie Python 3 unter CentOS 7

So installieren Sie R unter CentOS 7

So installieren Sie R unter CentOS 8