关于本人在ESC上搭建ElasticSearch单机到集群的踩坑之路

1.安装时踩的坑

1.下载elasticSearch Linux版,在你想存放的地方解压。
2.进入elasticSearch的bin目录下。

[root@localhost bin]# ./elasticsearch
2020-03-01T11:55:32,446][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:140) ~[elasticsearch-6.5.2.jar:6.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.2.jar:6.5.2]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.2.jar:6.5.2]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.2.jar:6.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.2.jar:6.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.2.jar:6.5.2]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.2.jar:6.5.2]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.2.jar:6.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.2.jar:6.5.2]
	... 6 more

3.创建用户并指定密码,因为ES不允许管理原直接运行,可能是出于安全考虑吧。

[root@localhost bin]# useradd jade  -p 123456

4.进入elasticsearch目录的上一级,将elasticsearch目录下的所有权限赋予刚创建的用户。

root@localhost elasticsearch]# cd ..
[root@localhost tools]# ls
elasticsearch
[root@localhost tools]# chown -R jade elasticsearch

5.切换用户。

[root@localhost tools]# su jade

6.修改ip ,修改配置文件。

[jade@localhost elasticsearch]$ cd config/
[jade@localhost config]$ vi elasticsearch.yml 

7.将下面内容的注释部分打开,network.host 修改为0.0.0.0后外网也可以访问到。

network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200

8.保存后,重新启动。

[jade@localhost bin]$ ./elasticsearch

然后就出现下面的错误了。

ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [3780] for user [jade] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-03-01T11:55:32,446][INFO ][o.e.n.Node               ] [PlbSkhz] stopping ...
[2020-03-01T11:55:32,446][INFO ][o.e.n.Node               ] [PlbSkhz] stopped
[2020-03-01T11:55:32,446][INFO ][o.e.n.Node               ] [PlbSkhz] closing ...
[2020-03-01T11:55:32,446][INFO ][o.e.n.Node               ] [PlbSkhz] closed
[2020-03-01T11:55:32,446][INFO ][o.e.x.m.j.p.NativeController] [PlbSkhz] Native controller process has stopped - no new native processes can be started

9.解决办法。
注意这里需要先切换到管理员,然后再修改。

[jade@localhost ~]# su
[root@localhost ~]# su vi /etc/security/limits.conf

在文件的末尾加上,注意修改为刚刚你自己创建的用户名。

jade soft nofile 65536
jade hard nofile 65536
jade soft nproc 4096
jade hard nproc 4096

进入到下面文件夹并修改conf文件,注意conf的格式大致为**–nproc.conf,大部分用户应该都是20-nproc.conf 。

[root@localhost ~]# cd /etc/security/limits.d
[root@localhost limits.d]# vi 20-nproc.conf 
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
*          soft    nproc     4096
root       soft    nproc     unlimited

将上面内容的*号改成用户名,注意修改刚刚你自己创建的用户名。

# See rhbz #432903 for reasoning.
jade   soft    nproc     4096
root       soft    nproc     unlimited

修改下面文件加上内容。

[root@localhost security]# vi /etc/sysctl.conf 
vm.max_map_count = 655360

对于上面的内容让其生效。

[root@localhost security]# sysctl -p

10.然后切换到刚刚创建的用户,再运行一下,还是报错了。

[2020-03-01T11:55:32,446][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-sql]
[2020-03-01T11:55:32,446][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-watcher]
[2020-03-01T11:55:32,447][INFO ][o.e.p.PluginsService     ] [Jade] no plugins loaded
[2020-03-01T11:55:41,922][INFO ][o.e.x.s.a.s.FileRolesStore] [Jade] parsed [0] roles from file [/usr/elasticsearch/config/roles.yml]
[2020-03-01T11:55:43,676][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [Jade] [controller/10385] [Main.cc@110] controller (64 bit): Version 7.2.0 (Build 65aefcbfce449b) Copyright (c) 2019 Elasticsearch BV
[2020-03-01T11:55:44,736][DEBUG][o.e.a.ActionModule       ] [Jade] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2020-03-01T11:55:45,546][INFO ][o.e.d.DiscoveryModule    ] [Jade] using discovery type [zen] and seed hosts providers [settings]
[2020-03-01T11:55:47,497][INFO ][o.e.n.Node               ] [Jade] initialized
[2020-03-01T11:55:47,497][INFO ][o.e.n.Node               ] [Jade] starting ...
[2020-03-01T11:55:47,829][INFO ][o.e.t.TransportService   ] [Jade] publish_address {192.168.0.4:9300}, bound_addresses {[::]:9300}
[2020-03-01T11:55:47,851][INFO ][o.e.b.BootstrapChecks    ] [Jade] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2020-03-01T11:55:47,903][INFO ][o.e.n.Node               ] [Jade] stopping ...
[2020-03-01T11:55:47,929][INFO ][o.e.n.Node               ] [Jade] stopped
[2020-03-01T11:55:47,929][INFO ][o.e.n.Node               ] [Jade] closing ...
[2020-03-01T11:55:47,965][INFO ][o.e.n.Node               ] [Jade] closed
[2020-03-01T11:55:47,968][INFO ][o.e.x.m.p.NativeController] [Jade] Native controller process has stopped - no new native processes can be started

解决方法:修改conf的elasticsearch.yml配置文件,在Discovery栏下加上。“cluster.initial_master_nodes: [“node-1”]”,重启elasticsearch即可。

# --------------------------------- Discovery ----------------------------------
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]

保存后启动成功啦(其实这里有个坑,下边会提到)。

[2020-03-01T12:07:29,500][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-ilm]
[2020-03-01T12:07:29,500][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-logstash]
[2020-03-01T12:07:29,501][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-ml]
[2020-03-01T12:07:29,501][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-monitoring]
[2020-03-01T12:07:29,501][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-rollup]
[2020-03-01T12:07:29,501][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-security]
[2020-03-01T12:07:29,502][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-sql]
[2020-03-01T12:07:29,502][INFO ][o.e.p.PluginsService     ] [Jade] loaded module [x-pack-watcher]
[2020-03-01T12:07:29,503][INFO ][o.e.p.PluginsService     ] [Jade] no plugins loaded
[2020-03-01T12:07:40,363][INFO ][o.e.x.s.a.s.FileRolesStore] [Jade] parsed [0] roles from file [/usr/elasticsearch/config/roles.yml]
[2020-03-01T12:07:42,185][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [Jade] [controller/11155] [Main.cc@110] controller (64 bit): Version 7.2.0 (Build 65aefcbfce449b) Copyright (c) 2019 Elasticsearch BV
[2020-03-01T12:07:43,183][DEBUG][o.e.a.ActionModule       ] [Jade] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2020-03-01T12:07:44,021][INFO ][o.e.d.DiscoveryModule    ] [Jade] using discovery type [zen] and seed hosts providers [settings]
[2020-03-01T12:07:46,127][INFO ][o.e.n.Node               ] [Jade] initialized
[2020-03-01T12:07:46,128][INFO ][o.e.n.Node               ] [Jade] starting ...
[2020-03-01T12:07:46,381][INFO ][o.e.t.TransportService   ] [Jade] publish_address {192.168.0.4:9300}, bound_addresses {[::]:9300}
[2020-03-01T12:07:46,402][INFO ][o.e.b.BootstrapChecks    ] [Jade] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2020-03-01T12:07:46,479][INFO ][o.e.c.c.Coordinator      ] [Jade] cluster UUID [mQQYVuHqQ_SiZZloBBfsvg]
[2020-03-01T12:07:46,798][INFO ][o.e.c.s.MasterService    ] [Jade] elected-as-master ([1] nodes joined)[{Jade}{5EaYA7RnThWOtA18NVkc-A}{nqRqtrHlRVK4WiBDyEgkCQ}{192.168.0.4}{192.168.0.4:9300}{ml.machine_memory=2096062464, xpack.installed=true, ml.max_open_jobs=20} elect leader, _BECOME_MASTER_TASK_, _FINISH_ELECTION_], term: 2, version: 18, reason: master node changed {previous [], current [{Jade}{5EaYA7RnThWOtA18NVkc-A}{nqRqtrHlRVK4WiBDyEgkCQ}{192.168.0.4}{192.168.0.4:9300}{ml.machine_memory=2096062464, xpack.installed=true, ml.max_open_jobs=20}]}
[2020-03-01T12:07:47,060][INFO ][o.e.c.s.ClusterApplierService] [Jade] master node changed {previous [], current [{Jade}{5EaYA7RnThWOtA18NVkc-A}{nqRqtrHlRVK4WiBDyEgkCQ}{192.168.0.4}{192.168.0.4:9300}{ml.machine_memory=2096062464, xpack.installed=true, ml.max_open_jobs=20}]}, term: 2, version: 18, reason: Publication{term=2, version=18}
[2020-03-01T12:07:47,370][INFO ][o.e.h.AbstractHttpServerTransport] [Jade] publish_address {192.168.0.4:9200}, bound_addresses {[::]:9200}
[2020-03-01T12:07:47,371][INFO ][o.e.n.Node               ] [Jade] started
[2020-03-01T12:07:47,839][INFO ][o.e.l.LicenseService     ] [Jade] license [c7d4e9ae-3e42-4f7b-ba62-ae9cfce93373] mode [basic] - valid
[2020-03-01T12:07:47,866][INFO ][o.e.g.GatewayService     ] [Jade] recovered [1] indices into cluster_state
[2020-03-01T12:07:48,626][INFO ][o.e.c.r.a.AllocationService] [Jade] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[nba][0]] ...]).

2.在入门实践时踩的坑

1.使用PostMan创建索引的时候,PUT方法创建索引等了好久还是报错了。
解决办法: 其实这就是上边我们留下的Bug。我们指定了一个节点名,但是我们随便填了个node-1,然而node-1并不是我们的主机名,还有就是我们没有指定这些节点的ip。本来我们是搭建一个单机模式,也就是本机就是唯一的节点,即本机名就是节点名,127.0.0.1就是节点ip。

[jade@Jade config]$ hostname
Jade
[jade@Jade config]$ vim elasticsearch.yml

修改配置文件。

# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["127.0.0.1"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["Jade"]
#
# For more information, consult the discovery and cluster formation module documentation.

生命不息,学习不止!

学习中,欢迎加我QQ一起讨论问题!!!

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42091436/article/details/104589142
今日推荐