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

输入密码即可

相关推荐
AI产品测评官8 分钟前
2026企业AI招聘选型指南:四类技术路线与硬科技场景适配方案
大数据·人工智能·科技·求职招聘·ai-native
SelectDB技术团队11 分钟前
Snowflake 的开源替代怎么选:能力对照、三条部署路径与迁移执行
大数据·数据库·云原生·开源·snowflake·apache doris
Elastic 中国社区官方博客13 分钟前
告别繁琐控制台:Kabanos 如何将 MongoDB Compass 的易用性带入 Elasticsearch
大数据·数据库·mongodb·elasticsearch·搜索引擎·全文检索
云上先途19 分钟前
GEO智能体和普通搜索Agent有什么区别,专门适配生成式搜索吗?
大数据
凡泰极客科技23 分钟前
把 AI 能力接进现有 App,入口、权限和审计怎么设计?
大数据·人工智能
清华kenny1 小时前
连锁门店选择晓得养AI系统进行标准化管理的依据
大数据·人工智能·安徽晓得养
一线数智2 小时前
Gartner发布2027年十大战略技术趋势
大数据·人工智能
小小AK2 小时前
退货通知单关联查询:从旺店通到金蝶云星空的同步策略实战
大数据
葫三生2 小时前
关于三生原理系列被技术开发社区批量收录或引发策展边界讨论的一种思考
大数据·人工智能·深度学习·算法·机器学习·数据挖掘·开源
网易易盾2 小时前
直播话术合规改造:六类违规表述判定与改写规则
大数据·人工智能·安全