Regarding my way of building a single ElasticSearch on ESC to a cluster

1. The pit stepped on during installation

1. Download the elasticSearch Linux version and unzip it where you want to store it.
2. Enter the bin directory of elasticSearch.

[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. Create a user and specify a password, because ES does not allow management to run directly, it may be for security reasons.

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

4. Go to the upper level of the elasticsearch directory and assign all permissions under the elasticsearch directory to the newly created user.

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

5. Switch users.

[root@localhost tools]# su jade

6. Modify ip, modify the configuration file.

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

7. Open the comment part of the following content, network.host can also be accessed after modifying the network.host to 0.0.0.0.

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

8. After saving, restart.

[jade@localhost bin]$ ./elasticsearch

Then the following error occurred.

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. The solution.
Note that you need to switch to the administrator first, and then modify it.

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

Add it at the end of the file, and make sure to change it to the username you just created.

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

Enter the following folder and modify the conf file. Note that the format of conf is roughly **–nproc.conf, and most users should be 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

Change the * in the above content to the user name, pay attention to modify the user name you just created.

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

Modify the following file and add content.

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

Let it take effect for the above content.

[root@localhost security]# sysctl -p

10. Then switch to the user you just created, run it again, and still get an error.

[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

Solution: Modify the elasticsearch.yml configuration file of conf and add it under the Discovery column. "Cluster.initial_master_nodes: ["node-1"]", just restart 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"]

After saving, the startup is successful (in fact, there is a pit here, which will be mentioned below).

[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. The pits stepped on when starting to practice

1. When using PostMan to create an index, the PUT method created an index after waiting for a long time and still reported an error.
Solution: In fact, this is the bug we left above. We specified a node name, but we randomly filled in node-1, but node-1 is not our host name, and we did not specify the ip of these nodes. Originally, we were building a stand-alone mode, that is, the machine is the only node, that is, the name of the machine is the node name, and 127.0.0.1 is the node ip.

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

Modify the configuration file.

# --------------------------------- 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.

Life is endless, and learning is endless!

While studying, welcome to join me in QQ to discuss issues together! ! !

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42091436/article/details/104589142