On this page
- How much memory does Elasticsearch need?
- How do you install Elasticsearch on Ubuntu or Debian?
- What does security on by default mean?
- How do you keep port 9200 off the internet?
- How do you size the JVM heap?
- How do you create a user for your application?
- How do you take snapshots and add nodes later?
- How do you upgrade and troubleshoot Elasticsearch?
- Questions
How much memory does Elasticsearch need?
Give an Elasticsearch node at least 4 GB of RAM for real use, with roughly half as JVM heap and the rest left to the operating system file cache, which Lucene relies on for fast searches. A 2 GB server runs a small test index but has little headroom.
Elasticsearch suits full text search for a shop or documentation site, log search and analytics over JSON documents. For a single site search, it also helps to know the alternatives covered elsewhere in this library, such as Apache Solr and PostgreSQL full text search, which may already be enough.
Before installing, log in as a sudo user, update the system and turn swap off or keep it minimal, because a JVM that pages to disk stalls. Fast NVMe storage pays off when indexing.
How do you install Elasticsearch on Ubuntu or Debian?
Import the Elastic signing key, add the 9.x repository, install the package and note the password it prints.
sudo apt update
sudo apt install -y curl gnupg apt-transport-https
curl -fsSL 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 -y elasticsearchThe output contains a block titled Security autoconfiguration information with the password of the built-in elastic superuser. Save it in a password manager straight away. The package bundles its own Java runtime, so no separate JDK is needed. It does not start the service on its own:
sudo systemctl daemon-reload
sudo systemctl enable --now elasticsearch
sudo systemctl status elasticsearch --no-pagerThe first start can take a minute while the node creates its keys and system indices.
What does security on by default mean?
From the first start, every request needs a username and password, the HTTP layer speaks TLS with a certificate from a CA the installer created, and traffic between nodes is encrypted too. Nothing answers anonymously.
sudo curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200
sudo curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic "https://localhost:9200/_cluster/health?pretty"A JSON reply with the version number and a cluster status of green (or yellow on a single node with replicas set) proves the install works. Plain http:// requests fail by design.
If you lose the elastic password, generate a new one:
sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic -iThe certificates live in /etc/elasticsearch/certs/. Clients on other machines need http_ca.crt, or the CA fingerprint, to trust the node.
How do you keep port 9200 off the internet?
Bind the HTTP layer to localhost. The installer writes http.host: 0.0.0.0 into /etc/elasticsearch/elasticsearch.yml so that other machines can enroll; for a single node, change it.
sudo nano /etc/elasticsearch/elasticsearch.yml
# change the line in the security block to:
http.host: 127.0.0.1
sudo systemctl restart elasticsearch
sudo ss -ltnp | grep -E ':9200|:9300'Both ports should now show 127.0.0.1 only. Add a firewall rule as a second layer:
sudo ufw deny 9200/tcp
sudo ufw deny 9300/tcpWhen an app on another server needs search, connect the servers with WireGuard and bind http.host to the tunnel address, or tunnel over SSH. TLS and passwords already protect the API, but a port that answers nobody is still the stronger default.
How do you size the JVM heap?
Set the minimum and maximum heap to the same value, about half the RAM, and stay below roughly 31 GB so the JVM keeps compressed object pointers. Put the setting in its own file under jvm.options.d:
echo -e '-Xms2g\n-Xmx2g' | sudo tee /etc/elasticsearch/jvm.options.d/heap.options
sudo systemctl restart elasticsearch
sudo curl -s --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic \
"https://localhost:9200/_nodes/stats/jvm?filter_path=**.heap_max_in_bytes,**.heap_used_percent&pretty"Without this file Elasticsearch picks a heap from the total RAM automatically, which is fine for a dedicated machine. Set it by hand when the server also runs a web stack, so the node does not claim memory other services need. On a 4 GB server shared with an app, 1.5 to 2 GB is reasonable; on an 8 GB dedicated node, 4 GB.
The package also raises the kernel limit on memory maps. Confirm it with sysctl vm.max_map_count; the value should be at least 262144.
How do you create a user for your application?
Create a role limited to the indices the app uses, then a user with that role. The elastic superuser belongs to administration only.
ES="https://localhost:9200"; CA=/etc/elasticsearch/certs/http_ca.crt
sudo curl -s --cacert $CA -u elastic -X PUT "$ES/_security/role/shop_rw" \
-H 'Content-Type: application/json' \
-d '{"indices":[{"names":["shop-*"],"privileges":["read","write","create_index","view_index_metadata"]}]}'
sudo curl -s --cacert $CA -u elastic -X PUT "$ES/_security/user/shop" \
-H 'Content-Type: application/json' \
-d '{"password":"App-Secret-Value-63","roles":["shop_rw"]}'Test it by indexing and searching a document:
sudo curl -s --cacert $CA -u shop -X POST "$ES/shop-products/_doc?refresh=true" -H 'Content-Type: application/json' -d '{"name":"NVMe VPS","tags":["linux","crypto"]}'
sudo curl -s --cacert $CA -u shop "$ES/shop-products/_search?q=name:vps&pretty"API keys, created with POST /_security/api_key, work well for services and can carry an expiry date.
How do you take snapshots and add nodes later?
Register a shared file system repository for snapshots, then snapshot on a schedule. List the directory in path.repo first:
sudo install -d -o elasticsearch -g elasticsearch /var/backups/es
echo 'path.repo: ["/var/backups/es"]' | sudo tee -a /etc/elasticsearch/elasticsearch.yml
sudo systemctl restart elasticsearch
sudo curl -s --cacert $CA -u elastic -X PUT "$ES/_snapshot/local" -H 'Content-Type: application/json' -d '{"type":"fs","settings":{"location":"/var/backups/es"}}'
sudo curl -s --cacert $CA -u elastic -X PUT "$ES/_snapshot/local/snap-$(date +%F)?wait_for_completion=true"Snapshot lifecycle management (_slm/policy) can automate this daily. To grow into a cluster, create an enrollment token on the first node and pass it to each new node before its first start. The transport layer on port 9300 must then listen on a reachable address and be allowed between nodes only:
sudo /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node
# on the new node, before starting it
sudo /usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token TOKENHow do you upgrade and troubleshoot Elasticsearch?
Upgrade within the 9.x line through apt after reading the release notes, one node at a time in a cluster, and read the cluster log first when something fails.
sudo apt update && sudo apt install --only-upgrade elasticsearch
sudo systemctl restart elasticsearch
sudo journalctl -u elasticsearch -n 50 --no-pager
sudo tail -n 80 /var/log/elasticsearch/elasticsearch.logCommon problems and fixes:
- Service killed during start: the heap is too large for the RAM; lower
-Xmx. - Cluster status yellow on one node: indices ask for replicas that have nowhere to go; set
"number_of_replicas": 0on them. - Writes blocked: the disk passed the flood-stage watermark (95 percent by default); free space and the block lifts automatically.
- Certificate errors from clients: give them
http_ca.crtor its fingerprint.
When the data outgrows the plan, deploy a larger one and restore a snapshot there; moving to a larger plan covers the server side.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
| Plan | Fits because | Size | Monthly | Order from |
|---|---|---|---|---|
| A2-4 | single node for site search | 2 vCPU, 4 GB RAM, 100 GB NVMe | $14.40/mo | $43.20 for 3 months |
| A4-8 | larger indices with a 4 GB heap | 4 vCPU, 8 GB RAM, 180 GB NVMe | $28.80/mo | $86.40 for 3 months |
| A8-16 | log analytics or heavy indexing | 8 vCPU, 16 GB RAM, 350 GB NVMe | $57.60/mo | $57.60 for 1 month |
Questions about Install Elasticsearch
Can I turn security off for testing?
You can set xpack.security.enabled: false, but then anyone who reaches the port can read and delete everything. Keep security on and use the generated password even for tests.
Why does curl say the certificate is untrusted?
The HTTP certificate comes from a CA the installer created on your server. Pass --cacert /etc/elasticsearch/certs/http_ca.crt so curl trusts it.
How much heap should I set?
About half the RAM, with the same value for -Xms and -Xmx, and never above about 31 GB. Leave the other half to the file system cache.
Do I need to install Java?
No. The package ships a bundled Java runtime that matches the release.
Can Kibana connect to this node?
Yes. Create a token with elasticsearch-create-enrollment-token -s kibana and paste it into Kibana on first start.
Which ports does Elasticsearch use?
Port 9200 for the HTTPS REST API and 9300 for traffic between nodes. Keep both closed to the public.
More in Databases
- Install MySQL 8
- Install MariaDB
- Install PostgreSQL
- Install MongoDB
- PostgreSQL JSON, arrays and special types
- PostgreSQL views, triggers and CTEs
- PostgreSQL full-text search and encryption
- MySQL keys, indexes and full-text search
- MySQL JSON, views and stored procedures
- Apache Solr search server
- Install Redis or Valkey
- Install Memcached
- Apache Cassandra cluster
- Install Apache CouchDB
- InfluxDB for time series
- Back up and restore MySQL and MariaDB
- Back up and restore PostgreSQL
- MySQL users, roles and passwords
- PostgreSQL roles and permissions
- Repair a crashed MySQL table
- PostgreSQL streaming replication
- MongoDB replica set
- PostGIS for location data
- Database insight with PgHero
- Couchbase Server
- ArangoDB multi-model database
- Remote database access over SSH