Mastodon è un social network gratuito open source basato sul protocollo web aperto. Utilizzava Ruby on Rails per il back-end e React.js e Redux per il front-end. In questo tutorial, ti mostreremo come installare Mastodon su un server CentOS 7.
1. Aggiorna il tuo server CentOS 7 e installa i pacchetti necessari
Accedi al tuo VPS tramite SSH come utente sudo:
ssh userame@IP_Address
Una volta effettuato l'accesso, impartisci i seguenti comandi per assicurarti che tutti i pacchetti installati siano aggiornati:
sudo yum update
Quindi, installa l'installazione dei pacchetti prerequisiti necessari per la creazione di Mastodon con il seguente comando:
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. Installa Node.js e Yarn
Installeremo Node.js v8 LTS dal repository NodeSource che dipende dal repository EPEL abilitato.
Per abilitare il repository EPEL sul tuo CentOS 7 VPS, emetti il seguente comando:
sudo yum install epel-release curl
Una volta abilitato il repository EPEL, eseguire il comando seguente per aggiungere il repository LTS Node.js v8:
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
Una volta abilitato il repository NodeSource, installa Node.js con il seguente comando:
sudo yum install nodejs
Abilita il repository Yarn RPM con:
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
Installa l'ultima versione di Yarn con:
sudo yum install yarn
3. Installa PostgreSQL
Abilita il repository PostgreSQL:
sudo rpm -Uvh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
Per installare il server PostgreSQL, esegui il seguente comando:
sudo yum install postgresql96-server postgresql96-contrib postgresql96-devel
Una volta completata l'installazione, crea un nuovo cluster di database con:
sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb
Avvia il servizio PostgreSQL e abilitalo all'avvio all'avvio:
sudo systemctl enable postgresql-9.6 sudo systemctl start postgresql-9.6
Accedi alla shell di PostgreSQL:
sudo -u postgres psql
Crea un nuovo utente per l'istanza Mastodon:
CREATE USER mastodon CREATEDB;
4. Installa Redis
L'installazione di Redis è piuttosto semplice, basta eseguire il seguente comando:
sudo yum install redis
5. Crea un nuovo utente di sistema
Per creare un nuovo utente di sistema per Mastodon eseguire il seguente comando:
sudo adduser mastodon
6. Installa Ruby
Installeremo Ruby usando lo script Rbenv.
Prima di clonare il repository rbenv, passare al nuovo utente mastodon:
sudo su - mastodon
Configura rbenv e ruby-build con i seguenti comandi:
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
Una volta configurate sia rbenv che ruby-build, installa l'ultima versione di Ruby con”
rbenv install 2.5.1 rbenv global 2.5.1
Per verificare che tutto sia fatto correttamente, usa il comando ruby --version
.
L'output dovrebbe essere simile al seguente:
ruby --version ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
7. Clona il repository git di Mastodon e installa le dipendenze
Anche i seguenti comandi vengono eseguiti come utente mastodon.
Clona il repository git di mastodon nel ~/live
directory e checkout per l'ultimo ramo stabile di Mastodon:
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)
Installa le dipendenze bundler e ruby con i seguenti comandi:
gem install bundler bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
Installa le dipendenze node.js con:
yarn install --pure-lockfile
8. Configura mastodonte
I seguenti comandi vengono eseguiti come utente mastodon.
Passare alla directory di installazione di Mastodon ed eseguire il seguente comando per avviare l'installazione:
cd ~/live RAILS_ENV=production bundle exec rake mastodon:setup
Il programma di installazione ti farà diverse domande, genererà un nuovo segreto dell'app, imposterà lo schema del database e compilerà le risorse.
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. Crea unità systemd Mastodon
I seguenti comandi vengono eseguiti come utente root o sudo.
Apri il tuo editor di testo e crea i seguenti file di unità di sistema:
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
Abilita e avvia tutti i servizi:
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. Installa e configura Nginx
Per installare Nginx eseguire il seguente comando:
sudo yum install nginx
Una volta installato nginx, crea un blocco server per il tuo dominio. Non dimenticare di impostare il percorso corretto per il certificato SSL e la chiave privata.
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; }
Salva il file e riavvia il servizio nginx:
sudo systemctl restart nginx
Ora puoi aprire il tuo browser, digitare il tuo dominio e ti verrà presentato il modulo di accesso Mastodon.
Ovviamente, non devi installare Mastodon su CentOS 7, se utilizzi uno dei nostri servizi di hosting gestito, nel qual caso puoi semplicemente chiedere ai nostri esperti amministratori Linux di installare Mastodon per te. Sono disponibili 24 ore su 24, 7 giorni su 7 e si prenderanno immediatamente cura della tua richiesta.
PS . Se ti è piaciuto questo post, su Come installare Mastodon su CentOS 7 per favore condividilo con i tuoi amici sui social network usando i pulsanti a sinistra o semplicemente lascia una risposta qui sotto. Grazie.