ES 压缩包安装

以下是 Elasticsearch (ES) 通过 .tar.gz 压缩包安装的详细步骤(适用于 Linux/macOS 系统):


1. 准备工作

1.1 检查系统依赖
  • Java 环境 :ES 需要 JDK,推荐 OpenJDK 11/17 (ES 7.x/8.x 兼容版本)。

    bash 复制代码
    java -version  # 检查是否已安装
    • 如果未安装,使用以下命令安装(以 Ubuntu 为例):

      bash 复制代码
      sudo apt update
      sudo apt install openjdk-11-jdk
1.2 创建专用用户
  • Elasticsearch 禁止以 root 用户运行 ,需创建普通用户:

    bash 复制代码
    sudo useradd -m elasticsearch
    sudo passwd elasticsearch  # 设置密码
    sudo usermod -aG sudo elasticsearch  # 授予 sudo 权限(可选)

2. 下载并解压 Elasticsearch

2.1 下载最新版本
  • Elastic 官网 获取 .tar.gz 包(以 8.13.0 为例):

    bash 复制代码
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.0-linux-x86_64.tar.gz
2.2 校验文件完整性
bash 复制代码
sha512sum elasticsearch-8.13.0-linux-x86_64.tar.gz  # 对比官网提供的 SHA512
2.3 解压到目标目录
bash 复制代码
sudo tar -xzf elasticsearch-8.13.0-linux-x86_64.tar.gz -C /usr/local/
sudo mv /usr/local/elasticsearch-8.13.0 /usr/local/elasticsearch
2.4 设置权限
bash 复制代码
sudo chown -R elasticsearch:elasticsearch /usr/local/elasticsearch

3. 配置 Elasticsearch

3.1 修改配置文件
  • 编辑主配置文件 /usr/local/elasticsearch/config/elasticsearch.yml

    bash 复制代码
    sudo su elasticsearch
    cd /usr/local/elasticsearch/config
    nano elasticsearch.yml
    • 基础配置示例 (按需调整):

      yaml 复制代码
      cluster.name: my-es-cluster  # 集群名称
      node.name: node-1            # 节点名称
      path.data: /var/lib/elasticsearch  # 数据存储路径(需提前创建并授权)
      path.logs: /var/log/elasticsearch  # 日志路径
      network.host: 0.0.0.0        # 允许所有 IP 访问(生产环境建议限制)
      discovery.type: single-node  # 单节点模式(集群需配置其他节点)
      xpack.security.enabled: true # 启用安全功能(8.x 默认开启)
3.2 设置 JVM 堆内存
  • 修改 /usr/local/elasticsearch/config/jvm.options

    bash 复制代码
    -Xms2g  # 最小堆内存(建议不超过物理内存的 50%)
    -Xmx2g  # 最大堆内存

4. 启动 Elasticsearch

4.1 切换到专用用户
bash 复制代码
sudo su elasticsearch
cd /usr/local/elasticsearch
4.2 启动服务(前台运行)
bash 复制代码
./bin/elasticsearch
  • 如果看到类似以下输出,说明启动成功:

    plaintext 复制代码
    [2024-07-07T10:00:00,000][INFO ][o.e.n.Node] [node-1] started
4.3 验证运行状态
  • 新开终端访问:

    bash 复制代码
    curl -XGET "http://localhost:9200/" --user elastic:<password>
    • 首次启动会生成默认密码(在终端日志中查找),或手动重置:

      bash 复制代码
      ./bin/elasticsearch-reset-password -u elastic

5. 设置为系统服务(可选)

5.1 创建 systemd 服务文件
bash 复制代码
sudo nano /etc/systemd/system/elasticsearch.service
  • 内容如下:

    ini 复制代码
    [Unit]
    Description=Elasticsearch
    After=network.target
    
    [Service]
    User=elasticsearch
    Group=elasticsearch
    ExecStart=/usr/local/elasticsearch/bin/elasticsearch
    Restart=always
    LimitNOFILE=65536  # 解决 "max file descriptors" 错误
    
    [Install]
    WantedBy=multi-user.target
5.2 启动并开机自启
bash 复制代码
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
sudo systemctl status elasticsearch  # 检查状态

6. 常见问题解决

6.1 内存锁定失败
  • 错误:memory locking requested for elasticsearch process but memory is not locked

  • 解决方案:

    bash 复制代码
    sudo nano /etc/security/limits.conf

    添加:

    plaintext 复制代码
    elasticsearch soft memlock unlimited
    elasticsearch hard memlock unlimited
6.2 最大文件描述符不足
  • 错误:max file descriptors [4096] for elasticsearch process is too low

  • 解决方案:

    bash 复制代码
    sudo nano /etc/security/limits.conf

    添加:

    plaintext 复制代码
    elasticsearch - nofile 65536

总结

  1. 安装 JDK → 2. 下载解压 ES → 3. 配置 elasticsearch.yml → 4. 启动服务 → 5. 验证访问
  • 生产环境建议:
    • 使用 systemd 托管服务
    • 启用 安全配置(如 HTTPS、RBAC)。
    • 监控 堆内存使用情况(避免 OOM)。

官方文档参考:Elasticsearch Install Guide

相关推荐
梦里不知身是客111 天前
Spark介绍
大数据·分布式·spark
啊吧怪不啊吧1 天前
SQL之表的查改(下)
大数据·数据库·sql
猫猫姐姐1 天前
Flink基于Paimon的实时湖仓解决方案的演进
大数据·flink·湖仓一体
极客数模1 天前
2025年(第六届)“大湾区杯”粤港澳金融数学建模竞赛准备!严格遵循要求,拿下大奖!
大数据·python·数学建模·金融·分类·图论·boosting
Elastic 中国社区官方博客1 天前
Elastic AI agent builder 介绍(三)
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索
王卫东2 天前
深入HBase:原理剖析与优化实战
大数据·数据库·hbase
HaiLang_IT2 天前
2026 人工智能与大数据专业毕业论文选题方向及题目示例(nlp/自然语言处理/图像处理)
大数据·人工智能·毕业设计选题
呆呆小金人2 天前
SQL键类型详解:超键到外键全解析
大数据·数据库·数据仓库·sql·数据库开发·etl·etl工程师
StarRocks_labs2 天前
StarRocks 4.0:基于 Apache Iceberg 的 Catalog 中心化访问控制
大数据·apache
梦子yumeko2 天前
第六章langchain4j之Tools和prompt
大数据·prompt