centos7 安装es8.12.0

在CentOS操作系统上安装Elasticsearch(ES)通常涉及以下步骤。虽然您提供的信息中包含了多个不同时间点和版本的安装指南片段,但这里我会为您概述一个通用且适用于较新版本Elasticsearch(如7.x或8.x)的安装流程。请根据实际需求调整具体的版本号和细节。

准备工作:

  1. 确认系统要求

    • 确保您的CentOS系统满足Elasticsearch的最低硬件和软件要求,包括足够的内存、磁盘空间以及兼容的CPU架构。
  2. 安装Java

    • Elasticsearch依赖于Java运行环境。确保安装了Java 11或更高版本(推荐使用OpenJDK)。您可以使用以下命令检查已安装的Java版本:

      bash 复制代码
      java -version
    • 如需安装或更新Java,可以使用官方仓库或第三方源,例如:

      bash 复制代码
      sudo yum install -y java-11-openjdk-devel
  3. 创建非root用户

    • 为了安全起见,不建议以root用户直接运行Elasticsearch。创建一个专门用于运行Elasticsearch的系统用户:

      bash 复制代码
      sudo useradd -r -s /sbin/nologin elasticsearch
    • -r表示创建系统账户,-s /sbin/nologin指定无登录shell,防止直接登录此账户。

安装Elasticsearch:

  1. 下载安装包

  2. 解压安装包

    • 将下载的tar.gz文件上传至CentOS服务器,并解压到适当的位置,如 /usr/local。假设文件名为 elasticsearch-8.12.0-linux-x86_64.tar.gz

      bash 复制代码
      sudo tar -xzf elasticsearch-8.12.0-linux-x86_64.tar.gz -C /usr/local
    • 之后,重命名目录以便管理:

      bash 复制代码
      sudo mv /usr/local/elasticsearch-8.12.0 /usr/local/elasticsearch
  3. 配置Elasticsearch

    • 编辑 /usr/local/elasticsearch/config/elasticsearch.yml 文件,根据您的环境调整配置。关键配置可能包括:
bash 复制代码
cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
xpack.security.enabled: false
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs

xpack.security.enrollment.enabled: false
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12
xpack.security.transport.ssl:
  enabled: false
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
 - `cluster.name`: 设置集群名称。
 - `node.name`: 设置节点名称。
 - `network.host`: 指定节点监听的主机地址(如 `localhost` 或特定IP)。
 - `path.data`: 数据存储路径。
 - `path.logs`: 日志文件存放路径。
 - 可能需要开启或配置安全功能(如X-Pack Security)。

编辑配置文件 /etc/security/limits.conf 或者在目录 /etc/security/limits.d/ 创建配置文件 (e.g., /etc/security/limits.d/elasticsearch.conf) 添加正面的内容

bash 复制代码
elasticsearch soft nofile 65536
elasticsearch hard nofile 65536

执行以下命令

bash 复制代码
sudo systemctl daemon-reload

在目录 /etc/sysctl.d/创建文件/etc/sysctl.d/elasticsearch.conf,添加以下内容:

bash 复制代码
vm.max_map_count=262144

执行以下命令

bash 复制代码
sudo sysctl --system
  1. 设置权限

    • 更新Elasticsearch目录及其子目录的所有者为刚创建的elasticsearch用户:

      bash 复制代码
      sudo chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
  2. 启动Elasticsearch

    • 切换到elasticsearch用户并执行启动命令:

      bash 复制代码
      sudo -u elasticsearch /usr/local/elasticsearch/bin/elasticsearch
    • 如果一切正常,Elasticsearch将开始运行,并输出日志信息。可以通过浏览器访问 http://localhost:9200 来验证安装是否成功。

可选步骤:

  • 设置开机自启动

    • 可以编写Systemd服务单元文件,以便在系统启动时自动启动Elasticsearch。创建 /etc/systemd/system/elasticsearch.service 文件,内容类似如下:

      [Unit]
      Description=Elasticsearch Service
      Requires=network-online.target
      After=network-online.target
      
      [Service]
      Type=simple
      User=elasticsearch
      Group=elasticsearch
      ExecStart=/usr/local/elasticsearch/bin/elasticsearch
      Restart=always
      
      [Install]
      WantedBy=multi-user.target
      
    • 启动服务、启用开机启动:

      bash 复制代码
      sudo systemctl daemon-reload
      sudo systemctl start elasticsearch
      sudo systemctl enable elasticsearch
  • 安装Kibana(可选)

    • 如果需要可视化界面,按照类似步骤安装Kibana,确保其配置中的 elasticsearch.url 指向正确运行的Elasticsearch实例。
  • 配置安全性和身份验证(可选)

    • 如果使用的是带有X-Pack Security的Elasticsearch版本,需要进一步配置用户、角色、权限,并可能需要生成和配置SSL证书。

请根据您的具体需求和所选Elasticsearch版本的官方文档来细化上述步骤。记得定期关注官方更新,及时升级到最新安全版本。

相关推荐
小O_好好学14 分钟前
CentOS 7文件系统
linux·运维·centos
程序员-珍4 小时前
虚拟机ip突然看不了了
linux·网络·网络协议·tcp/ip·centos
bubble小拾4 小时前
ElasticSearch高级功能详解与读写性能调优
大数据·elasticsearch·搜索引擎
不能放弃治疗5 小时前
重生之我们在ES顶端相遇第 18 章 - Script 使用(进阶)
elasticsearch
hengzhepa5 小时前
ElasticSearch备考 -- Search across cluster
学习·elasticsearch·搜索引擎·全文检索·es
Ljubim.te7 小时前
Linux基于CentOS学习【进程状态】【进程优先级】【调度与切换】【进程挂起】【进程饥饿】
linux·学习·centos
Elastic 中国社区官方博客7 小时前
Elasticsearch:使用 LLM 实现传统搜索自动化
大数据·人工智能·elasticsearch·搜索引擎·ai·自动化·全文检索
慕雪华年8 小时前
【WSL】wsl中ubuntu无法通过useradd添加用户
linux·ubuntu·elasticsearch
苦逼IT运维8 小时前
YUM 源与 APT 源的详解及使用指南
linux·运维·ubuntu·centos·devops
Elastic 中国社区官方博客10 小时前
使用 Vertex AI Gemini 模型和 Elasticsearch Playground 快速创建 RAG 应用程序
大数据·人工智能·elasticsearch·搜索引擎·全文检索