Come installare Graylog 4 su Ubuntu 22.04
Questo tutorial esiste per queste versioni del sistema operativo
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
Su questa pagina
- Prerequisiti
- Per iniziare
- Installa Java JDK
- Installa e configura Elasticsearch
- Installa il server MongoDB
- Installa e configura Graylog
- Configura Nginx come proxy inverso per Graylog
- Accedi all'interfaccia web di Graylog
- Conclusione
Graylog è uno strumento di monitoraggio dei log gratuito e open source utilizzato per acquisire, archiviare e consentire l'analisi in tempo reale di terabyte di dati macchina. È progettato per l'analisi dei log moderna che consente agli utenti di trovare rapidamente e facilmente il significato nei dati e agire più rapidamente. Fornisce inoltre avvisi e sistemi di ricerca della cronologia dei log utilizzando ElasticSearch come database di indice principale e MongoDB per l'archiviazione di meta informazioni. Ti aiuta a monitorare, cercare e analizzare una grande quantità di dati in un formato semplice e leggibile.
In questo tutorial, ti mostreremo come installare Graylog sul server Ubuntu 22.04.
Prerequisiti
- Un server che esegue Ubuntu 22.04 con un minimo di 4 GB di RAM
- Sul server è configurata una password di root.
Iniziare
Innanzitutto, dovrai aggiornare i tuoi pacchetti di sistema all'ultima versione. Puoi aggiornarli tutti con il seguente comando:
apt update -y
apt upgrade
Dopo aver aggiornato tutti i pacchetti, dovrai anche installare alcune dipendenze sul tuo server. Puoi installarli tutti con il seguente comando:
apt install apt-transport-https gnupg2 uuid-runtime pwgen curl dirmngr -y
Una volta installate tutte le dipendenze richieste, puoi procedere al passaggio successivo.
Installa Java JDK
Graylog richiede che Java sia installato sul tuo server. Se non è installato, puoi installarlo con il seguente comando:
apt install openjdk-11-jre-headless -y
Una volta installato Java, puoi verificare la versione installata di Java eseguendo il seguente comando:
java -version
Dovresti ottenere il seguente output:
openjdk version "11.0.16" 2022-07-19 OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04) OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)
Una volta terminato, puoi procedere al passaggio successivo.
Installa e configura Elasticsearch
Graylog utilizza Elasticsearch per archiviare i log provenienti da risorse esterne. Quindi dovrai installare Elasticsearch nel tuo sistema.
Per impostazione predefinita, il pacchetto Elasticsearch non è disponibile nel repository predefinito di Ubuntu. Quindi dovrai aggiungere il repository Elasticsearch al tuo sistema.
Innanzitutto, scarica e aggiungi la chiave GPG Elasticsearch con il seguente comando:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
Successivamente, aggiungi il repository Elasticsearch con il seguente comando:
echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
Successivamente, aggiorna il repository e installa Elasticsearch con il seguente comando:
apt update -y
apt install elasticsearch-oss -y
Dopo aver installato Elasticsearch, dovrai modificare il file di configurazione di Elasticsearch e definire il nome del cluster. Puoi farlo con il seguente comando:
nano /etc/elasticsearch/elasticsearch.yml
Definisci il nome del tuo cluster in Graylog e aggiungi un'altra riga come mostrato di seguito:
cluster.name: graylog action.auto_create_index: false
Salva e chiudi il file quando hai finito. Quindi, avvia il servizio Elasticsearch e abilitalo per l'avvio all'avvio con il seguente comando:
systemctl daemon-reload
systemctl start elasticsearch
systemctl enable elasticsearch
Puoi anche verificare lo stato del servizio Elasticsearch con il seguente comando:
systemctl status elasticsearch
Dovresti ottenere il seguente output:
? elasticsearch.service - Elasticsearch Loaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled) Active: active (running) since Sun 2022-09-25 07:05:27 UTC; 21s ago Docs: https://www.elastic.co Main PID: 74226 (java) Tasks: 48 (limit: 4579) Memory: 1.2G CPU: 22.739s CGroup: /system.slice/elasticsearch.service ??74226 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.t> Sep 25 07:05:11 ubuntu2204 systemd[1]: Starting Elasticsearch... Sep 25 07:05:27 ubuntu2204 systemd[1]: Started Elasticsearch.
Ora, verifica la risposta Elasticcsearch con il seguente comando:
curl -X GET http://localhost:9200
Dovresti ottenere il seguente output:
{ "name" : "ubuntu2204", "cluster_name" : "graylog", "cluster_uuid" : "6IWBEBx_THa2Gzqb7a1LTQ", "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" }
Installa il server MongoDB
Graylog utilizza MongoDB come database. Quindi dovrai installare il database MongoDB sul tuo server. Per impostazione predefinita, il pacchetto MongoDB non è incluso nel repository predefinito di Ubuntu. Quindi dovrai aggiungere il repository ufficiale MongoDB al tuo sistema:
Puoi aggiungerlo con 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
Una volta aggiunto il repository, aggiorna la cache del repository e installa Graylog con il seguente comando:
apt update -y
apt install -y mongodb-org
Una volta installato MongoDB, avvia il servizio MongoDB e abilitalo per l'avvio al riavvio del sistema con il seguente comando:
systemctl enable --now mongod
Puoi anche controllare lo stato di MongoDB con il seguente comando:
systemctl status mongod
Dovresti vedere lo stato di MongoDB nel seguente output:
? mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2022-09-25 07:20:35 UTC; 8s ago Docs: https://docs.mongodb.org/manual Main PID: 77018 (mongod) Memory: 60.0M CPU: 936ms CGroup: /system.slice/mongod.service ??77018 /usr/bin/mongod --config /etc/mongod.conf Sep 25 07:20:35 ubuntu2204 systemd[1]: Started MongoDB Database Server.
Una volta terminato, puoi procedere al passaggio successivo.
Installa e configura Graylog
Per impostazione predefinita, il pacchetto Graylog non è disponibile nel repository predefinito di Ubuntu. Quindi dovrai installare il repository Graylog sul tuo server.
Puoi scaricare il pacchetto del repository Graylog con il seguente comando:
wget https://packages.graylog2.org/repo/packages/graylog-4.3-repository_latest.deb
Una volta completato il download, installa il pacchetto scaricato con il seguente comando:
dpkg -i graylog-4.3-repository_latest.deb
Successivamente, aggiorna il repository e installa il server Graylog con il seguente comando:
apt update -y
apt install graylog-server -y
Dopo aver installato il server Graylog, sarà necessario generare un segreto per proteggere le password degli utenti. Puoi generarlo con il seguente comando:
pwgen -N 1 -s 96
Dovresti vedere il seguente output:
d1fDH1NEOMgb3nxbFYY3eVpqzjOprwgPgFuGh2F0flDdZglJP2CxENV4WEeW8iqZXsjDEZgMob3oBvQYm62RXxoc33hKTPJa
Successivamente, dovrai anche generare una password sicura per l'utente amministratore di Graylog. Avrai bisogno di questa password per accedere all'interfaccia web di Graylog. Puoi generarlo con il seguente comando:
echo -n "Enter Password: " && head -1
Dovresti vedere il seguente output:
Enter Password: yourpassword e472e1436cbe87774c1bc75d0a646d67e506bea1dff8701fd41f34bca33e1419
Ora modifica il file di configurazione principale di Graylog e definisci entrambe le password:
nano /etc/graylog/server/server.conf
Incolla entrambe le password che hai generato sopra, come mostrato di seguito:
password_secret = Wv4VQWCAA9sRbL7pxPeY7tb9lSo50esEWgNXxXHypx0Og3CezMmQLdF2QzQdRSIXmNXKINjRvZpPTrvZv4k4NlJrFYTfOc3c root_password_sha2 = e472e1436cbe87774c1bc75d0a646d67e506bea1dff8701fd41f34bca33e1419
Successivamente, dovrai anche definire il tuo server un indirizzo di bind come mostrato di seguito:
http_bind_address = 127.0.0.1:9000
Salva e chiudi il file quando hai finito, quindi avvia il servizio Graylog e abilitalo per l'avvio al riavvio del sistema con il seguente comando:
systemctl daemon-reload
systemctl start graylog-server
systemctl enable graylog-server
Successivamente, puoi verificare lo stato del server Graylog utilizzando il seguente comando:
systemctl status graylog-server
Dovresti vedere il seguente output:
? graylog-server.service - Graylog server Loaded: loaded (/lib/systemd/system/graylog-server.service; disabled; vendor preset: enabled) Active: active (running) since Sun 2022-09-25 07:25:13 UTC; 10s ago Docs: http://docs.graylog.org/ Main PID: 78082 (graylog-server) Tasks: 44 (limit: 4579) Memory: 539.4M CPU: 18.488s CGroup: /system.slice/graylog-server.service ??78082 /bin/sh /usr/share/graylog-server/bin/graylog-server ??78119 /usr/bin/java -Xms1g -Xmx1g -XX:NewRatio=1 -server -XX:+ResizeTLAB -XX:-OmitStackTraceInFastThrow -Djdk.tls.acknowledgeC> Sep 25 07:25:13 ubuntu2204 systemd[1]: Started Graylog server. Sep 25 07:25:13 ubuntu2204 graylog-server[78119]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 a> Sep 25 07:25:14 ubuntu2204 graylog-server[78119]: WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performan> Sep 25 07:25:17 ubuntu2204 graylog-server[78119]: WARNING: An illegal reflective access operation has occurred Sep 25 07:25:17 ubuntu2204 graylog-server[78119]: WARNING: Illegal reflective access by retrofit2.Platform (file:/usr/share/graylog-server/gr> Sep 25 07:25:17 ubuntu2204 graylog-server[78119]: WARNING: Please consider reporting this to the maintainers of retrofit2.Platform Sep 25 07:25:17 ubuntu2204 graylog-server[78119]: WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access > Sep 25 07:25:17 ubuntu2204 graylog-server[78119]: WARNING: All illegal access operations will be denied in a future release
Puoi anche verificare il registro del server Graylog con il seguente comando:
tail -f /var/log/graylog-server/server.log
Una volta che il server Graylog è stato avviato correttamente, dovresti ottenere il seguente output:
2022-09-25T07:25:40.117Z INFO [ServerBootstrap] Services started, startup times in ms: {FailureHandlingService [RUNNING]=73, GeoIpDbFileChangeMonitorService [RUNNING]=88, PrometheusExporter [RUNNING]=88, OutputSetupService [RUNNING]=89, JobSchedulerService [RUNNING]=89, InputSetupService [RUNNING]=90, BufferSynchronizerService [RUNNING]=91, LocalKafkaMessageQueueReader [RUNNING]=92, LocalKafkaMessageQueueWriter [RUNNING]=92, GracefulShutdownService [RUNNING]=93, MongoDBProcessingStatusRecorderService [RUNNING]=93, UserSessionTerminationService [RUNNING]=101, StreamCacheService [RUNNING]=133, LocalKafkaJournal [RUNNING]=134, UrlWhitelistService [RUNNING]=134, ConfigurationEtagService [RUNNING]=137, EtagService [RUNNING]=139, PeriodicalsService [RUNNING]=174, LookupTableService [RUNNING]=203, JerseyService [RUNNING]=4076} 2022-09-25T07:25:40.133Z INFO [ServerBootstrap] Graylog server up and running.
A questo punto, il server Graylog è avviato e in ascolto sulla porta 9000. Puoi verificarlo con il seguente comando:
ss -antpl | grep 9000
Dovresti ottenere il seguente output:
LISTEN 0 4096 [::ffff:127.0.0.1]:9000 *:* users:(("java",pid=78119,fd=56))
Configura Nginx come proxy inverso per Graylog
Successivamente, dovrai installare e configurare Nginx come proxy inverso per accedere al server Graylog sulla porta 80.
Innanzitutto, installa il server Nginx con il seguente comando:
apt install nginx -y
Dopo aver installato il server Nginx, crea un nuovo file di configurazione dell'host virtuale Nginx con il seguente comando:
nano /etc/nginx/sites-available/graylog.conf
Aggiungi le seguenti righe:
server { listen 80; server_name graylog.example.org; 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 http://$server_name/; proxy_pass http://208.117.84.72:9000; } }
Salva e chiudi il file quando hai finito. Quindi, verifica Nginx per qualsiasi errore di sintassi con il seguente comando:
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
Successivamente, abilita il file di configurazione dell'host virtuale Nginx con il seguente comando:
ln -s /etc/nginx/sites-available/graylog.conf /etc/nginx/sites-enabled/
Successivamente, rimuovi il file dell'host virtuale predefinito di Nginx:
rm -rf /etc/nginx/sites-enabled/default
Infine, riavvia il servizio Nginx per applicare le modifiche:
systemctl restart nginx
Successivamente, verifica lo stato del Graylog con il seguente comando:
systemctl status nginx
Dovresti ottenere 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 Sun 2022-09-25 07:30:45 UTC; 8s ago Docs: man:nginx(8) Process: 78980 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 78981 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 78982 (nginx) Tasks: 3 (limit: 4579) Memory: 3.3M CPU: 49ms CGroup: /system.slice/nginx.service ??78982 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;" ??78983 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ??78984 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Sep 25 07:30:45 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server... Sep 25 07:30:45 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.
Accedi all'interfaccia web di Graylog
Ora apri il tuo browser web e digita l'URL http://graylog.example.com. Verrai reindirizzato alla pagina di accesso di Graylog come mostrato di seguito:
Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante Accedi. Dovresti vedere la dashboard di Graylog nella pagina seguente:
Conclusione
Congratulazioni! hai installato e configurato correttamente il server Graylog con Nginx come proxy inverso su Ubuntu 22.04. Ora puoi esplorare Graylog e creare un input per ricevere i log Rsyslog da fonti esterne. Non esitate a chiedermi se avete domande.