为啥 Elasticsearch 集群只能发现 1 个节点?
Posted
技术标签:
【中文标题】为啥 Elasticsearch 集群只能发现 1 个节点?【英文标题】:Why does Elasticsearch cluster only discover 1 node?为什么 Elasticsearch 集群只能发现 1 个节点? 【发布时间】:2021-09-15 09:39:11 【问题描述】:我在 Kubernetes 中部署了 Elasticsearch 7.10.1 集群。 k8s规范的配置如下所示。
我将replicas: 3
配置为有 3 个 pod 作为 3 个节点工作以形成一个 Elasticsearch 集群。我可以看到所有三个节点都在运行。
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
es-0 1/1 Running 0 2m58s
es-1 1/1 Running 0 5m43s
es-2 1/1 Running 0 8m23s
但是 Elasticsearch 只能识别一个节点。以下是_cluster/health
的回复:
"cluster_name" : "elk-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
当我运行 _cat/nodes
时,它只显示 1 个节点。但它每次显示不同的节点名称。所以输出在:
10.0.2.185 38 32 3 0.05 0.48 0.38 cdhilmrstw * es-2
or
10.0.2.220 33 31 2 0.27 0.60 0.31 cdhilmrstw * es-0
or
10.0.1.240 14 96 1 0.04 0.68 0.49 cdhilmrstw * es-1
集群似乎一次只能找到一个节点,并且不断在不同节点之间切换。
如何在 Elasticsearch 上形成 3 个节点?
k8s 规格:
apiVersion: v1
kind: ConfigMap
metadata:
name: es-config
data:
elasticsearch.yml: |
cluster.name: elk-cluster
network.host: "0.0.0.0"
bootstrap.memory_lock: false
discovery.zen.ping.unicast.hosts: elasticsearch-cluster
discovery.zen.minimum_master_nodes: 2
node.max_local_storage_nodes: 9
ES_JAVA_OPTS: -Xms2g -Xmx4g
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: es
namespace: default
spec:
serviceName: es-entrypoint
replicas: 3
selector:
matchLabels:
name: es
template:
metadata:
labels:
name: es
spec:
volumes:
- name: es-config
configMap:
name: es-config
items:
- key: elasticsearch.yml
path: elasticsearch.yml
- name: persistent-storage
persistentVolumeClaim:
claimName: es-claim
initContainers:
- name: permissions-fix
image: busybox
volumeMounts:
- name: persistent-storage
mountPath: /usr/share/elasticsearch/data
command: [ 'chown' ]
args: [ '1000:1000', '/usr/share/elasticsearch/data' ]
containers:
- name: es
image: elasticsearch:7.10.1
resources:
requests:
cpu: 2
memory: 8
ports:
- name: http
containerPort: 9200
- containerPort: 9300
name: inter-node
volumeMounts:
- name: es-config
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
subPath: elasticsearch.yml
- name: persistent-storage
mountPath: /usr/share/elasticsearch/data
---
apiVersion: v1
kind: Service
metadata:
name: es-entrypoint
spec:
selector:
name: es
ports:
- port: 9200
targetPort: 9200
protocol: TCP
clusterIP: None
【问题讨论】:
请检查$ kubectl logs es-0
是否有错误。如果有,也添加错误消息。
【参考方案1】:
这些是 Elasticsearch 6.x 版的发现设置:
discovery.zen.ping.unicast.hosts: elasticsearch-cluster
discovery.zen.minimum_master_nodes: 2
在 7.x 中已弃用。您需要更新您的发现设置:
discovery.seed_hosts:
- es-entrypoint.default.svc # headless service dns
cluster.initial_master_nodes:
- es-0
- es-1
- es-2
【讨论】:
以上是关于为啥 Elasticsearch 集群只能发现 1 个节点?的主要内容,如果未能解决你的问题,请参考以下文章