Ricerca nel sito web

Come installare Mattermost Team Messaging System su Ubuntu 20.04


Questo tutorial esiste per queste versioni del sistema operativo

  • Ubuntu 22.04 (Jammy Jellyfish)
  • Ubuntu 20.04 (Focal Fossa)

Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa e configura MariaDB
  4. Installa e configura Mattermost
  5. Crea un file di servizio Systemd per Mattermost
  6. Configura Nginx come proxy inverso
  7. Proteggi Mattermost con Lets Encrypt SSL
  8. Accedi all'interfaccia web di Mattermost
  9. Conclusione

Mattermost è un'applicazione di messaggistica open source e self-hosted utilizzata per chat, condivisione di file, ricerca e integrazioni. È un'alternativa alla chat Slack che riunisce tutte le comunicazioni del tuo team in un unico posto. È scritto in React e Golang e utilizza il database PostgreSQL o MySQL nel backend. Offre un ricco set di funzionalità tra cui notifiche push, cronologia di ricerca illimitata, emoji personalizzati, webhook e comandi, directory attiva, supporto per la distribuzione di database multi-nodo, forum, forum di discussione e molti altri.

In questo tutorial, ti mostreremo come installare Mattermost con Nginx e Lets Encrypt SSL su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04.
  • Un nome di dominio valido indicato con l'IP del tuo server.
  • Sul server è configurata una password di root.

Iniziare

Innanzitutto, si consiglia di aggiornare i pacchetti di sistema con l'ultima versione. Puoi aggiornarli eseguendo il seguente comando:

apt-get update -y

Una volta aggiornati tutti i pacchetti, installa le altre dipendenze richieste eseguendo il seguente comando:

apt-get install curl wget vim git unzip gnupg2 -y

Dopo aver installato tutti i pacchetti richiesti, puoi procedere al passaggio successivo.

Installa e configura MariaDB

Mattermost utilizza MySQL/MariaDB come database back-end. Quindi il server MariaDB deve essere installato nel tuo server. Se non è installato, puoi installarlo con il seguente comando:

apt-get install mariadb-server -y

Dopo aver installato il server MariaDB, accedi a MariaDB con il seguente comando:

mysql

Una volta effettuato l'accesso, crea un database e un utente per Mattermost con il seguente comando:

MariaDB [(none)]> CREATE DATABASE mattermostdb;
MariaDB [(none)]> CREATE USER 'mattermost'@'%' IDENTIFIED BY 'password';

Successivamente, concedi tutti i privilegi al Mattermost con il seguente comando:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mattermost'@'%';

Successivamente, svuota i privilegi ed esci dalla shell MariaDB con il seguente comando:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Una volta configurato il database MariaDB, puoi procedere al passaggio successivo.

Installa e configura Mattermost

Innanzitutto, dovrai scaricare l'ultima versione di Mattermost dal suo sito Web ufficiale. Puoi scaricarlo con il seguente comando:

wget https://releases.mattermost.com/5.24.2/mattermost-5.24.2-linux-amd64.tar.gz

Una volta scaricato, estrai il file scaricato con il seguente comando:

tar -xvzf mattermost-5.24.2-linux-amd64.tar.gz

Successivamente, copia la directory estratta in /opt:

cp -r mattermost /opt

Successivamente, crea una directory di dati per Mattermost:

mkdir /opt/mattermost/data

Successivamente, dovrai creare un utente separato per eseguire Mattermost. Puoi crearlo con il seguente comando:

useradd --system --user-group mattermost

Successivamente, modifica la proprietà della directory più importante in più importante e concedi le autorizzazioni appropriate con il seguente comando:

chown -R mattermost:mattermost /opt/mattermost
chmod -R g+w /opt/mattermost

Successivamente, modifica il file di configurazione predefinito di Mattermost e definisci le impostazioni del database e l'URL del sito.

nano /opt/mattermost/config/config.json

Modifica le seguenti righe in base alle tue necessità:

    "SiteURL": "https://mattermost.linuxbuz.com",

    "DriverName": "mysql",
    "DataSource": "mattermost:(localhost:3306)/mattermostdb?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",

Salva e chiudi il file quando hai finito.

Crea un file di servizio Systemd per Mattermost

Successivamente, dovrai creare un file di servizio systemd per gestire il servizio Mattermost. Puoi crearlo con il seguente comando:

nano /lib/systemd/system/mattermost.service

Aggiungi le seguenti righe:

[Unit]
Description=Mattermost
After=network.target
After=mysql.service
Requires=mysql.service

[Service]
Type=notify
User=mattermost
Group=mattermost
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
LimitNOFILE=49152

[Install]
WantedBy=mariadb.service

Salva e chiudi il file, quindi ricarica il demone systemd con il seguente comando:

systemctl daemon-reload

Successivamente, avvia il servizio Mattermost e abilitalo per l'avvio al riavvio del sistema con il seguente comando:

systemctl start mattermost
systemctl enable mattermost

Successivamente, verifica lo stato del servizio Mattermost con il seguente comando:

systemctl status mattermost

Dovresti ottenere il seguente output:

? mattermost.service - Mattermost
     Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-08-01 09:12:52 UTC; 17s ago
   Main PID: 4106 (mattermost)
      Tasks: 20 (limit: 2353)
     Memory: 85.9M
     CGroup: /system.slice/mattermost.service
             ??4106 /opt/mattermost/bin/mattermost
             ??4198 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64

Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.131499,"caller":"mlog/sugar.go:19","msg":"Sent notification of ne>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.1841655,"caller":"jobs/workers.go:73","msg":"Starting workers"}
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.1842792,"caller":"bleveengine/bleve.go:267","msg":"UpdateConf Ble>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.1930475,"caller":"jobs/schedulers.go:74","msg":"Starting schedule>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.20063,"caller":"app/web_hub.go:83","msg":"Starting websocket hubs>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2099638,"caller":"app/license.go:37","msg":"License key from http>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2205582,"caller":"app/server.go:525","msg":"Starting Server..."}
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2208374,"caller":"app/server.go:594","msg":"Server is listening o>
Aug 01 09:12:52 ubunt4 mattermost[4106]: {"level":"info","ts":1596273172.2211802,"caller":"commands/server.go:106","msg":"Sending systemd >
Aug 01 09:12:52 ubunt4 systemd[1]: Started Mattermost.

A questo punto, Mattermost è in esecuzione e in ascolto sulla porta 8065.

Configura Nginx come proxy inverso

Successivamente, dovrai configurare Nginxx come proxy inverso per Mattermost. Innanzitutto, installa il pacchetto Nginx con il seguente comando:

apt-get install nginx -y

Una volta installato, crea un file di configurazione dell'host virtuale Nginx con il seguente comando:

nano /etc/nginx/sites-available/mattermost.conf

Aggiungi le seguenti righe:

upstream mattermost {
   server localhost:8065;
   keepalive 32;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;

server {
   listen 80;
   server_name mattermost.linuxbuz.com;

   location ~ /api/v[0-9]+/(users/)?websocket$ {
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       client_max_body_size 50M;
       proxy_set_header Host $http_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 $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       client_body_timeout 60;
       send_timeout 300;
       lingering_timeout 5;
       proxy_connect_timeout 90;
       proxy_send_timeout 300;
       proxy_read_timeout 90s;
       proxy_pass http://mattermost;
   }

   location / {
       client_max_body_size 50M;
       proxy_set_header Connection "";
       proxy_set_header Host $http_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 $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       proxy_read_timeout 600s;
       proxy_cache mattermost_cache;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 2;
       proxy_cache_use_stale timeout;
       proxy_cache_lock on;
       proxy_http_version 1.1;
       proxy_pass http://mattermost;
   }
}

Salvare e chiudere il file quindi attivare la configurazione dell'host virtuale con il seguente comando:

ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.conf

Quindi, verifica Nginx per eventuali errori di configurazione:

nginx -t

Dovresti ottenere il seguente output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Infine, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Proteggi Mattermost con Lets Encrypt SSL

Innanzitutto, dovrai installare il client Certbot nel tuo sistema per gestire Lets Encrypt SSL. Puoi installarlo con il seguente comando:

apt-get install python3-certbot-nginx -y

Dopo aver installato Certbot, esegui il seguente comando per installare Lets Encrypt SSL per il tuo sito web.

certbot --nginx -d mattermost.linuxbuz.com

Ti verrà chiesto di fornire un indirizzo email valido e di accettare i termini di servizio come mostrato di seguito:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mattermost.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/mattermost.conf

Successivamente, seleziona se reindirizzare o meno il traffico HTTP su HTTPS:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Digita 2 e premi Invio per installare Lets Encrypt SSL sul tuo dominio. Una volta installato, dovresti vedere il seguente output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/mattermost.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://mattermost.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=mattermost.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mattermost.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mattermost.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-10-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Accedi all'interfaccia web di Mattermost

Ora apri il tuo browser web e digita l'URL https://mattermost.linuxbuz.com. Verrai reindirizzato alla schermata di registrazione di Mattermost:

Fornisci il tuo indirizzo email, nome, password e fai clic sul pulsante Crea account. Dovresti vedere la seguente schermata:

Fare clic sul pulsante Crea una squadra. Dovresti vedere la seguente schermata:

Fornisci il nome della tua squadra e fai clic sul pulsante Avanti. Dovresti vedere la seguente schermata:

Fornisci l'URL del tuo team e fai clic sul pulsante Fine. Dovresti vedere la schermata di benvenuto di Mattermost:

Fare clic sul pulsante Salta tutorial. Dovresti vedere la dashboard Mattermost nella seguente schermata:

Conclusione

In questa guida, hai imparato come installare l'applicazione Mattermost Team Messaging sul server Ubuntu 20.04. Hai anche imparato a configurare Nginx come proxy inverso e a proteggerlo con Lets Encrypt SSL. Ora puoi esplorare i servizi Mattermost e collaborare con il tuo team.