下面按从零到生产可用的思路,给你讲一下 Elasticsearch(ES)集群的部署方式,涵盖规划 → 安装 → 配置 → 启动 → 验证 → 常见生产建议。
ES 集群通常由以下角色组成:
| 角色 | 说明 |
|---|---|
| master | 负责集群元数据、选主 |
| data | 存储数据、执行搜索 |
| ingest | 数据预处理 |
| coordinating | 仅路由请求(不存数据) |
生产建议:
# 关闭 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
# 以 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
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
路径:
/etc/elasticsearch/elasticsearch.yml
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只在首次启动集群时配置
# /etc/elasticsearch/jvm.options
-Xms16g
-Xmx16g
systemctl daemon-reload
systemctl enable elasticsearch
systemctl start elasticsearch
curl http://localhost:9200/_cat/nodes?v
curl http://localhost:9200/_cluster/health?pretty
✅ 健康状态应为:
"status" : "green"
ES 8 默认:
elastic 用户密码查看密码:
/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
访问:
curl -u elastic https://localhost:9200
3 × (master + data)
3 × master
N × data
3 × master
N × data
M × ingest
docker run -d \
-p 9200:9200 \
-e "discovery.type=single-node" \
elasticsearch:8.x
如果你愿意,可以告诉我:
我可以直接帮你写一套可用的配置文件模板。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。