我通过 docker compose 在本地集群中启动服务。两个docker容器来自elasticsearch的示例。我在 Elasticsearch 的控制台中收到以下错误:
elasticsearch_instance |
{
"@timestamp":"2024-07-11T07:39:09.788Z",
"log.level": "WARN",
"message": "this node is locked into cluster UUID [fxwqYYLsTdy-C7AmpycuLA] but [cluster.initial_master_nodes] is set to [35794ba3f6c5]; remove this setting to avoid possible data loss caused by subsequent cluster bootstrap attempts",
"ecs.version": "1.2.0",
"service.name": "ES_ECS",
"event.dataset": "elasticsearch.server",
"process.thread.name": "main",
"log.logger": "org.elasticsearch.cluster.coordination.ClusterBootstrapService",
"elasticsearch.node.name": "35794ba3f6c5",
"elasticsearch.cluster.name": "docker-cluster"
}
我的 docker-compose.yml 看起来像这样:
elasticsearch:
container_name: "elasticsearch_instance"
image: elasticsearch:8.3.2
environment:
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms1g -Xmx1g
- xpack.security.enabled=false
volumes:
- es_data:/usr/share/elasticsearch/data
- /home/xxx/configs/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
ports:
- 9200:9200
networks:
elastic-network:
aliases:
- myDb
kibana:
image: kibana:8.3.2
ports:
- target: 5601
published: 5601
depends_on:
- elasticsearch
networks:
elastic-network:
driver: bridge
上面的id“35794ba3f6c5”是docker容器的ID。 ID“fxwqYYLsTdy-C7AmpycuLA”似乎是由elasticsearch在每次启动时新创建的。 该警告意味着不应设置 cluster.initial_master_nodes 来解决此警告。但是,我没有在任何地方设置/应用此设置。
我的elasticsearch.yml 看起来像这样:
$ cat /usr/share/elasticsearch/config/elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
xpack.security.enabled: false
有人知道解决方案是否是取消设置 cluster.initial_master_nodes,或者是否有其他解决方案?
我看到的效果是日志不会出现在elasticsearch中,我怀疑这是因为这个警告,因为它告诉我们删除此设置以避免可能的数据丢失。
解决方案是使用以下方法删除所有现有的 docker 容器:
docker 容器修剪
删除
中data文件夹的内容/usr/share/elasticsearch/data
可以通过将“es_data”的名称更改为其他名称(例如“es_data1”)来完成。否则,数据似乎被持久化了。