今天在部署es集群的时候,发现它报了下面这样的一个错误:

uncaught exception in thread [main]
java.lang.IllegalArgumentException: unknown setting [discovery.send_hosts] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
        at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:532)
        at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:477)
        at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:448)
        at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:419)
        at org.elasticsearch.common.settings.SettingsModule.<init>(SettingsModule.java:149)
        at org.elasticsearch.node.Node.<init>(Node.java:356)
        at org.elasticsearch.node.Node.<init>(Node.java:257)
        at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:221)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349)
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
        at org.elasticsearch.cli.Command.main(Command.java:90)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
For complete error details, refer to the log at /usr/share/elasticsearch/logs/my-es.log
{"type": "server", "timestamp": "2022-01-26T08:22:12,982Z", "level": "ERROR", "component": "o.e.b.ElasticsearchUncaughtExceptionHandler", "cluster.name": "my-es", "node.name": "es-master-3", "message": "uncaught exception in thread [main]", 
"stacktrace": ["org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: unknown setting [discovery.send_hosts] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",
"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:174) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.6.2.jar:7.6.2]",
"at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.6.2.jar:7.6.2]",
"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.6.2.jar:7.6.2]",
"Caused by: java.lang.IllegalArgumentException: unknown setting [discovery.send_hosts] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",
"at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:532) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:477) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:448) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:419) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.common.settings.SettingsModule.<init>(SettingsModule.java:149) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.node.Node.<init>(Node.java:356) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.node.Node.<init>(Node.java:257) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.6.2.jar:7.6.2]",
"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.6.2.jar:7.6.2]",
"... 6 more"] }

开始的时候,我以为是JDK的问题,当我在linux上面重新安装了一个JDK之后,发现还是没有解决根本的问题,错误依然存在。后来,我就开始查看自己写的快速部署ES集群的脚本,集群shell脚本如下:

for port in $(seq 1 3); \
do \
mkdir -p /mydata/elasticsearch/master-${port}/config
mkdir -p /mydata/elasticsearch/master-${port}/data
chmod -R 777 /mydata/elasticsearch/master-${port}
cat <<EOF> /mydata/elasticsearch/master-${port}/config/elasticsearch.yml
cluster.name: my-es
node.name: es-master-${port}
node.master: true 
node.data: false 
network.host: 0.0.0.0
http.host: 0.0.0.0 
http.port: 920${port}
transport.tcp.port: 930${port}
discovery.zen.ping_timeout: 10s
discovery.send_hosts: ["172.18.12.21:9301","172.18.12.22:9302","172.18.12.23:9303"]
cluster.initial_master_nodes: ["172.18.12.21"]
EOF
docker run --name elasticsearch-node-${port} \
 -p 920${port}:920${port} -p 930${port}:930${port} \
 --network=mynet --ip 172.18.12.2${port} \
 -e ES_JAVA_OPTS="-Xms300m -Xmx300m" \
 -v /mydata/elasticsearch/master-${port}/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
 -v /mydata/elasticsearch/master-${port}/plugins:/usr/share/elasticsearch/plugins \
 --privileged=true \
 -d elasticsearch:7.6.2
done

发现脚本里面有一个discovery.send_hosts,这个是去设置集群节点IP的,可是错误里面显示又没有这个设置,然后百度了一下,我将discovery.send_hosts替换成了discovery.zen.ping.unicast.hosts,修改之后的脚本如下:

for port in $(seq 1 3); \
do \
mkdir -p /mydata/elasticsearch/master-${port}/config
mkdir -p /mydata/elasticsearch/master-${port}/data
chmod -R 777 /mydata/elasticsearch/master-${port}
cat <<EOF> /mydata/elasticsearch/master-${port}/config/elasticsearch.yml
cluster.name: my-es
node.name: es-master-${port}
node.master: true 
node.data: false 
network.host: 0.0.0.0
http.host: 0.0.0.0 
http.port: 920${port}
transport.tcp.port: 930${port}
discovery.zen.ping_timeout: 10s
discovery.zen.ping.unicast.hosts: ["172.18.12.21:9301","172.18.12.22:9302","172.18.12.23:9303"]
discovery.zen.minimum_master_nodes: 2
cluster.initial_master_nodes: ["172.18.12.21"]
EOF
docker run --name elasticsearch-node-${port} \
 -p 920${port}:920${port} -p 930${port}:930${port} \
 --network=mynet --ip 172.18.12.2${port} \
 -e ES_JAVA_OPTS="-Xms300m -Xmx300m" \
 -v /mydata/elasticsearch/master-${port}/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
 -v /mydata/elasticsearch/master-${port}/plugins:/usr/share/elasticsearch/plugins \
 --privileged=true \
 -d elasticsearch:7.6.2
done

然后我再运行这个脚本,发现成功启动了ES集群。

discovery.seed_hosts是一种新的配置方式,
discovery.zen.ping.unicast.hosts是一种过时的配置方式,可以在 elasticsearch.yml 配置文件中使用discovery.zen.ping.unicast.hosts静态设置设置主机列表。
discovery.zen.ping.unicast.hosts: [“host1”, “host2”]
具体的值是一个主机数组或逗号分隔的字符串。
因为我的shell脚本里面配置的都是写在elasticsearch.yml这个配置文件中,是静态设置的主机列表,故需要使用discovery.zen.ping.unicast.hosts来进行设置。

在调试的过程中,可能需要频繁的创建docker容器或者删除docker容器,现在将调试命令贡献给大家,大家可以按需使用:

批量停止es集群容器:
docker stop $(docker ps -a | grep elasticsearch-node-* | awk ‘{ print $1}’)

批量删除es集群容器:
docker rm $(docker ps -a | grep elasticsearch-node-* | awk ‘{ print $1}’)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐