当前位置: 首页 > news >正文

Liunx部署ES单机集群

ES 7.17.26 为例

一、单机

下载ES安装包

下载地址

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.26-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.26-linux-x86_64.tar.gz.sha512
shasum -a 512 -c elasticsearch-7.17.26-linux-x86_64.tar.gz.sha512 
tar -xzf elasticsearch-7.17.26-linux-x86_64.tar.gz
cd elasticsearch-7.17.26/ 

修改配置

vim elasticsearch.yml#开启远程访问  
network.host: 0.0.0.0
#单节点模式   初学者建议设置为此模式 
discovery.type: single-node

后台启动

./bin/elasticsearch -d -p pid

验证

http://192.168.65.174:9200

关闭ES

pkill -F pid# 或
# 查找进程ID
pgrep -f 'elasticsearch'  # 输出类似 "12345"# 终止进程(先尝试正常退出)
kill 12345# 若未响应则强制终止(慎用)
kill -9 12345

二、集群

创建用户

adduser es
passwd es

修改host

切换到root用户,修改/etc/hosts

vim  /etc/hosts
192.168.65.174 es-node1  
192.168.65.192 es-node2  
192.168.65.204 es-node3  

修改elasticsearch.yml

node.name: node-1
cluster.name: es-cluster
node.master: true
node.data: true
network.host: 0.0.0.0# 如果服务器存在 Docker 或其他虚拟网卡,需在配置中 排除无关网卡:# 强制传输层使用 ens-33
ransport.host: _ens33:ipv4_  
discovery.seed_hosts: ["es-node1", "es-node2", "es-node3"]
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
http.cors.enabled: true
http.cors.allow-origin: "*"node.name: node-2
cluster.name: es-cluster
node.master: true
node.data: true
network.host: 0.0.0.0
ransport.host: _ens33:ipv4_
discovery.seed_hosts: ["es-node1", "es-node2", "es-node3"]
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
http.cors.enabled: true
http.cors.allow-origin: "*"node.name: node-3
cluster.name: es-cluster
node.master: true
node.data: true
network.host: 0.0.0.0
ransport.host: _ens33:ipv4_  
discovery.seed_hosts: ["es-node1", "es-node2", "es-node3"]
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
http.cors.enabled: true
http.cors.allow-origin: "*"

启动ES服务

bin/elasticsearch -d 

验证集群

http://192.168.65.174:9200/_cat/nodes?pretty
==>
192.168.235.134 37 95 0 0.00 0.01 0.00 cdfhilmrstw - node-1
192.168.235.136 11 70 0 0.15 0.05 0.02 cdfhilmrstw - node-3
192.168.235.135 56 20 0 0.03 0.02 0.00 cdfhilmrstw * node-2

三、配置开机自启

通过Systemd服务(推荐,适用于CentOS 7+/Ubuntu 16.04+)

1. 创建systemd服务文件
在用户es下, 新建一个.service文件,例如es-cluster.service:

sudo vim /etc/systemd/system/es-cluster.service

添加以下内容(根据实际路径和用户调整):

[Unit]
Description=Elasticsearch Cluster Startup Script# 确保网络就绪后启动
After=network.target[Service]
Type=forking
# 建议使用非root用户
User=es
# 用户所属组
Group=es    # 设置工作目录
WorkingDirectory=/home/es/elasticsearch-7.17.26
ExecStart=/home/es/elasticsearch-7.17.26/start.sh# 避免超时误判
TimeoutStartSec=0# 失败时自动重启
Restart=on-failure[Install]
WantedBy=multi-user.target
  • start.sh (使用绝对路径)

#!/bin/bash
# 启动 ES(使用绝对路径)
/home/es/elasticsearch-7.17.26/bin/elasticsearch -d

2. 设置脚本权限与服务配置

  • 确保start.sh有执行权限:
sudo chmod +x /home/es/elasticsearch-7.17.26/start.sh
  • 重载systemd配置并启用服务:
sudo systemctl daemon-reload
sudo systemctl enable es-cluster.service

3. 验证与操作

启动服务:sudo systemctl start es-cluster
查看状态:systemctl status es-cluster
查看日志:journalctl -u es-cluster -b(-b表示仅本次启动日志)
http://www.xdnf.cn/news/677179.html

相关文章:

  • Streamlit 项目知识点总结
  • OpenCv高阶(十三)——人脸检测
  • 第二章:软盘里的90年代
  • 力扣四道题,力扣LCR 016无重复字符的最长子串力扣452.用最小数量的箭引爆气球LCR026.重排链表力扣.1765地图中的最高点
  • 猿大师办公助手WebOffice用二进制数据流在Web前端打开Office文档
  • 如何使用 Redis 实现排行榜功能
  • 中车靶场,网络安全暑期实训营
  • [特殊字符]使用 Hyperlane 实现 WebSocket广播
  • MySql(四)
  • python-自定义导包问题ModuleNotFoundError: No module named
  • Linux 文件管理相关知识与命令
  • Linux升级内核回退到旧内核启动
  • Linux 进阶命令篇
  • 广东省省考备考(第二十二天5.27)—言语(第九节课)
  • Python正则表达式:30秒精通文本处理
  • 【判断含有相同数字rfind】2022-1-28
  • 高频面试--redis
  • [yolov11改进系列]基于yolov11引入分布移位卷积DSConv的python源码+训练源码
  • AI智能体策略FunctionCalling和ReAct有什么区别?
  • 多卡训练的开源大模型,开箱即用
  • Jenkins实践(8):服务器A通过SSH调用服务器B执行Python自动化脚本
  • WSL连接网络
  • 新太空原子钟任务为全球标准化测高系统铺平道路
  • 编译原理——语法制导的语义计算
  • 欢乐熊大话蓝牙知识11:如何打造一个低功耗蓝牙温湿度传感器?
  • getline()跳过输入
  • 01背包问题
  • 【Elasticsearch】_update api用于更新单文档,更新多个文档使用_update_by_query
  • 软件更新 | TSMaster 202504 版本已上线!三大功能让车载测试更智能
  • 基于Python技术的面部考勤微信小程序的设计与实现