Collect, process and visualise statistics from zeropingheroes/lancache-bare-metal with Elasticsearch, Logstash and Kibana
- Host running Ubuntu Server 24.04
- Separate host running
zeropingheroes/lancache-bare-metal
git clone git@github.com/zeropingheroes/lancache-elk /opt
sudo apt install apt-transport-https
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/9.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-9.x.list
sudo apt update
sudo apt install elasticsearch logstash kibana -y
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch logstash kibana
/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
sudo systemctl start elasticsearch
curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
sudo apt install apache2
sudo ln -s /opt/lancache-elk/etc/apache2/sites-available/kibana.conf /etc/apache2/sites-available/kibana.conf
sudo ln -s /etc/apache2/sites-available/kibana.conf /etc/apache2/sites-enabled/kibana.conf
echo "Listen 5602" | sudo tee -a /etc/apache2/ports.conf
sudo systemctl start apache2
/usr/share/kibana/bin/kibana-encryption-keys generate
Copy the config lines.
sudo nano /etc/kibana/kibana.yml
- Set
server.publicBaseUrlto your server's URL, for examplehttp://elk.example.com:5602 - Set
server.nameto your server's fully-qualified domain name, for exampleelk.example.com - Paste the generated key config from the previous step
/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
sudo systemctl start kibana
sudo systemctl status kibana
- Visit the URL provided by Kibana, changing the port to 5602
- Enter the Elastic enrollment token
- Click Configure Elastic
- If you're prompted for a verification code, enter the code provided by the
statuscommand above - Log in with the username
elasticand the password you set earlier
- Navigate to Stack Management > Security > Users
- Create a user with privileges for viewing and editing dashboards
- Navigate to Stack Management > Security > Roles
- Create a
logstash_writerrole:- Cluster privileges:
manage_index_templates,monitorandmanage_ilm - Indices privileges:
write,create,create_index,manageandmanage_ilm
- Cluster privileges:
- Navigate to Stack Management > Security > Users
- Create a
logstash_internaluser with thelogstash_writerrole
/usr/share/logstash/bin/logstash-keystore create --path.settings /etc/logstash/
/usr/share/logstash/bin/logstash-keystore --path.settings /etc/logstash/ add ES_USER ES_PWD
- For
ES_USERenterlogstash_internal - For
ES_PWDenter the password you set above
sudo mkdir /etc/logstash/certs
sudo cp /etc/elasticsearch/certs/http_ca.crt /etc/logstash/certs/http_ca.crt
sudo tee -a /etc/logstash/pipelines.yml > /dev/null <<EOF
- pipeline.id: lancache
path.config: "/opt/lancache-elk/etc/logstash/conf.d/*.conf"
EOF
sudo usermod -a -G logstash YOUR_USERNAME
sudo chown -R logstash:logstash /usr/share/logstash /var/log/logstash/ /var/lib/logstash /etc/logstash /opt/lancache-elk/
sudo chmod -R g+w /usr/share/logstash /var/log/logstash/ /var/lib/logstash /etc/logstash /opt/lancache-elk/
/usr/share/logstash/bin/logstash --path.settings /etc/logstash/ --config.test_and_exit
cd /opt/lancache-elk/
cp .env.example .env
nano .env
/opt/lancache-elk/elastic-import-index-template.sh
/opt/lancache-elk/kibana-import-dashboard.sh
/opt/lancache-elk/kibana-import-data-view.sh
sudo apt install apt-transport-https
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/9.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-9.x.list
sudo apt update
sudo apt install filebeat -y
git clone git@github.com/zeropingheroes/lancache-elk /opt
sudo mv /etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml.default
sudo ln -s /opt/lancache-elk/etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml
sudo nano /opt/lancache-elk/etc/filebeat/filebeat.yml
Change example.com to your logstash server's fully-qualified domain name.
sudo systemctl daemon-reload
sudo systemctl enable filebeat
sudo systemctl start filebeat
cd /opt/lancache-elk/etc/logstash/conf.d/
mv 98-output-debug.conf.disabled 98-output-debug.conf
mv 99-output-elastic.conf 99-output-elastic.conf.disabled
sudo systemctl stop logstash
/usr/share/logstash/bin/logstash --path.settings /etc/logstash/ --config.reload.automatic
mv 98-output-debug.conf 98-output-debug.conf.disabled
mv 99-output-elastic.conf.disabled 99-output-elastic.conf
sudo journalctl -u filebeat
| Elastic Field | Type | Elastic Data Type | HTTP Access | HTTP Error | Stream Access | Stream Error |
|---|---|---|---|---|---|---|
| @timestamp | Base ECS | date | ✅ | ✅ | ✅ | ✅ |
| client.bytes | Base ECS | long | ✅ | ❌ | ✅ | ✅ |
| client.ip | Base ECS | ip | ✅ | ✅ | ✅ | ✅ |
| error.message | Base ECS | match_only_text | ❌ | ✅ | ❌ | ✅ |
| http.request.method | Base ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| http.request.ranges.end | Base ECS | long | ✅ | ❌ | ❌ | ❌ |
| http.request.ranges.original | Base ECS | keyword | ✅ | ❌ | ❌ | ❌ |
| http.request.ranges.start | Base ECS | long | ✅ | ❌ | ❌ | ❌ |
| http.request.referrer | Base ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| http.response.body.bytes | Base ECS | long | ✅ | ❌ | ❌ | ❌ |
| http.response.status_code | Base ECS | long | ✅ | ✅ | ✅ | ❌ |
| http.version | Base ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| log.level | Base ECS | keyword | ✅ | ✅ | ✅ | ✅ |
| nginx.bytes | Base ECS | long | ❌ | ❌ | ❌ | ✅ |
| nginx.connection_id | Custom ECS | long | ❌ | ✅ | ❌ | ✅ |
| nginx.session_duration | Custom ECS | float | ✅ | ❌ | ✅ | ❌ |
| nginx.slice.range.end | Custom ECS | long | ✅ | ❌ | ❌ | ❌ |
| nginx.slice.range.start | Custom ECS | long | ✅ | ❌ | ❌ | ❌ |
| process.pid | Base ECS | long | ❌ | ✅ | ❌ | ✅ |
| process.thread.id | Base ECS | long | ❌ | ❌ | ❌ | ❌ |
| server.bytes | Base ECS | long | ✅ | ❌ | ✅ | ✅ |
| steam.depot.id | Custom ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| steam.depot.chunk.id | Custom ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| steam.depot.manifest.id | Custom ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| steam.depot.manifest.segment1 | Custom ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| steam.depot.manifest.segment2 | Custom ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| upstream.address | Base ECS | keyword | ✅ | ✅ | ✅ | ✅ |
| upstream.bytes | Base ECS | long | ✅ | ❌ | ❌ | ✅ |
| upstream.cache_status | Custom ECS | keyword | ✅ | ❌ | ❌ | ❌ |
| upstream.label | Custom ECS | keyword | ✅ | ✅ | ✅ | ✅ |
| upstream.response.status_code | Custom ECS | long | ✅ | ❌ | ❌ | ❌ |
| upstream.response.time | Custom ECS | float | ✅ | ❌ | ❌ | ❌ |
| upstream.url | Custom ECS | keyword | ❌ | ✅ | ❌ | ❌ |
| url.path | Base ECS | wildcard | ✅ | ✅ | ❌ | ❌ |
| url.query | Base ECS | keyword | ✅ | ✅ | ❌ | ❌ |
| user_agent.original | Base ECS | match_only_text | ✅ | ❌ | ❌ | ❌ |
- https://www.elastic.co/docs/deploy-manage/deploy/self-managed/install-elasticsearch-with-debian-package
- https://www.elastic.co/docs/deploy-manage/deploy/self-managed/install-kibana-with-debian-package
- https://www.elastic.co/docs/reference/logstash/installing-logstash
- https://www.elastic.co/docs/reference/logstash/secure-connection#es-security-onprem
- https://www.elastic.co/docs/reference/logstash/keystore
- https://www.elastic.co/docs/reference/beats/filebeat/configuration-filebeat-options
- https://www.elastic.co/docs/reference/beats/filebeat/filebeat-input-filestream
- https://www.elastic.co/docs/reference/beats/filebeat/exported-fields-beat-common
- https://www.elastic.co/docs/reference/beats/filebeat/exported-fields-log
- https://www.elastic.co/docs/reference/beats/filebeat/logstash-output
- https://www.elastic.co/docs/reference/beats/filebeat/configuration-general-options#libbeat-configuration-fields
- https://regex-generator.olafneumann.org
- https://github.com/logstash-plugins/logstash-patterns-core/blob/main/patterns/ecs-v1/grok-patterns
- https://github.com/zeropingheroes/lancache-bare-metal/blob/main/access-log-formats/http/detailed.conf
- https://www.elastic.co/docs/reference/ecs/ecs-http
- https://www.elastic.co/docs/reference/security/fields-and-object-schemas/siem-field-reference
- https://www.elastic.co/docs/reference/observability/fields-and-object-schemas
- https://www.elastic.co/docs/reference/logstash/plugins/plugins-filters-grok
- https://www.elastic.co/docs/reference/ecs/ecs-getting-started
- https://www.elastic.co/docs/reference/ecs/ecs-guidelines
- https://www.elastic.co/blog/do-you-grok-grok
Submit pull requests that for example:
- Extract additional fields from URIs
- Add Kibana visualisations
Modify index templates, dashboards and data views in Kibana, and use the export scripts to add them to the repository.