متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 36Elasticsearch · Monitoring

Install and set up Elasticsearch

Elasticsearch is a search and analytics engine. In IT and security work it is the heart of the ELK / Elastic Stack: it stores logs and events and finds anything in billions of lines in seconds — for log search, SIEM and app search. This guide installs Elasticsearch 9 from the Elastic repository on RHEL and Ubuntu, keeps the security that is turned on at install, sets memory and the cluster settings, and covers health, index lifecycle, snapshots and the most common errors (yellow/red health, read-only indices).

  • 9 الدروس
  • 15 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

36.1

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).

ItemValue
Packageelasticsearch (Elastic repository, 9.x)
Serviceelasticsearch.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/
Ports9200/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.

36.2

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…

تذكّر

**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.

الأوامر في هذا الدرس

36.3

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 elasticsearch

الأوامر في هذا الدرس

36.4

First configuration: the settings to make first

/etc/elasticsearch/elasticsearch.yml
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:

/etc/elasticsearch/jvm.options.d/heap.options
-Xms4g
-Xmx4g
SettingWhy
network.hostListen on the private IP (default is localhost only).
discovery.type: single-nodeOne node, no election; for labs and small setups.
Heap = 50 % RAMThe other half is the file cache, which Elasticsearch needs as much.
path.repoA folder (shared in a cluster) for snapshots.
xpack.security.enabled: trueLogin 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 --reload

Lost the password? /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic.

36.5

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 -30

Real 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.

الأوامر في هذا الدرس

36.6

Make it safe

Security checklist:

  • Keep security on (TLS + login); never open 9200 or 9300 to the internet.
  • Change the elastic password and do not use elastic in 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.

36.7

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 elasticsearch

In a cluster: disable shard allocation, upgrade and restart one node, wait for green, then the next node.

36.8

Fix common problems

ProblemCauseFix
Health yellow on one nodeReplicas can not be placed on a single node.Normal on one node; or set "number_of_replicas": 0 on those indices.
Health redA 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 lowKernel setting (containers, manual installs).sysctl -w vm.max_map_count=262144 and in /etc/sysctl.d/.
Service fails: OutOfMemoryError / killed by OOMHeap too big or too small for the RAM.Heap 50 % of RAM; check journalctl -u elasticsearch and the GC log.
curl: (60) SSL certificate problemThe 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 …".

36.9

Next steps

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.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل