温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

elasticsearch集群怎样部署

发布时间:2026-10-07 12:20:46 来源:亿速云 阅读:100 作者:小樊 栏目:关系型数据库

下面按从零到生产可用的思路,给你讲一下 Elasticsearch(ES)集群的部署方式,涵盖规划 → 安装 → 配置 → 启动 → 验证 → 常见生产建议。


一、部署前规划(非常重要)

1. 节点角色(ES 7+ 推荐)

ES 集群通常由以下角色组成:

角色 说明
master 负责集群元数据、选主
data 存储数据、执行搜索
ingest 数据预处理
coordinating 仅路由请求(不存数据)

生产建议:

  • master 节点 3 个(奇数,避免脑裂)
  • data 节点根据数据量横向扩展
  • 小集群可合并角色,大集群要分离

2. 硬件建议

  • CPU:2–8 核起步,搜索密集可更高
  • 内存:
    • 单节点 ≤ 64G
    • JVM 堆内存 = 物理内存的一半,且 ≤ 31G
  • 磁盘:
    • SSD 优先
    • 使用 多盘挂载 + 多 path.data
  • 网络:千兆起步,推荐万兆

3. 系统准备(Linux)

# 关闭 swap
swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab

# 文件描述符
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf

# 虚拟内存
sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" >> /etc/sysctl.conf

二、安装 Elasticsearch

方式一:官方 RPM / DEB(推荐)

# 以 CentOS 为例
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

cat > /etc/yum.repos.d/elasticsearch.repo <<EOF
[elasticsearch]
name=Elasticsearch
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
enabled=1
EOF

yum install elasticsearch -y

方式二:Tar 包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.x.x-linux-x86_64.tar.gz
tar -xzf elasticsearch-8.x.x-linux-x86_64.tar.gz

三、核心配置文件(elasticsearch.yml)

路径:

/etc/elasticsearch/elasticsearch.yml

1. 基础集群配置(示例:3 节点)

cluster.name: my-es-cluster

node.name: es-node-1
node.roles: [master, data]

network.host: 0.0.0.0
http.port: 9200

discovery.seed_hosts:
  - 10.0.0.1
  - 10.0.0.2
  - 10.0.0.3

cluster.initial_master_nodes:
  - es-node-1
  - es-node-2
  - es-node-3

⚠️ initial_master_nodes 只在首次启动集群时配置


2. JVM 配置

# /etc/elasticsearch/jvm.options
-Xms16g
-Xmx16g

四、启动集群

1. 启动服务

systemctl daemon-reload
systemctl enable elasticsearch
systemctl start elasticsearch

2. 查看状态

curl http://localhost:9200/_cat/nodes?v
curl http://localhost:9200/_cluster/health?pretty

✅ 健康状态应为:

"status" : "green"

五、安全配置(ES 8 默认开启)

1. 内置安全(TLS + 账号)

ES 8 默认:

  • 开启 TLS
  • 自动生成 elastic 用户密码

查看密码:

/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

访问:

curl -u elastic https://localhost:9200

六、常见部署架构

1. 最小生产集群(3 节点)

3 × (master + data)

2. 中型集群

3 × master
N × data

3. 大型集群

3 × master
N × data
M × ingest

七、容器 / 云部署(简要)

Docker

docker run -d \
  -p 9200:9200 \
  -e "discovery.type=single-node" \
  elasticsearch:8.x

K8s(生产推荐)

  • 使用 ECK(Elastic Cloud on Kubernetes)
  • 自动管理 master / data / 安全

八、运维建议

  • 使用 索引生命周期管理(ILM)
  • 定期快照(Snapshot + Repository)
  • 监控:Elasticsearch Exporter + Prometheus
  • 不要频繁重启 data 节点

如果你愿意,可以告诉我:

  • ES 版本(7 / 8)
  • 节点数量 & 数据规模
  • 是否上云 / K8s

我可以直接帮你写一套可用的配置文件模板。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI
助
手