Ricerca nel sito web

Come installare Consente di chattare su Ubuntu 22.04


Su questa pagina

  1. Prerequisiti
  2. Installa Node.JS
  3. Installa il database MongoDB
  4. Installa Chatta
  5. Crea un file di servizio Systemd per Chatta
  6. Configura Nginx per Chatta
  7. Accesso all'interfaccia web di Lets Chat
  8. Conclusione

Lets Chat è un'applicazione di messaggistica gratuita, open source e persistente che funziona su Node.js e MongoDB. È progettato per team piccoli e intimi che offrono un ricco set di funzionalità come l'autenticazione LDAP/Kerberos, un'API simile a REST e il supporto XMPP. Usando Lets Chat, puoi inviare tutti i tipi di messaggi e anche trovare chat di gruppi di interesse, adesivi vocali e fantastici emoji.

In questo post, ti mostreremo come installare Chatta con Nginx come proxy inverso su Ubuntu 22.04.

Prerequisiti

  • Un server che esegue Ubuntu 22.04.
  • Sul server è configurata una password di root.

Installa Node.JS

Prima di iniziare, dovrai installare Node.js sul tuo server. Per installare l'ultima versione di Node.js, dovrai aggiungere il repository Node Source ad APT.

Innanzitutto, installa tutte le dipendenze richieste con il seguente comando:

apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common -y

Una volta installate tutte le dipendenze, aggiungi il repository Node.js ad APT

curl -sL https://deb.nodesource.com/setup_18.x | bash -

Una volta aggiunto il repository, puoi installare Node.js con il seguente comando:

apt-get install nodejs -y

Dopo l'installazione corretta, verifica la versione di Node.js con il seguente comando:

node -v

Otterrai il seguente output:

v18.7.0

Installa il database MongoDB

Avrai anche bisogno di un database MongoDB da installare sul tuo server.

Innanzitutto, scarica e installa il pacchetto libssl con il seguente comando:

wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb

Successivamente, aggiungi la chiave GPG MongoDB e il repository utilizzando il seguente comando:

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list

Successivamente, aggiorna la cache del repository con il seguente comando:

apt update

Una volta aggiornato il repository, installa MongoDB utilizzando il seguente comando:

apt install -y mongodb-org

Una volta installato il pacchetto MongoDB, avvia e abilita il servizio MongoDB con il seguente comando:

systemctl start mongod
systemctl enable mongod

Puoi controllare lo stato del servizio MongoDB con il seguente comando:

systemctl status mongod

Dovresti vedere il seguente output:

? mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-07-31 04:00:08 UTC; 6s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 42274 (mongod)
     Memory: 61.1M
        CPU: 1.014s
     CGroup: /system.slice/mongod.service
             ??42274 /usr/bin/mongod --config /etc/mongod.conf

Jul 31 04:00:08 ubuntu2204 systemd[1]: Started MongoDB Database Server.

Installa Chatta

Innanzitutto, dovrai scaricare l'ultima versione di Lets Chat dal repository Git Hub. Puoi scaricarlo con il seguente comando:

git clone https://github.com/sdelements/lets-chat.git

Una volta completato il download, cambia la directory nella directory scaricata e installa tutte le dipendenze richieste usando il seguente comando:

cd lets-chat
npm install

Successivamente, copia il file di configurazione di esempio e avvia il server Lets Chat con il seguente comando:

cp settings.yml.sample settings.yml
npm start

Dovresti vedere il seguente output:

>  start
> node app.js

(node:42373) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/4.x/docs/connections.html#use-mongo-client
(Use `node --trace-deprecation ...` to show where the warning was created)

???     ?????????????????????????     ??????????  ??? ?????? ?????????
???     ?????????????????????????    ???????????  ????????????????????
???     ??????     ???   ????????    ???     ????????????????   ???   
???     ??????     ???   ????????    ???     ????????????????   ???   
????????????????   ???   ????????    ???????????  ??????  ???   ???   
????????????????   ???   ????????     ??????????  ??????  ???   ???

Release 0.4.8

Premi CTRL + C per interrompere il servizio Lets Chat.

Crea un file di servizio Systemd per Chatta

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

nano /etc/systemd/system/letschat.service

Aggiungi le seguenti righe:

[Unit]
Description=Let's Chat Server
Wants=mongodb.service
After=network.target mongod.service

[Service]
Type=simple
WorkingDirectory=/root/lets-chat
ExecStart=/usr/bin/npm start
User=root
Group=root
Restart=always
RestartSec=9

[Install]
WantedBy=multi-user.target

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

systemctl daemon-reload

Successivamente, avvia e abilita il servizio Lets Chat con il seguente comando:

systemctl start letschat
systemctl enable letschat

Successivamente, controlla lo stato di Lets Chat con il seguente comando:

systemctl status letschat

Dovresti vedere il seguente output:

? letschat.service - Let's Chat Server
     Loaded: loaded (/etc/systemd/system/letschat.service; disabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-07-31 04:02:34 UTC; 4s ago
   Main PID: 42429 (npm start)
      Tasks: 23 (limit: 2242)
     Memory: 157.9M
        CPU: 4.457s
     CGroup: /system.slice/letschat.service
             ??42429 "npm start" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??42440 sh /tmp/start-b5e830e4.sh
             ??42441 letschat "" "" ""

Jul 31 04:02:34 ubuntu2204 npm[42429]: > node app.js
Jul 31 04:02:38 ubuntu2204 npm[42441]: (node:42441) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead>
Jul 31 04:02:38 ubuntu2204 npm[42441]: (Use `node --trace-deprecation ...` to show where the warning was created)
Jul 31 04:02:38 ubuntu2204 npm[42441]: ???     ?????????????????????????     ??????????  ??? ?????? ?????????
Jul 31 04:02:38 ubuntu2204 npm[42441]: ???     ?????????????????????????    ???????????  ????????????????????
Jul 31 04:02:38 ubuntu2204 npm[42441]: ???     ??????     ???   ????????    ???     ????????????????   ???
Jul 31 04:02:38 ubuntu2204 npm[42441]: ???     ??????     ???   ????????    ???     ????????????????   ???
Jul 31 04:02:38 ubuntu2204 npm[42441]: ????????????????   ???   ????????    ???????????  ??????  ???   ???
Jul 31 04:02:38 ubuntu2204 npm[42441]: ????????????????   ???   ????????     ??????????  ??????  ???   ???
Jul 31 04:02:38 ubuntu2204 npm[42441]: Release 0.4.8

A questo punto il servizio Lets Chat viene avviato ed è in ascolto sulla porta 5000. Puoi controllare ti con il seguente comando:

ss -antpl | grep 5000

Dovresti vedere il seguente output:

LISTEN 0      511        127.0.0.1:5000       0.0.0.0:*    users:(("letschat",pid=42441,fd=20))     

Configura Nginx per Chatta

Successivamente, dovrai installare e configurare Nginx come proxy inverso per Lets Chat. Quindi puoi accedere a Lets Chat tramite la porta 80.

Innanzitutto, installa il pacchetto del server Nginx con il seguente comando:

apt install nginx -y

Successivamente, crea un file di configurazione dell'host virtuale Nginx:

nano /etc/nginx/conf.d/letschat.conf

Aggiungi le seguenti configurazioni:

server {
server_name letschat.example.com;
listen 80;

access_log /var/log/nginx/lets_chat-access.log;
error_log /var/log/nginx/lets_chat-error.log;

location / {
proxy_set_header   X-Real-IP $remote_addr;
proxy_set_header   Host      $host;
proxy_http_version 1.1;
proxy_set_header   Upgrade $http_upgrade;
proxy_set_header   Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
proxy_pass         http://127.0.0.1:5000;
}

}

Salva e chiudi il file, quindi verifica Nginx per eventuali errori di sintassi:

nginx -t

Dovresti vedere 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 alla configurazione:

systemctl restart nginx

Puoi anche controllare lo stato di Nginx usando il seguente comando:

systemctl status nginx

Dovresti vedere lo stato di Nginx nel 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 Sun 2022-07-31 04:04:23 UTC; 5s ago
       Docs: man:nginx(8)
    Process: 43193 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 43194 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 43195 (nginx)
      Tasks: 2 (limit: 2242)
     Memory: 2.5M
        CPU: 35ms
     CGroup: /system.slice/nginx.service
             ??43195 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??43196 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jul 31 04:04:23 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 31 04:04:23 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.

Accedi Consente di chattare all'interfaccia Web

Ora apri il tuo browser web e accedi all'interfaccia web Lets Chat utilizzando l'URL http://letschat.example.com.

Dovrai fare clic sul pulsante \Ho bisogno di un account per creare un account. Dovresti vedere la seguente pagina:

Fornisci il tuo nome utente, password, indirizzo e-mail e fai clic sul pulsante Registrati. Una volta che ti sei registrato con successo, dovresti ottenere la seguente schermata:

Fare clic sul pulsante OK. Verrai reindirizzato alla schermata di accesso Lets Chat:

Fornisci il nome utente e la password di Lets Chat e fai clic sul pulsante Accedi. Dovresti vedere la dashboard Lets Chat nella seguente schermata:

Conclusione

Congratulazioni! hai installato con successo il server Lets Chat con Nginx come proxy inverso su Ubuntu 22.04. Ora puoi implementare Lets Chat nel tuo ambiente di lavoro e iniziare a comunicare con altri membri del team. Non esitate a chiedermi se avete domande.