Elasticsearch单机安装

下载

Past Releases of Elastic Stack Software | Elastichttps://www.elastic.co/downloads/past-releases找到需要下载的版本并上传到服务器

解压

配置

elasticsearch.yml

config目录下

复制代码
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: elasticsearch
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /opt/can/elasticsearch/data
#
# Path to log files:
#
path.logs: /opt/can/elasticsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

开启密码

复制代码
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

日志和data数据存储路径

复制代码
path.logs: /opt/can/elasticsearch/logs
复制代码
path.data: /opt/can/elasticsearch/data

jvm.options

  1. 内存配置

    • 堆大小 :使用 -Xms-Xmx 设置堆的初始大小和最大大小。例如,-Xms8g -Xmx8g 表示将堆的初始大小和最大大小都设置为 8GB。通常建议将 -Xms-Xmx 设为相同的值,以避免 JVM 堆的动态调整给应用进程带来不稳定因素。同时,堆的大小不应超过物理内存的 50%,因为 Elasticsearch 还需要利用堆外内存来进行网络通信、依赖操作系统的文件系统缓存来有效访问文件等操作,JVM 本身也需要一些内存。
  2. 垃圾回收器配置

    • 选择垃圾回收器 :可以使用 -XX:+UseG1GC 等参数选择不同的垃圾回收器。G1 垃圾回收器是 Elasticsearch 默认使用的垃圾回收器,它适合处理大量短生命周期对象的环境,并且可以提供可预测的停顿时间。
    • 新生代和老年代比例 :对于 G1 垃圾回收器,可以通过 -XX:NewRatio=n 设置新生代和老年代的比例,默认值为 2。也可以使用 -XX:NewSize-XX:MaxNewSize 分别设置新生代的初始大小和最大大小,但这两个参数的优先级比 -XX:NewRatio 高,会覆盖其配置的值。
    • 并发标记周期-XX:ConcGCThreads=n 可以设置并发标记阶段的线程数,默认值为 CPU 核心数。增加该值可以提高并发标记的速度,但也会增加系统的开销。
    • 混合回收阈值-XX:InitiatingHeapOccupancyPercent=n 可以设置混合回收的阈值,当堆内存的使用率达到该值时,会触发混合回收。默认值为 45%。
  3. 直接内存配置

    • 直接内存大小-XX:MaxDirectMemorySize=n 可以设置 JVM 堆外内存的最大值。默认情况下,JVM 会在需要时动态分配堆外内存,但可能会导致系统出现 OOM 异常。通过设置这个参数,可以限制堆外内存的使用,避免因堆外内存不足而导致的问题。
  4. 其他配置

    • 预分配内存-XX:+AlwaysPreTouch 可以减少新生代晋升到老年代时的停顿。在 JVM 初始化时,它会预分配参数里指定的内存,使得启动后访问内存会更流畅,减少因页面分配导致的 GC 停顿时间。

    • 禁用交换-XX:+DisableExplicitGC 可以禁用显式的垃圾回收调用。在生产环境中,一般不需要手动触发垃圾回收,由 JVM 自动管理即可。

    • 线程栈大小-Xss 可以配置线程占用的栈内存大小,默认每条线程为 1M。如果应用程序中创建了大量的线程,可以适当调整该值。

    • 文件描述符限制 :在 Linux 系统中,需要在 /etc/security/limits.conf 文件中将 * soft nofile 65536* hard nofile 65536 修改为 655300 后执行 sysctl -p,以增大文件描述符的个数,否则启动时可能会报值太小的错误。

elasticsearch-env

bin目录下

创建用户(默认无法使用root用户启动)

复制代码
sudo useradd es

/home 目录下为该用户创建一个主目录。

复制代码
sudo useradd -m es

sudo groupadd es

sudo usermod -aG 组名 用户名

复制代码
sudo usermod -aG es es

es文件夹授权给es

复制代码
chown -R es:es es安装路径

chmod -R 777 es路径

切换用户

su es

运行

启动es

cd 到bin文件

复制代码
./elasticsearch -d

设置密码

cd 到bin文件

复制代码
./elasticsearch-setup-passwords  interactive

然后依次设置密码即可。

测试

在浏览器访问9200端口,如172.30.6.42:9200

输入密码即可

相关推荐
End9283 小时前
Spark之搭建Yarn模式
大数据·分布式·spark
我爱写代码?3 小时前
Spark 集群配置、启动与监控指南
大数据·开发语言·jvm·spark·mapreduce
TDengine (老段)3 小时前
什么是物联网 IoT 平台?
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
青云交3 小时前
Java 大视界 -- 基于 Java 的大数据分布式存储在工业互联网海量设备数据长期存储中的应用优化(248)
java·大数据·工业互联网·分布式存储·冷热数据管理·hbase 优化·kudu 应用
会飞的架狗师3 小时前
【SpringBoot实战指南】集成Easy ES
spring boot·elasticsearch
艾醒(AiXing-w)4 小时前
探索大语言模型(LLM):国产大模型DeepSeek vs Qwen,谁才是AI模型的未来?
大数据·人工智能·语言模型
£菜鸟也有梦4 小时前
从0到1上手Kafka:开启分布式消息处理之旅
大数据·kafka·消息队列
Elastic 中国社区官方博客4 小时前
在 Elasticsearch 中删除文档中的某个字段
大数据·数据库·elasticsearch·搜索引擎
时序数据说5 小时前
时序数据库IoTDB分布式系统监控基础概述
大数据·数据库·database·时序数据库·iotdb
漂流瓶6666666 小时前
Spark处理过程-转换算子
大数据·分布式·spark