Skip to content

Elasticsearch

基本信息

属性
版本6.8.23(含拼音分词插件)
Helm 目录k8s-apps/04-helm/07-elasticsearch/
Namespaceyidun-infra
Release 名称elasticsearch-yidun
节点标签elasticsearch: "true"
NodePort30092
镜像elasticsearch/elasticsearch:6.8.23(含拼音分词定制镜像)

为什么用 ES 6.x

易盾反垃圾平台使用了特定版本的 ES 拼音分词插件,需要与 ES 6.8.x 配套。ES 7.x 版本也提供备选(07-elasticsearch7/),但需要单独测试业务兼容性。

关键配置

副本与分片

yaml
replicas: 1           # 单机模式
# replicas: 3         # 集群模式(自动调整)
minimumMasterNodes: 1 # 集群模式改为 2

JVM 内存

yaml
esJavaOpts: "-Xmx4g -Xms4g -XshowSettings:vm"

资源配置

yaml
resources:
  requests:
    cpu: "2"
    memory: "4Gi"
  limits:
    cpu: "4"
    memory: "6Gi"

存储

yaml
volumeClaimTemplate:
  storageClassName: "local-path"
  resources:
    requests:
      storage: 20Gi

服务暴露

yaml
service:
  type: NodePort
  nodePort: "30092"   # 外部访问端口

访问方式

bash
# 集群内访问(HTTP)
http://elasticsearch-yidun-master.yidun-infra.svc.cluster.local:9200

# NodePort 访问(从宿主机)
http://<节点IP>:30092

# 数据初始化时使用
export ELASTICSEARCH_HOST="127.0.0.1:30092"

常用运维

bash
# 查看集群健康状态
curl http://localhost:30092/_cluster/health?pretty

# 查看节点信息
curl http://localhost:30092/_cat/nodes?v

# 查看索引列表
curl http://localhost:30092/_cat/indices?v&s=index

# 查看分片分配情况
curl http://localhost:30092/_cat/shards?v

# 查看磁盘使用
curl http://localhost:30092/_cat/allocation?v

数据初始化

ES 索引由专门的初始化脚本创建:

bash
cd k3s-yidun-apps/yidun-platform/02-build/init-elasticsearch/antispam
export ELASTICSEARCH_HOST="127.0.0.1:30092"
bash docker-entrypoint.sh

常见问题

集群状态 RED/YELLOW

bash
# 查看未分配的分片
curl http://localhost:30092/_cluster/allocation/explain?pretty

# 常见原因:单节点时 replica=1 导致分片无法分配
# 解决:将 number_of_replicas 设为 0
curl -X PUT "http://localhost:30092/_settings" \
  -H "Content-Type: application/json" \
  -d '{"index": {"number_of_replicas": 0}}'

vm.max_map_count 不足

bash
# 错误信息:max virtual memory areas vm.max_map_count [65530] is too low
# 解决
sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" >> /etc/sysctl.conf

磁盘水位告警

ES 默认当磁盘使用率 > 85% 时停止写入:

bash
# 临时调整水位
curl -X PUT "http://localhost:30092/_cluster/settings" \
  -H "Content-Type: application/json" \
  -d '{
    "persistent": {
      "cluster.routing.allocation.disk.watermark.low": "90%",
      "cluster.routing.allocation.disk.watermark.high": "95%",
      "cluster.routing.allocation.disk.watermark.flood_stage": "97%"
    }
  }'

内部使用文档,请勿外传