Parakushtet
Instalimi i Dependencies
Instalimi dhe konfigurimi i PostgreSQL
Instaloni Ruby
Instaloni Nginx me Let's Encrypt SSL
Vendosja e Shërbimit të Sistemit
konkluzioni
Mastodon është një server i mikroblogimit dhe rrjeteve sociale me burim të hapur. Ai ofron veçori të ngjashme me Twitter; por në vend që të kontrollohet nga një kompani e vetme, ajo është një federatë serverësh të decentralizuar që lidhen së bashku për të krijuar një sistem të tërë rrjetesh sociale. Një ekip i vogël mund të fillojë shembullin e serverit të tij Mastodon për të komunikuar mes tyre, si dhe me përdoruesit e tjerë të komunitetit të federuar. Gjithashtu ju mundëson të zgjidhni politikat tuaja të privatësisë dhe të moderimit dhe të përcaktoni se si komunikoni me përdoruesit e tjerë të serverëve të ndryshëm. Përmbajtja që krijon dhe abonohet një përdorues individual është e vendosur në serverin ku është krijuar llogaria e tij/saj. Përdoruesit mund të ndjekin njëri-tjetrin edhe nëse nuk janë të pritur në të njëjtin server. Çdo përdorues në rrjetin Mastodon ka emrin e tij/saj unik ose ID-në e cila gjendet në@username@domain-name.comformat. Aplikimet e klientëve për Mastodon janë të disponueshme për pothuajse të gjitha platformat.
Parakushtet
Shënim: Ne do të përdorim social.example.comsi emër domaini të përdorur për shembullin Mastodon. Zëvendësoni të gjitha dukuritë social.example.comme emrin tuaj aktual të domenit që dëshironi të përdorni për aplikacionin tuaj Mastodon .
Përditësoni sistemin tuaj bazë duke përdorur udhëzuesin Si të përditësoni CentOS 7 , nëse është e nevojshme. Pasi sistemi juaj të jetë përditësuar, vazhdoni të instaloni varësitë e kërkuara.
Instalimi i varësive
Mastodon kërkon disa varësi për të funksionuar. Instaloni versionin më të fundit të Node.js, i cili do të përdoret për të përpiluar skedarët JavaScript.
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum -y install nodejs
Instalo Yarn, i cili është një aplikacion i shpejtë, i besueshëm dhe i sigurt i menaxherit të varësisë. Ne do të përdorim Yarn për të instaluar varësitë Node.js.
sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
sudo yum -y install yarn
Instaloni Redis. Redis është një aplikacion për ruajtjen e strukturës së të dhënave dhe memorien e memories.
sudo yum -y install redis
Nisni Redis dhe aktivizoni që të fillojë automatikisht në nisje.
sudo systemctl start redis
sudo systemctl enable redis
Instaloni disa varësi të tjera që kërkohen për të ndërtuar Rubyinstalimin dhe varësi të tjera.
sudo yum -y install ImageMagick git libxml2-devel libxslt-devel gcc bzip2 openssl-devel zlib-devel gdbm-devel ncurses-devel autoconf automake bison gcc-c++ libffi-devel libtool patch readline-devel sqlite-devel glibc-headers glibc-devel libyaml-devel libicu-devel libidn-devel
Do t'ju duhet gjithashtu të instaloni mjetet e zhvillimit.
sudo yum -y groupinstall 'Development Tools'
Instalimi dhe konfigurimi i PostgreSQL
PostgreSQL është një sistem bazë të dhënash relacionale objektesh. Do t'ju duhet të shtoni depon e PostgreSQL në sistemin tuaj pasi yumdepoja e paracaktuar përmban një version më të vjetër të aplikacionit.
sudo rpm -Uvh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
Instaloni serverin e bazës së të dhënave PostgreSQL.
sudo yum -y install postgresql96-server postgresql96-contrib postgresql96-devel
Inicializoni bazën e të dhënave.
sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb
Redaktoni pg_hba.confskedarin për të aktivizuar MD5vërtetimin e bazuar.
sudo nano /var/lib/pgsql/9.6/data/pg_hba.conf
Gjeni rreshtat e mëposhtëm dhe ndryshoni peernë trustdhe identnë md5.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
Pasi të përditësohet, konfigurimi duhet të duket kështu.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Nisni serverin PostgreSQL dhe aktivizoni që të fillojë automatikisht në nisje.
sudo systemctl start postgresql-9.6
sudo systemctl enable postgresql-9.6
Ndryshoni fjalëkalimin për përdoruesin e paracaktuar të PostgreSQL.
sudo passwd postgres
Hyni në shell si PostgreSQLpërdorues.
sudo su - postgres
Krijo një PostgreSQLpërdorues të ri për Mastodon.
createuser mastodon
PostgreSQL siguron psqlshell për të ekzekutuar pyetje në bazën e të dhënave. Kaloni në guaskën PostgreSQL duke ekzekutuar.
psql
Vendosni një fjalëkalim për përdoruesin e krijuar rishtazi për bazën e të dhënave Mastodon dhe jepni lejen për të shtuar baza të reja të dhënash.
ALTER USER mastodon WITH ENCRYPTED password 'DBPassword' CREATEDB;
Zëvendësoni DBPasswordme një fjalëkalim të fortë. Dalja nga psqlguaska:
\q
Kalo te sudopërdoruesi.
exit
Instaloni disa varësi të tjera të kërkuara PostgreSQL.
sudo yum -y install libpqxx-devel protobuf-devel
Instaloni Ruby
Krijoni një përdorues të ri për Mastodon dhe kaloni te përdoruesi i krijuar rishtazi.
sudo adduser mastodon -d /opt/mastodon
sudo su - mastodon
Ne do të instalojmë versionin më të fundit të Ruby duke përdorur Ruby Version Manager, ose RVM. Përdoret për të instaluar dhe menaxhuar versione të shumta të Ruby.
Shtoni GPGçelësin e RVM në serverin tuaj.
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Instaloni RVM.
curl -sSL https://get.rvm.io | bash -s stable
source /opt/mastodon/.rvm/scripts/rvm
Tani merrni listën e versioneve të disponueshme të Ruby.
rvm list known
Do të shihni daljen e mëposhtme.
[mastodon@vultr ~]$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
ruby-head
...
Tani instaloni versionin më të fundit të Ruby nga lista.
rvm install 2.4
Përdorni versionin e instaluar të Ruby.
rvm use 2.4
Ju duhet të jeni në gjendje të verifikoni versionin e tij.
ruby -v
Ju duhet të shihni një dalje të ngjashme.
[mastodon@vultr ~]$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
Instalo bundler, i cili është menaxheri i varësisë për aplikacionin Ruby.
gem install bundler
Tani kaloni në drejtorinë kryesore të përdoruesit të Mastodon dhe klononi skedarët e depove të aplikacionit nga Github.
cd ~
git clone https://github.com/tootsuite/mastodon.git app
Move the application directory and checkout the latest releases of the application.
cd ~/app
git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
Configure the bundle to use a custom path for the PostgreSQL configuration. Also, install the Ruby dependencies.
bundle config build.pg --with-pg-config=/usr/pgsql-9.6/bin/pg_config
bundle install --deployment --without development test
Install the Node.js dependencies using Yarn.
yarn install --pure-lockfile
You will need to create a configuration file for the Mastodon application. Copy the sample configuration file.
cd ~/app
cp .env.production.sample .env.production
Before editing the file, generate three different secrets by running the following command three times. You will need to set these secrets in the configuration file.
RAILS_ENV=production bundle exec rake secret
You should get a similar output.
[mastodon@vultr app]$ RAILS_ENV=production bundle exec rake secret
0f17dab1cf4a07f6fac671ecd5815adcb59d012b338dae9350c66402250c6c729dccd6182b1a8f75c4fde55453ce283ea66e07ed4466cdc6d4d6974c98512967
Edit the configuration file using the nano editor.
nano .env.production
Find the following lines and change the values accordingly.
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
Provide the database credentials, according to database user you have created during installation of PostgreSQL. Provide any name for database name as Mastodon will automatically create the database with the name you provide.
DB_HOST=127.0.0.1
DB_USER=mastodon
DB_NAME=mastodon
DB_PASS=DBPassword
DB_PORT=5432
Set the domain name of the application.
LOCAL_DOMAIN=social.example.com
Find the following lines and set its value to the secrets you have generated.
PAPERCLIP_SECRET=
SECRET_KEY_BASE=
OTP_SECRET=
Save the file and exit from the editor.
Now, run the following command to generate Web Push VAPID keys. You will get an error while generating the Web Push VAPID keys if you have not set the secrets in the configuration file mentioned above.
RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key
You should see the following output.
[mastodon@vultr app]$ RAILS_ENV=production bundle exec rake mastodon:webpush:generate_vapid_key
VAPID_PRIVATE_KEY=DCMQdSPkdm-mepsNh4F3suc-UIvsABCvwFd03jSVemM=
VAPID_PUBLIC_KEY=BMMVcVXmqnV0C8S_ybZ7eQH-MXBEX2exqfdPSYQiMMUF2rRxfhoEtVF931i26ebMgmslHB_nvVadOdcBPhaFEjw=
Open the configuration file again and set the generated keys in their respective lines.
VAPID_PRIVATE_KEY=
VAPID_PUBLIC_KEY=
Finally, provide the information of your SMTP mail server so that the application can send emails to users. It is important that you use a working SMTP server as, upon new registration, users will be sent an email with an activation link. New users will have to click on the activation link to activate their account.
SMTP_SERVER=mail.example.com
SMTP_PORT=456
SMTP_LOGIN=mail@example.com
SMTP_PASSWORD=MailPassword
SMTP_FROM_ADDRESS=notifications@example.com
SMTP_TLS=true
Once done, save the file and exit from the editor. You have done the basic configuration of Mastodon instance.
Setup the PostgreSQL database for the first time.
RAILS_ENV=production bundle exec rails db:setup
First, the above command will create a new database with the name mentioned in the configuration. Then, it will write the database according to the configuration.
Precompile all CSS and JavaScript files to create the cache.
RAILS_ENV=production bundle exec rails assets:precompile
Mastodon is now installed on your server. Now you will need to setup an Nginx web server to serve the application and setup Systemd services to run the Mastodon services.
From now on, we will need to execute the commands using the sudo user.
Install Nginx with Let's Encrypt SSL
We will use the Nginx web server as a reverse proxy to serve the application to the users. We will also obtain and install SSL certificates from Let's Encrypt.
Install Nginx and Certbot. Certbot is the official certificates issuing client for Let's Encrypt CA.
sudo yum -y install nginx certbot
Adjust your firewall setting to allow the standard HTTP and HTTPS ports through the firewall as Certbot needs to make an HTTP connection for verifying the domain authority.
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Note: To obtain certificates from Let's Encrypt CA, you must ensure that the domain for which you wish to generate the certificates is pointed towards the server. If not, then make the necessary changes to the DNS records of your domain and wait for the DNS to propagate before making the certificate request again. Certbot checks the domain authority before providing the certificates.
Now use the builtin web server in Certbot to generate the certificates for your domain.
sudo certbot certonly --standalone -d social.example.com
The generated certificates are likely to be stored in the /etc/letsencrypt/live/social.example.com/ directory. The SSL certificate will be retained as fullchain.pem and the private key will be saved as privkey.pem.
Let's Encrypt certificates expire in 90 days, so it is recommended to set up auto renewal for the certificates using Cron jobs. Cron is a system service which is used to run periodic tasks.
Open the cron job file.
sudo crontab -e
Add the following line.
0 0 * * * /usr/bin/certbot renew --quiet
The above cron job will run daily at midnight. If the certificate is due for expiry, it will automatically renew the certificates.
Now create a new Nginx server block for the Mastodon site.
sudo nano /etc/nginx/conf.d/mastodon.conf
Populate the file with this.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
listen [::]:80;
server_name social.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name social.example.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/letsencrypt/live/social.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/social.example.com/privkey.pem;
keepalive_timeout 70;
sendfile on;
client_max_body_size 0;
root /opt/mastodon/app/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 @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;
}
Be sure to change the domain name and the path to the SSL certificates.
Now you can start the Nginx web server and enable it to start at boot automatically.
sudo systemctl start nginx
sudo systemctl enable nginx
You will also be required to allow port 4000 through the firewall as the port will be providing the streaming API service.
sudo firewall-cmd --permanent --zone=public --add-port=4000/tcp
sudo firewall-cmd --reload
Provide the execution permissions for the Mastodon directory.
sudo chmod +x /opt/mastodon
Setting Up Systemd Service
Ju do të duhet të filloni tre procese të ndryshme për të nisur me sukses serverin Mastodon. Përdorimi i shërbimit Systemd do të sigurojë që serveri Mastodon të fillojë automatikisht në nisje dhe të përpunojë dështimet.
Krijo një shërbim të ri systemd për të ekzekutuar shërbimin në internet Mastodon. Ky shërbim do të nisë ueb serverin e integruar në port 3000.
sudo nano /etc/systemd/system/mastodon-web.service
Plotësoni skedarin me përmbajtjen e mëposhtme.
[Unit]
Description=Mastodon Web Service
After=network.target
[Service]
Type=simple
User=mastodon
Group=mastodon
WorkingDirectory=/opt/mastodon/app
Environment="RAILS_ENV=production"
Environment="PORT=3000"
ExecStart=/bin/bash -lc 'bundle exec puma -C config/puma.rb'
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
Krijoni shërbimin e dytë Systemd për të ekzekutuar shërbimin e radhës së sfondit Mastodon. Shërbimi i radhës Mastodon kujdeset për të gjitha detyrat e sfondit.
sudo nano /etc/systemd/system/mastodon-queue.service
Plotësoni skedarin me përmbajtjen e mëposhtme.
[Unit]
Description=Mastodon Queue Service
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/opt/mastodon/app
Environment="RAILS_ENV=production"
Environment="DB_POOL=5"
ExecStart=/bin/bash -lc 'bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push'
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
Më në fund, krijoni skedarin e fundit të shërbimit për shërbimin Mastodon streaming API.
sudo nano /etc/systemd/system/mastodon-api.service
Plotësoni skedarin me përmbajtjen e mëposhtme.
[Unit]
Description=Mastodon Streaming
After=network.target
[Service]
Type=simple
User=mastodon
WorkingDirectory=/opt/mastodon/app
Environment="NODE_ENV=production"
Environment="PORT=4000"
ExecStart=/bin/npm run start
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
Aktivizo shërbimet Mastodon të fillojnë automatikisht në kohën e nisjes.
sudo systemctl enable mastodon-web mastodon-queue mastodon-api
Për të nisur shërbimet Mastodon, mund ta ekzekutoni këtë.
sudo systemctl start mastodon-web mastodon-queue mastodon-api
Për të kontrolluar statusin e shërbimeve, mund ta ekzekutoni këtë.
sudo systemctl status mastodon-web mastodon-queue mastodon-api
konkluzioni
Tani mund të përdorni aplikacionin Mastodon duke shkuar te https://social.example.com. Krijoni një llogari të re përdoruesi në serverin tuaj dhe verifikoni llogarinë e përdoruesit duke hapur lidhjen e dërguar në email. Për të siguruar privilegje administratori në llogarinë që sapo keni krijuar, ekzekutoni këtë.
sudo su - mastodon && cd ~/app
RAILS_ENV=production bundle exec rails mastodon:make_admin USERNAME=<user_name>
Zëvendësojeni <user_name>me emrin aktual të përdoruesit që keni përdorur për të krijuar llogarinë në ndërfaqen Mastodon.
Shembulli juaj Mastodon tani është instaluar dhe konfiguruar për të ekzekutuar. Filloni duke ftuar miqtë tuaj të bashkohen me shembullin tuaj dhe të eksplorojnë veçoritë e ofruara nga Mastodon. Ju mund të përdorni faqen tuaj të rrjeteve sociale në celular duke shkarkuar ndonjë nga aplikacionet e disponueshme për platforma të ndryshme.