For our Blog Visitor only Get Additional 3 Month Free + 10% OFF on TriAnnual Plan YSBLOG10
Grab the Deal

How to Setup ElasticSearch on Linux Server – Easy Guide

To set up Elasticsearch on a Linux server, add Elastic’s official repository, install the package, configure elasticsearch.yml (network, discovery, security), tune JVM heap, adjust kernel limits (vm.max_map_count), open firewall ports, disable swap, and enable the systemd service. Then secure with built‑in authentication and TLS, and verify via curl or Kibana.

In this guide, you’ll learn how to setup Elasticsearch on Linux server securely and correctly, from package installation to production-grade tuning. I’ll show Ubuntu/Debian and RHEL/CentOS flows, explain core settings, and share real-world tips from 12+ years in hosting so you avoid bootstrap and performance pitfalls.

What is Elasticsearch and Why it Matters?

Elasticsearch is a distributed, RESTful search and analytics engine used for full‑text search, logging (ELK/Elastic Stack), observability, and metrics. It scales horizontally, stores JSON documents, and provides near real‑time search. Getting the Linux install right is critical: misconfigured memory, swap, or network settings cause crashes, slow queries, or failed cluster startups.

Prerequisites and System Requirements

Before you install, ensure the following for a smooth deployment and to pass Elasticsearch bootstrap checks:

  • Linux distro: Ubuntu 20.04/22.04/24.04, Debian 11/12, RHEL/Rocky/Alma 8/9.
  • CPU/RAM: Minimum 2 vCPU, 4 GB RAM (8–16 GB+ recommended for production).
  • Storage: SSD-backed volumes; plan for growth (indexes grow faster than you expect).
  • Java: Elasticsearch 8.x ships with a bundled JDK—no separate Java needed.
  • Network ports: 9200 (HTTP), 9300 (transport/cluster). Keep 9200 private unless protected.
  • Root or sudo access.

If you prefer fully managed infrastructure, YouStable’s SSD NVMe VPS and Dedicated Servers are ideal for Elasticsearch, with quick scaling, DDoS protection, and 24×7 help setting up secure clusters.

Quick Install: Ubuntu/Debian (APT)

These commands install the latest Elasticsearch 8.x from Elastic’s official repository.

# 1) Import GPG key and add repo
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/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

# 2) Install Elasticsearch
sudo apt update
sudo apt install -y elasticsearch

Quick Install: RHEL/CentOS/Rocky/Alma (YUM/DNF)

# 1) Import key and repo
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo tee /etc/yum.repos.d/elasticsearch.repo >/dev/null <<'EOF'
[elasticsearch-8.x]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

# 2) Install
sudo dnf install -y elasticsearch || sudo yum install -y elasticsearch

Post‑Install System Tuning (Must‑Do)

These settings prevent common “bootstrap checks failed” errors and improve stability.

Increase Virtual Memory Areas

# Temporary until reboot
sudo sysctl -w vm.max_map_count=262144

# Persist across reboots
echo "vm.max_map_count=262144" | sudo tee /etc/sysctl.d/99-elasticsearch.conf
sudo sysctl --system

Disable Swap

Elasticsearch relies on the OS page cache; swap degrades performance and can block startup.

# Disable now
sudo swapoff -a

# Comment out any swap entries in /etc/fstab to keep it off after reboot
sudo sed -ri 's/^([^#].*\s+swap\s+)/#\1/' /etc/fstab

File Descriptors and Processes

# Allow Elasticsearch to open many files and threads
sudo tee /etc/security/limits.d/elasticsearch.conf >/dev/null <<'EOF'
elasticsearch - nofile 65535
elasticsearch - nproc  4096
EOF

Core Configuration: elasticsearch.yml

Edit the main config file: /etc/elasticsearch/elasticsearch.yml. For a single-node dev or sandbox, use discovery.type: single-node and keep HTTP bound to localhost for safety.

sudo nano /etc/elasticsearch/elasticsearch.yml

# Minimal single-node example (safe for a dev box)
cluster.name: my-es-cluster
node.name: es-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 127.0.0.1
http.port: 9200
discovery.type: single-node
# In 8.x, security is on by default. Keep it enabled.
xpack.security.enabled: true

For a production node, bind to a private IP, configure initial master nodes, and seed hosts:

# Production sketch (adjust IPs/hostnames)
cluster.name: prod-es
node.name: es-1
network.host: 10.0.1.10
http.port: 9200

discovery.seed_hosts: ["10.0.1.11","10.0.1.12"]
cluster.initial_master_nodes: ["es-1","es-2","es-3"]

xpack.security.enabled: true

JVM Heap and Performance Tuning

Right-size the heap so Elasticsearch has memory while leaving OS cache for Lucene segments.

  • Set -Xms and -Xmx to the same value (avoid resizing pauses).
  • Use ~50% of system RAM for heap, max 31g to keep compressed OOPs efficient.
  • Leave at least 50% to the OS for file system cache.
# Create a JVM override file (survives package updates)
sudo mkdir -p /etc/elasticsearch/jvm.options.d
echo "-Xms4g" | sudo tee /etc/elasticsearch/jvm.options.d/heap.options
echo "-Xmx4g" | sudo tee -a /etc/elasticsearch/jvm.options.d/heap.options

Start and Enable the Service

sudo systemctl daemon-reload
sudo systemctl enable --now elasticsearch
sudo systemctl status elasticsearch --no-pager

Open Firewall Ports (Only What You Need)

UFW (Ubuntu/Debian)

# Allow SSH
sudo ufw allow 22/tcp

# Allow HTTP API only if necessary and secured
# sudo ufw allow 9200/tcp

# Allow transport port for intra-cluster comms (private networks only)
sudo ufw allow 9300/tcp

sudo ufw enable
sudo ufw status

firewalld (RHEL Family)

sudo firewall-cmd --permanent --add-service=ssh
# sudo firewall-cmd --permanent --add-port=9200/tcp
sudo firewall-cmd --permanent --add-port=9300/tcp
sudo firewall-cmd --reload

Security Basics: Users, Passwords, and TLS

Elasticsearch 8.x enables security by default. Set passwords for built-in users and use TLS. For a single-node dev host, keep 127.0.0.1 binding to avoid exposing 9200 publicly.

# Set or reset the elastic user's password (Elasticsearch 8.x)
sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

# (Optional) Generate HTTP/transport TLS materials
# This creates a CA and certs you can reference in elasticsearch.yml
sudo /usr/share/elasticsearch/bin/elasticsearch-certutil ca
sudo /usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

For zero-trust environments, terminate TLS at a reverse proxy (Nginx/HAProxy) with mTLS or IP allowlists, and restrict 9300 to private networks only. Never leave 9200 open to the internet without authentication and TLS.

Verify the Installation

# If bound to localhost and security enabled
curl -k -u elastic:<PASSWORD> https://127.0.0.1:9200

# Expected: cluster_name, cluster_uuid, tagline: "You Know, for Search"

If you see SSL or auth errors, confirm the password, CA trust, and that you are using HTTPS. For non‑TLS local testing (not recommended in production), you would connect via http://127.0.0.1:9200 if security/TLS are disabled.

Optional: Install Kibana

Kibana is the UI for Elasticsearch exploration and management. Use the same repository you added for Elasticsearch.

# Ubuntu/Debian
sudo apt install -y kibana

# RHEL family
sudo dnf install -y kibana || sudo yum install -y kibana

# Configure
sudo nano /etc/kibana/kibana.yml
# Minimal edits:
# server.host: "0.0.0.0"              # or private IP
# elasticsearch.hosts: ["https://127.0.0.1:9200"]

# For 8.x, use enrollment flow or set kibana_system password:
# sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana_system

# Start Kibana
sudo systemctl enable --now kibana
sudo systemctl status kibana --no-pager

Production‑Ready Checklist

  • Network and topology: Use 3+ master‑eligible nodes for quorum; separate data and master roles if scaling.
  • Security: Keep xpack.security enabled; enforce HTTPS; rotate passwords; restrict 9200 to trusted sources.
  • Heap: 50% of RAM, max 31g; disable swap.
  • Storage: Use fast SSD/NVMe; dedicate disks; monitor IOPS; enable RAID1/10 where needed.
  • Index lifecycle: Use ILM for logs/metrics; rollover and shrink to control shard counts.
  • Shards: Don’t overshard—prefer fewer, larger shards; target shard sizes of a few GB to tens of GB based on workload.
  • Monitoring: Enable Elastic Stack monitoring or Prometheus exporters; set alerts on heap, CPU steal, disk watermarks.
  • Backups: Use snapshot repositories (S3, GCS, NFS) and test restores.
  • Upgrades: Read release notes; upgrade minor versions across the cluster in rolling fashion.

Troubleshooting Common Errors

“vm.max_map_count too low”

Set vm.max_map_count=262144 and reload sysctl as shown earlier, then restart Elasticsearch.

“bootstrap checks failed” during startup

  • Ensure swap is disabled.
  • Increase file descriptors and nproc.
  • Use discovery settings (seed hosts and initial master) for clusters.
  • Don’t bind 0.0.0.0 without proper security.

High GC pauses or OOM

  • Lower shard count; avoid tiny shards.
  • Right‑size heap; keep -Xms = -Xmx, stay under 31g.
  • Check hot threads: GET _nodes/hot_threads, profile heavy queries.

When to Consider OpenSearch

Elasticsearch 8.x uses the Elastic license. If you need Apache 2.0 licensing or want AWS-integrated alternatives, consider OpenSearch. Operationally it’s similar, but plugins, features, and APIs can differ. YouStable supports both Elasticsearch and OpenSearch on our VPS and dedicated platforms—ask us which fits your compliance and budget.

Real‑World Tips From Hosting at Scale

  • Plan index lifecycle early. Log/metrics stacks balloon; ILM saves storage and cost.
  • Keep 9200 private. Use a bastion or VPN for API access; expose Kibana behind SSO.
  • Reserve CPU credits on burstable instances to avoid latency spikes.
  • Pre-warm caches after rolling restarts for predictable performance.
  • Test snapshot restores quarterly—backups you can’t restore aren’t backups.

Step‑By‑Step Summary

  • Add Elastic’s repo and install the package.
  • Set vm.max_map_count, disable swap, raise ulimits.
  • Configure elasticsearch.yml (network, discovery, security).
  • Tune JVM heap to ~50% RAM (max 31g).
  • Start and enable the service with systemd.
  • Secure with passwords and TLS; lock down ports.
  • Verify with curl and (optionally) install Kibana.

If you want a turnkey setup, YouStable can provision an optimized Linux server with Elasticsearch pre‑tuned for your workload, including VPC/firewall hardening, SSL, snapshots, and 24×7 monitoring.

FAQs: How to Setup Elasticsearch on Linux Server

What is the fastest way to install Elasticsearch on Ubuntu?

Use Elastic’s official APT repo, then apt install elasticsearch. This ensures the latest compatible 8.x build with bundled JDK. After install, tune vm.max_map_count, disable swap, edit elasticsearch.yml, and enable the service via systemctl.

Which ports does Elasticsearch need?

Port 9200 for the HTTP API and 9300 for node‑to‑node transport. Keep 9200 private or gated by TLS and authentication. Restrict 9300 to your cluster’s private network only.

How much RAM should I allocate to the JVM heap?

Allocate about 50% of system RAM to the heap with -Xms and -Xmx set equally, but cap at 31g to retain compressed object pointers. Leave the remaining RAM for the OS page cache.

Do I need Java installed separately?

No. Elasticsearch 8.x includes a bundled JDK. Using the bundled JDK avoids version conflicts and is the recommended approach.

How do I secure Elasticsearch in production?

Keep xpack.security enabled, set strong passwords for built‑in users, enforce HTTPS (TLS), restrict network access, and consider a reverse proxy with SSO or IP allowlisting. Regularly patch and monitor the cluster, and don’t expose 9200 directly to the public internet.

Prahlad Prajapati

Prahlad is a web hosting specialist and SEO-focused organic growth expert from India. Active in the digital space since 2019, he helps people grow their websites through clean, sustainable strategies. Passionate about learning and adapting fast, he believes small details create big success. Discover his insights on web hosting and SEO to elevate your online presence.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top