配置Elasticsearch 7集群

时间:2019-05-25 04:50:48

标签: elasticsearch

我有三台服务器,并且在所有服务器上都安装了elasticsearch。

在elasticsearch.yml中,我具有以下配置:

第一台服务器:172.31.1.1

# /etc/elasticsearch/elasticsearch.yml
cluster.name: es-cluster
node.name: es-1
network.host: 172.31.1.1
http.port: 9200
network.host:
discovery.seed_hosts: ["172.31.1.1", "172.31.1.2", "172.31.1.3"]
cluster.initial_master_nodes:["es-1", "es-2", "es-3"]

gateway.recover_after_nodes: 2
gateway.expected_nodes: 3
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
# some more default values

第二台服务器:172.31.1.2

node.name: es-2
network.host: 172.31.1.2
# everything else same as first server

第二台服务器:172.31.1.3

node.name: es-3
network.host: 172.31.1.3
# everything else same as first server

现在,当我跑步时:curl http://es-1:9200/_cluster/stats

我注意到群集大小为1。如果在不同的服务器上运行相同的curl命令,则群集大小再次为1,cluster_name相同,但是cluster_uuid不同...

似乎节点之间无法相互连接...


我正在使用Ubuntu服务器,对于节点名,我编辑了/ etc / hostname并将主机名更改为 es-1,并在elasticsearch.yml中使用了相同的名称...但是看来群集节点无法相互通信...


更新1

curl http://es-1:9200/_cat/health
prod-es-cluster red 1 1 0 0 0 0 0 0 - NaN%

curl http://es-1/:9200/_cat/nodes
172.31.1.1 8 38 1 0.03 0.03 0.00 mdi * ip-172-31-1-1

我只是检查日志,这很奇怪...

sudo cat /var/log/elasticsearch/elasticsearch.log
[INFO ][o.e.n.Node               ] [es-1] stopping ...
[INFO ][o.e.x.w.WatcherService   ] [es-1] stopping watch service, reason [shutdown initiated]
[INFO ][o.e.x.m.p.l.CppLogMessageHandler] [es-1] [controller/19159] [Main.cc@148] Ml controller exiting
[INFO ][o.e.x.m.p.NativeController] [es-1] Native controller process has stopped - no new native processes can be started
[INFO ][o.e.n.Node               ] [es-1] stopped
[INFO ][o.e.n.Node               ] [es-1] closing ...
[INFO ][o.e.n.Node               ] [es-1] closed

全部写入日志文件...重新启动Elasticsearch之后,没有新内容添加到日志文件...感觉就像我在读取错误的日志文件或将配置放入错误的.yml中文件

更新2

这是我启动服务的方式:

sudo /bin/systemctl enable elasticsearch.service

更新3

正如@hamidbayat指出的那样,我认为存在许可问题。只有超级用户有权使用/ var / lib / elasticsearch

如果我尝试以ubuntu用户身份运行弹性搜索,则会出现此错误:

ubuntu@my-ip:~$ /usr/share/elasticsearch/bin/elasticsearch
/usr/share/elasticsearch/bin/elasticsearch-env: line 73: 
/etc/default/elasticsearch: Permission denied

如果我尝试以root身份运行它,则会收到此错误:

ubuntu@myip:~$ sudo /usr/share/elasticsearch/bin/elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[data][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [es-1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.1.0.jar:7.1.0]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.1.0.jar:7.1.0]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.1.0.jar:7.1.0]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.1.0.jar:7.1.0]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.1.0.jar:7.1.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.1.0.jar:7.1.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.1.0.jar:7.1.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:102) ~[elasticsearch-7.1.0.jar:7.1.0]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:169) ~[elasticsearch-7.1.0.jar:7.1.0]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:325) ~[elasticsearch-7.1.0.jar:7.1.0]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.1.0.jar:7.1.0]
        ... 6 more

2 个答案:

答案 0 :(得分:0)

这是我解决问题的方法:

  1. 我正在读elasticsearch.log,以为我没有在日志文件中得到任何东西,但是意识到日志正在写入cluster-name.log(在我的情况下是es-cluster.log

  2. 我在http.port: 9200中注释了elasticsearch.yml,我相信Elasticsearch默认使用9300。

  3. 我从discovery.seed_hosts:删除了该节点自己的ip,所以只有其他节点被添加到该列表中,例如对于第一台服务器,我有:

    discovery.seed_hosts: ["172.31.1.2", "172.31.1.3"]

  4. 我意识到每个节点都形成了自己的集群,这就是为什么它们没有加入同一集群的原因。所以我不得不合并集群。由于群集中没有数据,因此可以选择删除数据路径。因此,我让节点1运行,并停止了节点2和3上的elasticsearch。然后删除了节点2和3上的数据路径(在我的情况下,数据路径为/var/lib/elasticsearch/)。然后启动节点2和3,它们加入了集群。

答案 1 :(得分:0)

您需要配置引导检查,在6.x中它会引发警告

对于7.x版本,必须配置引导程序

bootstrap.system_call_filter:错误,请添加此尝试开始