Ricerca nel sito web

Come installare Matrix Synapse Chat Server su Ubuntu 22.04


Questo tutorial esiste per queste versioni del sistema operativo

  • Ubuntu 22.04 (Jammy Jellyfish)
  • Ubuntu 18.04 (Bionic Beaver)

Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa Matrix Synapse su Ubuntu 22.04
  4. Configura Matrix Synapse
  5. Configura Nginx come proxy inverso per Matrix Synapse
  6. Crea un account Super User
  7. Proteggi Matrix Synapse con Lets Encrypt
  8. Accedi a Matrix Synapse
  9. Conclusione

Matrix è una soluzione gratuita, open source e basata sul Web utilizzata per i servizi di messaggistica e VoIP. Si tratta di un protocollo VOIP standard aperto che consente di comunicare con altri utenti su un diverso fornitore di servizi tramite voice-over-IP e chat. Fornisce API JSON HTTP RESTful per la creazione di server di chat distribuiti e federati senza un singolo punto di controllo e errore e fornisce tutti i riferimenti per le API. È scritto in Python e ti consente di creare il tuo server di casa e archiviare tutte le informazioni personali dell'utente e la cronologia della chat.

In questo post, ti mostreremo come installare Matrix Synapse su Ubuntu 22.04.

Prerequisiti

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

Iniziare

Innanzitutto, dovrai aggiornare i tuoi pacchetti di sistema alla versione aggiornata. Puoi farlo con il seguente comando:

apt update -y

Una volta aggiornati tutti gli indici dei pacchetti, installa le altre dipendenze richieste utilizzando il seguente comando:

apt install curl wget gnupg2 apt-transport-https -y

Una volta installate tutte le dipendenze, puoi procedere al passaggio successivo.

Installa Matrix Synapse su Ubuntu 22.04

Per impostazione predefinita, i pacchetti Matrix Synapse non sono inclusi nel repository predefinito di Ubuntu 22.04. Quindi dovrai aggiungere il repository ufficiale Matrix Synapse ad APT.

Innanzitutto, scarica e aggiungi la chiave GPG Matrix Synapse con il seguente comando:

wget -qO /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg

Quindi, aggiungi il repository Matrix Synapse ad APT usando il seguente comando:

echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/matrix-org.list

Successivamente, aggiorna il repository e installa il pacchetto Matrix Synapse utilizzando il seguente comando:

apt-get update -y
apt-get install matrix-synapse-py3 -y

Durante l'installazione, ti verrà chiesto di definire il tuo nome di dominio come mostrato di seguito:

Fornisci il tuo nome di dominio e premi il tasto Invio. Ti verrà chiesto di segnalare statistiche anonime:

Selezionare Sì e premere il tasto Invio per continuare.

Una volta completata l'installazione, avviare il servizio Matrix e abilitarlo all'avvio al riavvio del sistema utilizzando il comando indicato di seguito:

systemctl start matrix-synapse
systemctl enable matrix-synapse

Puoi anche controllare lo stato di Matrix Synapse con il seguente comando:

systemctl status matrix-synapse

Otterrai il seguente output:

? matrix-synapse.service - Synapse Matrix homeserver
     Loaded: loaded (/lib/systemd/system/matrix-synapse.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-06-04 08:01:22 UTC; 3s ago
    Process: 1916 ExecStartPre=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.ya>
   Main PID: 1923 (python)
      Tasks: 8 (limit: 9460)
     Memory: 78.6M
        CPU: 4.911s
     CGroup: /system.slice/matrix-synapse.service
             ??1923 /opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config>

Jun 04 08:01:17 ubuntu2204 systemd[1]: Starting Synapse Matrix homeserver...
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: This server is configured to use 'matrix.org' as its trusted key server via the
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: 'trusted_key_servers' config option. 'matrix.org' is a good choice for a key
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: server since it is long-lived, stable and trusted. However, some admins may
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: wish to use another server for this purpose.
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: To suppress this warning and continue using 'matrix.org', admins should set
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: 'suppress_key_server_warning' to 'true' in homeserver.yaml.
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: --------------------------------------------------------------------------------
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: Config is missing macaroon_secret_key

A questo punto il servizio Matrix Synapse viene avviato ed è in ascolto sulla porta 8008. Puoi verificarlo con il seguente comando:

ss -antpl | grep python

Otterrai il seguente output:

LISTEN 0      50         127.0.0.1:8008      0.0.0.0:*    users:(("python",pid=1950,fd=12))        
LISTEN 0      50             [::1]:8008         [::]:*    users:(("python",pid=1950,fd=11))   

Configura Matrix Synapse

Dopo aver installato Matrix Synapse, dovrai configurarlo. Innanzitutto, crea un segreto usando il seguente comando:

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

Otterrai il seguente output:

R3jvgiDYyhh5XgduDPsgtwxPDiar8q2s

Successivamente, modifica il file di configurazione predefinito di Matrix Synapse:

nano /etc/matrix-synapse/homeserver.yaml

Definisci il tuo bind-address, disabilita la registrazione e definisci i tuoi segreti come mostrato di seguito:

    bind_addresses: ['127.0.0.1']
    enable_registration: false
    registration_shared_secret: "R3jvgiDYyhh5XgduDPsgtwxPDiar8q2s"

Salva e chiudi il file, quindi riavvia il servizio Matrix Synapse per applicare le modifiche:

systemctl restart matrix-synapse

Configura Nginx come proxy inverso per Matrix Synapse

È una buona idea configurare Nginx come proxy inverso per Matix Synapse. Innanzitutto, installa il pacchetto del server Web Nginx con il seguente comando:

apt-get install nginx -y

Una volta installato Nginx, crea un file di configurazione dell'host virtuale Nginx:

nano /etc/nginx/conf.d/matrix.conf

Aggiungi la seguente configurazione:

server {
listen 80;
server_name matrix.linuxbuz.com;
location / {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
}

Salva e chiudi il file per verificare la configurazione di Nginx utilizzando il seguente comando:

nginx -t

Otterrai il seguente output:

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

Successivamente, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Puoi anche controllare lo stato del servizio Nginx usando il seguente comando:

systemctl status nginx

Dovresti vedere il seguente output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-06-04 08:06:22 UTC; 26s ago
       Docs: man:nginx(8)
    Process: 2433 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 2434 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 2436 (nginx)
      Tasks: 5 (limit: 9460)
     Memory: 4.8M
        CPU: 58ms
     CGroup: /system.slice/nginx.service
             ??2436 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??2437 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??2438 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??2439 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??2440 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jun 04 08:06:22 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 04 08:06:22 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.

Crea un account Super User

Successivamente, dovrai creare un account utente amministratore e impostare una password per accedere a Matrix Synapse.

register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml http://localhost:8008

Fornisci il tuo account utente amministratore e imposta una password come mostrato di seguito:

New user localpart [root]: matrixadmin
Password: 
Confirm password: 
Make admin [no]: yes
Sending registration request...
Success!

Proteggi Matrix Synapse con Lets Encrypt

Si consiglia inoltre di proteggere Matrix Synapse con Lets Encrypt SSL. Innanzitutto, installa il pacchetto client Certbot con il seguente comando:

apt-get install certbot python3-certbot-nginx -y

Una volta installato il pacchetto Certbot, eseguire il seguente comando per installare Lets Encrypt SSL:

certbot

Ti verrà chiesto di fornire il tuo indirizzo email e di accettare i termini di servizio:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
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. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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
Account registered.

Ti verrà chiesto di selezionare il sito Web su cui desideri installare SSL:

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: matrix.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1

Digita 1 e premi il tasto Invio per installare Lets Encrypt SSL sul tuo sito web.

Requesting a certificate for matrix.linuxbuz.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/matrix.linuxbuz.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/matrix.linuxbuz.com/privkey.pem
This certificate expires on 2022-09-02.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for matrix.linuxbuz.com to /etc/nginx/conf.d/matrix.conf
Congratulations! You have successfully enabled HTTPS on https://matrix.linuxbuz.com
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.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Accedi a Matrix Synapse

Ora puoi verificare l'installazione di Matrix Synapse utilizzando l'URL https://matrix.linuxbuz.com sul tuo browser web. Dovresti vedere la seguente schermata:

Puoi anche verificare la tua Matrix Synapse utilizzando il client Web di Riot https://riot.im/app/#/login. Dovresti vedere la seguente schermata:

Fare clic sul pulsante Modifica. Dovresti vedere la seguente schermata:

Fornisci l'URL del tuo server Matrix e fai clic sul pulsante Continua. Dovresti vedere la pagina di accesso a Matrix:

Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante Accedi. Una volta connesso al server Matrix Synapse. Dovresti vedere la seguente schermata:

Conclusione

In questo post, hai imparato come installare Matrix Synapse con Nginx come proxy inverso sul server Ubuntu 22.04. Verifichi anche Matrix Synapse utilizzando il client basato sul Web di Riot. Ora puoi creare il tuo server VOIP utilizzando Matrix Synapse.