$ run as a normal user# run as root (or with sudo)
Know it before you install
Data is stored as JSON documents in indices. Each index is split into shards (spread over nodes) with replicas (copies on other nodes). Cluster health: green (all copies placed), yellow (replicas missing — normal on one node), red (data missing).
| Item | Value |
|---|---|
| Package | elasticsearch (Elastic repository, 9.x) |
| Service | elasticsearch.service |
| Config | /etc/elasticsearch/elasticsearch.yml |
| Memory (heap) | /etc/elasticsearch/jvm.options.d/*.options |
| Certificates | /etc/elasticsearch/certs/ (made at install) |
| Data / logs | /var/lib/elasticsearch/, /var/log/elasticsearch/ |
| Ports | 9200/tcp (HTTPS REST API), 9300/tcp (node-to-node) |
| Tools | /usr/share/elasticsearch/bin/ (elasticsearch-reset-password, elasticsearch-create-enrollment-token) |
What you need: 64-bit Linux, at least 4 GB RAM for a lab (8–64 GB in real use), fast disks (SSD), and the same version on all nodes. OpenSearch is the open-source fork if you need Apache 2.0.
Install on RHEL, Rocky, Alma and Fedora
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat > /etc/yum.repos.d/elasticsearch.repo <<'EOF'
[elasticsearch]
name=Elasticsearch repository for 9.x packages
baseurl=https://artifacts.elastic.co/packages/9.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
EOF
dnf -y install --enablerepo=elasticsearch elasticsearch
--------------------------- Security autoconfiguration information ------------------------------
The generated password for the elastic built-in superuser is : Xy7…Remember
**Copy the elastic password from the install output now.** The repo has enabled=0, so a normal dnf upgrade does not upgrade Elasticsearch by surprise.
Install on Ubuntu and Debian
apt-get install -y apt-transport-https gnupg wget
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | 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" > /etc/apt/sources.list.d/elastic-9.x.list
apt-get update
apt-get install -y elasticsearch
apt-mark hold elasticsearchFirst configuration: the settings to make first
cluster.name: logs-prod
node.name: es-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 10.0.2.11
http.port: 9200
discovery.type: single-node
path.repo: ["/backup/es-snapshots"]
xpack.security.enabled: true(The install already added the xpack.security.* TLS lines — keep them. For a 3-node cluster use discovery.seed_hosts and cluster.initial_master_nodes instead of single-node.)
Set the heap to half of the RAM, at most about 31 GB, min and max the same:
-Xms4g
-Xmx4g| Setting | Why |
|---|---|
network.host | Listen on the private IP (default is localhost only). |
discovery.type: single-node | One node, no election; for labs and small setups. |
| Heap = 50 % RAM | The other half is the file cache, which Elasticsearch needs as much. |
path.repo | A folder (shared in a cluster) for snapshots. |
xpack.security.enabled: true | Login and TLS — never turn it off. |
Also: swap off (or vm.swappiness=1); the package already sets vm.max_map_count=262144. Start and test:
mkdir -p /backup/es-snapshots && chown elasticsearch: /backup/es-snapshots
systemctl daemon-reload
systemctl enable --now elasticsearch
curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://10.0.2.11:9200
Enter host password for user 'elastic':
{ "name" : "es-1", "cluster_name" : "logs-prod", "version" : { "number" : "9.1.5" … }, "tagline" : "You Know, for Search" }
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.0/16" port port="9200" protocol="tcp" accept'
firewall-cmd --reloadLost the password? /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic.
Daily use: health, indices and lifecycle
Make a short helper and look at the cluster:
alias es='curl -s --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:"$ES_PASS"'
es 'https://10.0.2.11:9200/_cluster/health?pretty'
es 'https://10.0.2.11:9200/_cat/nodes?v'
es 'https://10.0.2.11:9200/_cat/indices?v&s=store.size:desc' | head
es 'https://10.0.2.11:9200/_cat/allocation?v'
es 'https://10.0.2.11:9200/_cluster/allocation/explain?pretty'Delete old logs automatically with an ILM policy (rollover at 30 GB or 1 day, delete after 30 days):
es -X PUT 'https://10.0.2.11:9200/_ilm/policy/logs-30d' -H 'Content-Type: application/json' -d '{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_primary_shard_size":"30gb","max_age":"1d"}}},"delete":{"min_age":"30d","actions":{"delete":{}}}}}}'Snapshots (backups) to the path.repo folder:
es -X PUT 'https://10.0.2.11:9200/_snapshot/fs_backup' -H 'Content-Type: application/json' -d '{"type":"fs","settings":{"location":"/backup/es-snapshots"}}'
es -X PUT 'https://10.0.2.11:9200/_snapshot/fs_backup/snap-1?wait_for_completion=true'
es 'https://10.0.2.11:9200/_snapshot/fs_backup/_all?pretty' | head -30Real uses at work:
- Central log search (with Fluent Bit / Logstash / Elastic Agent and Kibana).
- SIEM: security events from servers, firewalls and cloud, with detection rules (Elastic Security, Wazuh).
- Full-text search for apps and shops.
Make it safe
Security checklist:
- Keep security on (TLS + login); never open 9200 or 9300 to the internet.
- Change the
elasticpassword and do not useelasticin apps — create users/roles or API keys with only the rights needed. - Firewall: 9200 from shippers and Kibana only; 9300 only between nodes.
- Snapshots to another place (object storage via repository plugins) and a restore test.
- ILM so the disk never fills; monitor disk usage (watermarks).
- Same version on all nodes; upgrade with a rolling restart, after reading the notes.
Update and remove
dnf -y upgrade --enablerepo=elasticsearch elasticsearch
apt-mark unhold elasticsearch && apt-get install --only-upgrade -y elasticsearch && apt-mark hold elasticsearch
systemctl restart elasticsearch
dnf -y remove elasticsearchIn a cluster: disable shard allocation, upgrade and restart one node, wait for green, then the next node.
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
| Health yellow on one node | Replicas can not be placed on a single node. | Normal on one node; or set "number_of_replicas": 0 on those indices. |
| Health red | A primary shard is missing (node down, disk). | _cluster/allocation/explain; bring the node back; restore from snapshot. |
index … blocked by: [TOO_MANY_REQUESTS/12/disk usage exceeded flood-stage watermark, index has read-only-allow-delete block] | Disk over 95 %. | Free space or delete old indices; the block lifts by itself when disk is under the limit. |
max virtual memory areas vm.max_map_count [65530] is too low | Kernel setting (containers, manual installs). | sysctl -w vm.max_map_count=262144 and in /etc/sysctl.d/. |
Service fails: OutOfMemoryError / killed by OOM | Heap too big or too small for the RAM. | Heap 50 % of RAM; check journalctl -u elasticsearch and the GC log. |
curl: (60) SSL certificate problem | The client does not trust the auto-made CA. | --cacert /etc/elasticsearch/certs/http_ca.crt. |
missing authentication credentials (401) | No user/password or API key. | -u elastic or -H "Authorization: ApiKey …". |
Next steps
- The UI: Install and set up Kibana. Ship logs into it: Install and set up Fluent Bit.
- The other log store: Grafana Loki.
- Practise log investigation: Lab: investigate an SSH brute-force attack from the logs.
- Command line help: Command page: curl, Command page: jq.
1A single-node cluster is yellow. Is data missing?
No. Yellow means replicas are not placed — on one node there is nowhere to put them.
2How big should the Elasticsearch heap be on a 16 GB server?
About 8 GB (half of RAM), with -Xms and -Xmx the same.