TL;DR

  • Scenario: Single machine deployment of Elasticsearch for development and testing
  • Conclusion: Single-node mode meets small company business scenarios, simple config easy to get started
  • Output: Complete deployment process, JVM config, system parameters

ES Single Machine Deployment Overview

Single-Node Mode

Elasticsearch is a distributed full-text search engine, supports:

  • Single-node mode (Single-Node Mode)
  • Cluster mode (Cluster Mode)

Small company business scenarios can use Single-Node Mode.


Official Website

https://www.elastic.co/cn/downloads/elasticsearch

Download and Extract

Download

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.0-linux-x86_64.tar.gz

Extract

cd /opt/software/
tar -zxvf elasticsearch-7.3.0-linux-x86_64.tar.gz
mv elasticsearch-7.3.0 ../servers/

Config Modification

Service Config

Modify elasticsearch.yml:

vim /opt/servers/elasticsearch-7.3.0/config/elasticsearch.yml
  • For single machine installation, uncomment: node.name: node-1
  • Modify network and port
# ------------------------------------ Node ------------------------------------
node.name: node-1

JVM Config

Modify jvm.options:

vim /opt/servers/elasticsearch-7.3.0/config/jvm.options

Note: Default 1G memory not enough, recommend setting 2G:

-Xms2g
-Xmx2g

User and Permissions

Create User

ES doesn’t allow root user to start by default:

useradd es_server
passwd es_server

Grant Permissions

chown -R es_server /opt/servers/elasticsearch-7.3.0

System Parameter Config

Modify sysctl.conf

ES needs to create many index files, need to adjust kernel parameters:

vim /etc/sysctl.conf

Add at end:

vm.max_map_count=655360

Apply:

sysctl -p

Modify limits.conf

Modify file descriptor limits:

vim /etc/security/limits.conf

Add at end:

* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096

Start Service

Switch User

su es_server

Start

/opt/servers/elasticsearch-7.3.0/bin/elasticsearch

Start in Background

/opt/servers/elasticsearch-7.3.0/bin/elasticsearch -d

Access Service

Verify

http://h121.wzk.icu:9200

Return Result

{
  "name": "node-1",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "zv9WF53-RfKO1xNaIxt3uA",
  "version": {
    "number": "8.15.0",
    "build_flavor": "default",
    "build_type": "tar",
    "build_hash": "1a77947f34deddb41af25e6f0ddb8e830159c179",
    "build_date": "2024-08-05T10:05:34.233336849Z",
    "build_snapshot": false,
    "lucene_version": "9.11.1",
    "minimum_wire_compatibility_version": "7.17.0",
    "minimum_index_compatibility_version": "7.0.0"
  },
  "tagline": "You Know, for Search"
}

Deployment Best Practices

Cluster Planning

  • Set different roles like master node, data node, coordinating node
  • Set reasonable shard and replica counts to ensure performance and fault tolerance

Security

  • Use X-Pack for user authentication and role management
  • Configure TLS/SSL encrypted communication to ensure data transmission security

Performance Optimization

  • Reasonably set index.refresh_interval to reduce overhead
  • Use index.max_result_window to adjust query result count limit
  • Enable shard allocation awareness to ensure shards distribute on different physical nodes

Error Quick Reference

SymptomRoot CauseFix
Memory insufficientJVM heap set too large/physical memory insufficientReduce -Xms2g -Xmx2g
File descriptor too lowlimits.conf not appliedRestart or re-login
max_map_count too lowKernel parameter not setsysctl -p to apply
Root run deniedES doesn’t allow root to startCreate normal user
Port occupied9200/9300 port occupiedCheck port or modify config