Installa Graylog 4 su Ubuntu 22.04|20.04 con Let's Encrypt
Graylog è uno strumento di aggregazione e gestione dei log open source che può essere utilizzato per archiviare, analizzare e inviare avvisi dai log raccolti. Graylog può essere utilizzato per analizzare log sia strutturati che non strutturati utilizzando ElasticSearch e MongoDB. Ciò include una varietà di sistemi tra cui sistemi Windows, sistemi Linux, diverse applicazioni e microservizi ecc.
Graylog semplifica l'analisi e il monitoraggio di questi sistemi e applicazioni da un singolo host.
Graylog ha i seguenti componenti:
- Server Graylog
- MongoDB
- Ricerca elastica
Passiamo rapidamente all'installazione del server Graylog su un host Ubuntu 22.04|20.04. Configureremo quindi SSL utilizzando Let'sEncrypt.
Per raggiungere questo obiettivo, dovremo installare Nginx che fungerà da proxy inverso sul nostro sistema.
Articoli simili: Come inoltrare i log a Grafana Loki utilizzando Promtail
Prerequisiti di installazione
Prima di poterlo installare sul tuo box, assicurati che il tuo host soddisfi i requisiti minimi riportati di seguito:
- 4 core della CPU
- 8 GB di RAM
- Spazio su disco rigido SSD con IOPS elevati per l'archiviazione dei log Elasticsearch
- Ubuntu 22.04|20.04 LTS installato e aggiornato.
- Tutti i pacchetti aggiornati
Soddisfatte le condizioni di cui sopra, iniziamo il processo di installazione.
Passaggio 1: installa Java su Ubuntu 22.04 | 20.04
Prima dell'installazione di Java, aggiorniamo e aggiorniamo il nostro sistema.
sudo apt update && sudo apt -y full-upgrade
Ti consigliamo vivamente di eseguire un riavvio del sistema dopo l'aggiornamento:
[ -f /var/run/reboot-required ] && sudo reboot -f
Per l'installazione di Graylog è richiesta Java versione 8 e successive. In questo post utilizzeremo il JDK 11 aperto
sudo apt update
sudo apt install vim apt-transport-https openjdk-11-jre-headless uuid-runtime pwgen curl dirmngr
Puoi verificare la versione Java che hai appena installato utilizzando il comando java -version
:
$ java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)
Passaggio 2: installa Elasticsearch su Ubuntu 22.04 | 20.04
La ricerca elastica è lo strumento utilizzato per archiviare e analizzare i log in entrata da origini esterne. Utilizza l'API RESTful basata sul web.
Scarica e installa la chiave di firma GPG Elasticsearch.
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/elastic.gpg
Aggiungi il repository Elasticsearch all'elenco delle fonti:
echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
Installa Elasticsearch:
sudo apt update
sudo apt install elasticsearch-oss -y
Configura il nome del cluster per Graylog.
sudo vim /etc/elasticsearch/elasticsearch.yml
Modifica il nome del cluster in graylog
cluster.name: graylog
Aggiungi le seguenti informazioni nello stesso file
action.auto_create_index: false
Ricaricare il demone per avviare il servizio Elasticsearch.
sudo systemctl daemon-reload
sudo systemctl restart elasticsearch
sudo systemctl enable elasticsearch
Puoi verificare lo stato del servizio tramite:
$ systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-11-08 12:36:10 UTC; 14s ago
Docs: http://www.elastic.co
Main PID: 1352139 (java)
Tasks: 15 (limit: 4582)
Memory: 1.1G
CGroup: /system.slice/elasticsearch.service
└─1352139 /bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.>
Nov 08 12:36:10 graylog.computingforgeeks.com systemd[1]: Started Elasticsearch.
Elasticsearch funziona sulla porta 9200 e questa può essere viralizzata con il comando curl
:
curl -X GET http://localhost:9200
Dovresti vedere il nome del tuo cluster nell'output.
$ curl -X GET http://localhost:9200
{
"name" : "ubuntu",
"cluster_name" : "graylog",
"cluster_uuid" : "RsPmdLmDQUmNGKC-E4JPmQ",
"version" : {
"number" : "7.10.2",
"build_flavor" : "oss",
"build_type" : "deb",
"build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
"build_date" : "2021-01-13T00:42:12.435326Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
Passaggio 3: installare MongoDB su Ubuntu 22.04|20.04
Inizia importando la chiave GPG MongoDB 6.0 sul tuo sistema:
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-6.gpg
Aggiungi il repository MongoDB 6.0 sul sistema:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
Scarica e installa mongoDB dal repository di base di Ubuntu.
sudo apt update && sudo apt install mongodb-org -y
Avvia MongoDB
sudo systemctl start mongod
sudo systemctl enable mongod
$ systemctl status mongod
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-11-08 12:45:21 UTC; 1s ago
Docs: man:mongod(1)
Main PID: 1352931 (mongod)
Tasks: 3 (limit: 4582)
Memory: 27.9M
CGroup: /system.slice/mongodb.service
└─1352931 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf
Nov 08 12:45:21 graylog.computingforgeeks.com systemd[1]: Started An object/document-oriented database.
Passaggio 4: installare Graylog Server su Ubuntu 22.04|20.04
Scarica e configura il repository Graylog.
wget https://packages.graylog2.org/repo/packages/graylog-5.0-repository_latest.deb
sudo dpkg -i graylog-5.0-repository_latest.deb
Installa il server Graylog:
sudo apt update
sudo apt install graylog-server
Genera un segreto per proteggere le password degli utenti utilizzando il comando pwgen
pwgen -N 1 -s 96
L'output dovrebbe essere simile a:
FFP3LhcsuSTMgfRvOx0JPcpDomJtrxovlSrbfMBG19owc13T8PZbYnH0nxyIfrTb0ANwCfH98uC8LPKFb6ZEAi55CvuZ2Aum
Modifica il file di configurazione di Graylog per aggiungere il segreto che abbiamo appena creato:
sudo vim /etc/graylog/server/server.conf
Individua la riga password_secret =
e aggiungi dopo di essa il segreto creato sopra.
password_secret = FFP3LhcsuSTMgfRvOx0JPcpDomJtrxovlSrbfMBG19owc13T8PZbYnH0nxyIfrTb0ANwCfH98uC8LPKFb6ZEAi55CvuZ2Aum
Se desideri che Graylog si interfaccia con l'indirizzo IP e la porta del server, imposta http_bind_address
sul nome host pubblico o su un indirizzo IP pubblico della macchina a cui puoi connetterti.
$ sudo vim /etc/graylog/server/server.conf
http_bind_address = 0.0.0.0:9000
Il passaggio successivo è creare una password hash sha256 per l'amministratore. Questa è la password necessaria per accedere all'interfaccia web.
$ echo -n "Enter Password: " && head -1 </dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1
Enter Password: password
Otterrai un output di questo tipo:
e3c652f0ba0b4801205814f8b6bc49672c4c74e25b497770bb89b22cdeb4e951
Modifica il file /etc/graylog/server/server.conf
quindi inserisci la password hash in root_password_sha2 =
$ sudo vim /etc/graylog/server/server.conf
root_password_sha2 = e3c652f0ba0b4801205814f8b6bc49672c4c74e25b497770bb89b22cdeb4e951
Graylog è ora configurato e pronto per l'uso.
Avvia il servizio Graylog:
sudo systemctl daemon-reload
sudo systemctl restart mongodb graylog-server
sudo systemctl enable mongodb graylog-server
Puoi verificare se il servizio è stato avviato correttamente dai log:
sudo tail -f /var/log/graylog-server/server.log
Produzione :
2020-11-08T13:37:55.067Z INFO [ServerBootstrap] Graylog server up and running.
È quindi possibile accedere alla dashboard web di Graylog su:
http://<serverip_hostname>:9000
Passaggio 5: configura Nginx con Let's Encrypt per GrayLog
Il prossimo passo è configurare SSL in modo da poter accedere all'interfaccia web di Graylog tramite HTTPS.
Per raggiungere questo obiettivo, avremo bisogno di quanto segue:
- Nome di dominio completo (FQDN)
- Nginx
- Crittografiamo il certificato
Segui i passaggi nella guida seguente:
- Configura il proxy Graylog Nginx con Let's Encrypt SSL
I passaggi sono forniti di seguito per una facile consultazione.
- aggiorna il sistema e installa nginx
sudo apt update
sudo apt install nginx
2. Configurare il firewall
sudo ufw allow 'Nginx Full'
3. Crea virtualhost con il tuo nome di dominio
Crea un file in /etc/nginx/sites-available/
ad es
sudo vim /etc/nginx/sites-available/graylog.conf
Aggiungere quanto segue nel file:
server {
listen 80;
server_name graylog.yourdomain.com;
return 301 https://$host$request_uri;
access_log /var/log/nginx/graylog.yourdomain.com.access.log combined;
error_log /var/log/nginx/graylog.yourdomain.com.error.log;
}
Ricordati di sostituire graylog.tuodominio.com con il tuo FQDN.
4. Crea un collegamento simbolico del file appena creato in /etc/nginx/sites-available
a /etc/nginx/sites-enabled
sudo ln -s /etc/nginx/sites-available/graylog.conf /etc/nginx/sites-enabled/
5. Controlla se la configurazione di nginx è corretta eseguendo il comando nginx -t
.
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
6. Installa Let'sEncrypt con certbot.
sudo apt install certbot python3-certbot-nginx
7. Esegui certbot per nginx
$ sudo certbot --nginx
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): [email
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: N
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: graylog.computingforgeeks.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
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for graylog.computingforgeeks.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/graylog.computingforgeeks.com.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/graylog.computingforgeeks.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://graylog.computingforgeeks.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=graylog.computingforgeeks.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/graylog.computingforgeeks.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/graylog.computingforgeeks.com/privkey.pem
Your cert will expire on 2021-02-06. 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
Hai ottenuto con successo SSL per il nostro dominio.
Il passaggio successivo è configurare il proxy inverso su Nginx che verrà utilizzato per servire Graylog che è in esecuzione sullo stesso host sulla porta 9000.
Modifica il file /etc/nginx/sites-available/graylog.conf
:
sudo vim /etc/nginx/sites-available/graylog.conf
E aggiungi la seguente configurazione nella sezione Posizione
.
location /
{
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Graylog-Server-URL https://$server_name/;
proxy_pass http://127.0.0.1:9000;
}
Il file di configurazione finale dovrebbe essere simile a:
server {
listen 80;
server_name graylog.example.com;
return 301 https://$host$request_uri;
access_log /var/log/nginx/graylog_access.log combined;
error_log /var/log/nginx/graylog_error.log;
}
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name graylog.example.com;
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/graylog.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/graylog.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location /
{
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Graylog-Server-URL https://$server_name/;
proxy_pass http://127.0.0.1:9000;
}
}
Verifica la tua configurazione nginx utilizzando nginx -t
solo per assicurarti che la tua configurazione nginx sia corretta.
Ora riavvia il servizio nginx.
sudo systemctl restart nginx
Con quanto sopra attivo e funzionante, dovresti essere in grado di accedere alla dashboard di Graylog inserendo https://graylog.yourdomain.com
.
Ricordati di sostituire graylog.tuodominio.com
con il tuo FQDN.
Il nome utente predefinito per Graylog è admin e la password che abbiamo configurato nel passaggio 4 (Installazione del server Graylog) sopra. Nel mio caso, questo sarebbe “Str0ngPassw0rd”
Ora puoi iniziare a utilizzare la dashboard web Graylog configurata con SSL.
Conclusione
Abbiamo installato con successo il server Graylog, configurato SSL tramite Nginx come proxy inverso e siamo riusciti ad accedere all'interfaccia web.
La configurazione di SSL sul server Graylog è importante per proteggere il tuo sistema.
Se dovessi affrontare qualsiasi problema durante il processo di installazione, sentiti libero di commentare o porre qualsiasi domanda nella sezione commenti.
- Configura il proxy inverso Graylog Nginx con Letsencrypt SSL