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
# 查看状态:
sudo systemctl status es-cluster
# 查看日志:
sudo journalctl -u es-cluster -b(-b表示仅本次启动日志)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JackHuan_code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值