Elasticsearch is the search and analytics workhorse behind log pipelines, product catalogs, and observability stacks. This article installs Elasticsearch 8.x on Ubuntu 22.04 or 24.04 from the vendor APT repository, sets the JVM heap correctly, locks the node to localhost, and verifies the cluster status. Audience is operators bringing up a single node for development or as the first node of a small production cluster.
How to verify
After the install, confirm the service is up and the cluster is green:
systemctl status elasticsearch
journalctl -u elasticsearch -n 50 --no-pager
ss -tlnp | grep -E '9200|9300'
curl -sk -u elastic:"$ELASTIC_PASSWORD" https://localhost:9200/
curl -sk -u elastic:"$ELASTIC_PASSWORD" https://localhost:9200/_cluster/health?pretty
curl -sk -u elastic:"$ELASTIC_PASSWORD" https://localhost:9200/_cat/nodes?v
Healthy output: status: green, one node listed, no shard initializing.
What’s happening
Elasticsearch is a JVM application that wraps Apache Lucene with a distributed coordination layer. Each node holds shards (primary and replica), accepts HTTP traffic on 9200, and gossips with peers on 9300. For a single-node setup, replicas must be set to zero — without a peer, replicas stay unassigned and indices stall in yellow.
Starting with 8.x, security is on by default: TLS for the HTTP API, an auto-generated elastic superuser password, and a built-in enrollment token mechanism for adding nodes and Kibana. The first boot writes the password to the journal — capture it.
The JVM heap is the single most important tuning knob. The rule of thumb is half the system RAM, capped at 31 GiB (above 32 GiB the JVM loses compressed oops and you waste memory). For development or small clusters, 2-4 GiB is plenty.
The procedure
1. Install Java prerequisites and the vendor repo:
sudo apt update
sudo apt install -y apt-transport-https gnupg curl
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | \
sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | \
sudo tee /etc/apt/sources.list.d/elastic-8.x.list
sudo apt update
2. Install the package and capture the bootstrap password:
sudo apt install -y elasticsearch
The post-install script prints the elastic user password and Kibana enrollment token. Copy them immediately — they only print once. If you miss them, regenerate with /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic.
3. Pin the heap size. Drop a file under /etc/elasticsearch/jvm.options.d/:
sudo tee /etc/elasticsearch/jvm.options.d/heap.options >/dev/null <<EOF
-Xms2g
-Xmx2g
EOF
-Xms and -Xmx must match — JVM growth at runtime causes GC pauses.
4. Configure single-node clustering. Edit /etc/elasticsearch/elasticsearch.yml:
cluster.name: sh-search
node.name: node-1
network.host: 127.0.0.1
http.port: 9200
discovery.type: single-node
xpack.security.enabled: true
network.host: 127.0.0.1 keeps the API off the public interface — put HAProxy or Nginx in front if you need to expose it.
5. Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable --now elasticsearch
The first boot takes 30-60 seconds while Lucene initializes the data directory.
6. Smoke-test with a real index:
export ELASTIC_PASSWORD='paste-the-bootstrap-password'
curl -sk -u elastic:"$ELASTIC_PASSWORD" -X PUT https://localhost:9200/test-1 \
-H 'Content-Type: application/json' \
-d '{"settings":{"number_of_shards":1,"number_of_replicas":0}}'
curl -sk -u elastic:"$ELASTIC_PASSWORD" -X POST https://localhost:9200/test-1/_doc \
-H 'Content-Type: application/json' \
-d '{"msg":"hello"}'
curl -sk -u elastic:"$ELASTIC_PASSWORD" https://localhost:9200/test-1/_search?pretty
Common pitfalls
- Heap larger than 31 GiB — JVM drops compressed object pointers and you lose effective memory. Keep at or below 31g, or run multiple nodes.
- No
vm.max_map_countbump — Elasticsearch refuses to start when it’s below 262144. Setvm.max_map_count=262144in/etc/sysctl.d/99-elastic.confand runsysctl -p. - Default replica count of 1 on single node — every new index stays yellow. Use an index template setting
number_of_replicas: 0for dev nodes. - Forgetting to disable swap — even a single page-out triggers multi-second pauses. Set
bootstrap.memory_lock: trueand addLimitMEMLOCK=infinityunder[Service]in/etc/systemd/system/elasticsearch.service.d/override.conf. - Snapshot repos point to
/tmp— Elasticsearch erases the path on restart. Use a persistent path or an S3 repository (see Elasticsearch snapshot restore to S3).
In the engagements we run, Elasticsearch rarely lives alone — it’s behind a load balancer, fronting a Kibana, and shipping snapshots to object storage every six hours. The configuration shown here is the foundation; production hardening (TLS for transport, mlockall, repository encryption, ILM, snapshot drills) is what we layer on top. See /en/services/managed-operations/ for how we run search clusters as an operating model.