Elastic Stack之 Elasticsearch 6.7.1版本单机版安装、集群版安装

2021-01-13 10:45:34 浏览数 (1)

1、截至目前Elasticsearch 版本已经更新到了7.10.1版本了,这里先使用Elasticsearch 6.7.1版本,给一个下载地址,如下所示:

官方下载地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch

如果你只是找到了最新版本的下载地址,却不知道历史版本如何下载,只要点击下面的即可:

2、由于Elasticsearch是Java开发的,所以需要安装Jdk的,这里安装jdk-8u271-linux-x64.tar.gz。

注意:安装elasticsearch之前安装好java,因为elasticsearch是Java语言开发的,注意选择Java的版本是1.8.0的第20版本以后的,第20之前的会出现很多问题。

代码语言:javascript复制
1 [root@k8s-master package]# tar zxvf jdk-8u271-linux-x64.tar.gz -C /usr/local/soft/

然后配置到环境变量中,如下所示:

代码语言:javascript复制
1 [root@k8s-master soft]# 
2 [root@k8s-master soft]# vim /etc/profile
3 [root@k8s-master soft]# source /etc/profile

配置环境变量,内容,如下所示:

然后开始安装单节点的 Elasticsearch 6.7.1版本,如下所示:

代码语言:javascript复制
1 [root@k8s-master package]# tar -zxvf elasticsearch-6.7.1.tar.gz -C /usr/local/soft/

解压缩之后,使用./bin/elasticsearch进行运行,发现报错了,Elasticsearch 不支持使用root进行启动,所以需要创建一个Elasticsearch 的账号,如下所示:

代码语言:javascript复制
 1 [root@k8s-master soft]# cd elasticsearch-6.7.1/
 2 [root@k8s-master elasticsearch-6.7.1]# 
 3 [root@k8s-master elasticsearch-6.7.1]# 
 4 [root@k8s-master elasticsearch-6.7.1]# ls
 5 bin  config  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.textile
 6 [root@k8s-master elasticsearch-6.7.1]# ./bin/elasticsearch
 7 [2021-01-09T17:19:19,506][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
 8 org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
 9     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.7.1.jar:6.7.1]
10     at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.7.1.jar:6.7.1]
11     at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.7.1.jar:6.7.1]
12     at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.7.1.jar:6.7.1]
13     at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.7.1.jar:6.7.1]
14     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.7.1.jar:6.7.1]
15     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.7.1.jar:6.7.1]
16 Caused by: java.lang.RuntimeException: can not run elasticsearch as root
17     at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.7.1.jar:6.7.1]
18     at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.7.1.jar:6.7.1]
19     at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.7.1.jar:6.7.1]
20     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.7.1.jar:6.7.1]
21     ... 6 more
22 [root@k8s-master elasticsearch-6.7.1]# 

创建elsearch组和elsearch用户,然后将刚才解压缩的授权给新创建的用户,如下所示:

代码语言:javascript复制
 1 [root@k8s-master elasticsearch-6.7.1]# groupadd elsearch
 2 [root@k8s-master elasticsearch-6.7.1]# useradd elsearch -g elsearch
 3 [root@k8s-master elasticsearch-6.7.1]# passwd elsearch
 4 Changing password for user elsearch.
 5 New password:
 6 BAD PASSWORD: The password contains the user name in some form
 7 Retype new password:
 8 passwd: all authentication tokens updated successfully.
 9 [root@k8s-master elasticsearch-6.7.1]# cd /usr/local/soft/
10 [root@slaver4 soft]# ls
11 elasticsearch-6.7.1
12 [root@slaver4 soft]# chown -R elsearch:elsearch elasticsearch-6.7.1/
13 [root@slaver4 soft]# su elsearch
14 [elsearch@slaver4 soft]$ ls
15 elasticsearch-6.7.1
16 [elsearch@slaver4 soft]$ cd elasticsearch-6.7.1/
17 [elsearch@slaver4 elasticsearch-6.7.1]$ ls
18 bin  config  data  hs_err_pid11491.log  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.textile

此时,启动elasticsearch,如下所示:

代码语言:javascript复制
 1 [elsearch@k8s-master elasticsearch-6.7.1]$ ./bin/elasticsearch
 2 [2021-01-09T17:27:31,756][INFO ][o.e.e.NodeEnvironment    ] [5q5VHg0] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [3gb], net total_space [17.7gb], types [rootfs]
 3 [2021-01-09T17:27:31,764][INFO ][o.e.e.NodeEnvironment    ] [5q5VHg0] heap size [1007.3mb], compressed ordinary object pointers [true]
 4 [2021-01-09T17:27:31,769][INFO ][o.e.n.Node               ] [5q5VHg0] node name derived from node ID [5q5VHg0JSpawCOXUgpsQ3w]; set [node.name] to override
 5 [2021-01-09T17:27:31,770][INFO ][o.e.n.Node               ] [5q5VHg0] version[6.7.1], pid[101788], build[default/tar/2f32220/2019-04-02T15:59:27.961366Z], OS[Linux/3.10.0-957.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_271/25.271-b09]
 6 [2021-01-09T17:27:31,770][INFO ][o.e.n.Node               ] [5q5VHg0] JVM arguments [-Xms1g, -Xmx1g, -XX: UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX: UseCMSInitiatingOccupancyOnly, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX: AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch-3395773329025720144, -XX: HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX: PrintGCDetails, -XX: PrintGCDateStamps, -XX: PrintTenuringDistribution, -XX: PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX: UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/usr/local/soft/elasticsearch-6.7.1, -Des.path.conf=/usr/local/soft/elasticsearch-6.7.1/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
 7 [2021-01-09T17:27:39,562][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [aggs-matrix-stats]
 8 [2021-01-09T17:27:39,563][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [analysis-common]
 9 [2021-01-09T17:27:39,563][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [ingest-common]
10 [2021-01-09T17:27:39,563][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [ingest-geoip]
11 [2021-01-09T17:27:39,563][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [ingest-user-agent]
12 [2021-01-09T17:27:39,564][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [lang-expression]
13 [2021-01-09T17:27:39,564][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [lang-mustache]
14 [2021-01-09T17:27:39,564][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [lang-painless]
15 [2021-01-09T17:27:39,564][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [mapper-extras]
16 [2021-01-09T17:27:39,566][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [parent-join]
17 [2021-01-09T17:27:39,566][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [percolator]
18 [2021-01-09T17:27:39,566][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [rank-eval]
19 [2021-01-09T17:27:39,567][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [reindex]
20 [2021-01-09T17:27:39,567][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [repository-url]
21 [2021-01-09T17:27:39,567][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [transport-netty4]
22 [2021-01-09T17:27:39,567][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [tribe]
23 [2021-01-09T17:27:39,567][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-ccr]
24 [2021-01-09T17:27:39,567][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-core]
25 [2021-01-09T17:27:39,568][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-deprecation]
26 [2021-01-09T17:27:39,568][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-graph]
27 [2021-01-09T17:27:39,568][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-ilm]
28 [2021-01-09T17:27:39,568][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-logstash]
29 [2021-01-09T17:27:39,568][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-ml]
30 [2021-01-09T17:27:39,568][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-monitoring]
31 [2021-01-09T17:27:39,568][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-rollup]
32 [2021-01-09T17:27:39,569][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-security]
33 [2021-01-09T17:27:39,569][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-sql]
34 [2021-01-09T17:27:39,569][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-upgrade]
35 [2021-01-09T17:27:39,570][INFO ][o.e.p.PluginsService     ] [5q5VHg0] loaded module [x-pack-watcher]
36 [2021-01-09T17:27:39,571][INFO ][o.e.p.PluginsService     ] [5q5VHg0] no plugins loaded
37 [2021-01-09T17:27:55,845][INFO ][o.e.x.s.a.s.FileRolesStore] [5q5VHg0] parsed [0] roles from file [/usr/local/soft/elasticsearch-6.7.1/config/roles.yml]
38 [2021-01-09T17:27:59,193][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [5q5VHg0] [controller/102054] [Main.cc@109] controller (64 bit): Version 6.7.1 (Build e1f492de67a719) Copyright (c) 2019 Elasticsearch BV
39 [2021-01-09T17:28:02,594][DEBUG][o.e.a.ActionModule       ] [5q5VHg0] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
40 [2021-01-09T17:28:04,283][INFO ][o.e.d.DiscoveryModule    ] [5q5VHg0] using discovery type [zen] and host providers [settings]
41 [2021-01-09T17:28:09,793][INFO ][o.e.n.Node               ] [5q5VHg0] initialized
42 [2021-01-09T17:28:09,796][INFO ][o.e.n.Node               ] [5q5VHg0] starting ...
43 [2021-01-09T17:28:10,677][INFO ][o.e.t.TransportService   ] [5q5VHg0] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
44 [2021-01-09T17:28:14,198][INFO ][o.e.c.s.MasterService    ] [5q5VHg0] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {5q5VHg0}{5q5VHg0JSpawCOXUgpsQ3w}{lznczxGjR4WwoMNwfzimaA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=2398703616, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
45 [2021-01-09T17:28:14,245][INFO ][o.e.c.s.ClusterApplierService] [5q5VHg0] new_master {5q5VHg0}{5q5VHg0JSpawCOXUgpsQ3w}{lznczxGjR4WwoMNwfzimaA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=2398703616, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {5q5VHg0}{5q5VHg0JSpawCOXUgpsQ3w}{lznczxGjR4WwoMNwfzimaA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=2398703616, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
46 [2021-01-09T17:28:14,657][INFO ][o.e.h.n.Netty4HttpServerTransport] [5q5VHg0] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
47 [2021-01-09T17:28:14,657][INFO ][o.e.n.Node               ] [5q5VHg0] started
48 [2021-01-09T17:28:14,862][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [5q5VHg0] Failed to clear cache for realms [[]]
49 [2021-01-09T17:28:15,165][INFO ][o.e.g.GatewayService     ] [5q5VHg0] recovered [0] indices into cluster_state
50 [2021-01-09T17:28:16,295][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.triggered_watches] for index patterns [.triggered_watches*]
51 [2021-01-09T17:28:16,613][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.watches] for index patterns [.watches*]
52 [2021-01-09T17:28:16,909][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.watch-history-9] for index patterns [.watcher-history-9*]
53 [2021-01-09T17:28:17,036][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*]
54 [2021-01-09T17:28:17,230][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.monitoring-es] for index patterns [.monitoring-es-6-*]
55 [2021-01-09T17:28:17,326][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*]
56 [2021-01-09T17:28:17,404][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]
57 [2021-01-09T17:28:17,492][INFO ][o.e.c.m.MetaDataIndexTemplateService] [5q5VHg0] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]
58 [2021-01-09T17:28:17,795][INFO ][o.e.l.LicenseService     ] [5q5VHg0] license [1c2bca2b-217b-4d20-86ca-8fd95402ae06] mode [basic] - valid

elasticsearch在后台启动如下所示,可以使用命令查看启动进程信息,如下所示:

代码语言:javascript复制
 1 [elsearch@k8s-master elasticsearch-6.7.1]$ ./bin/elasticsearch -d
 2 [elsearch@k8s-master elasticsearch-6.7.1]$ jps
 3 105528 Elasticsearch
 4 105581 Jps
 5 [elsearch@k8s-master elasticsearch-6.7.1]$ 
 6 [elsearch@k8s-master elasticsearch-6.7.1]$ 
 7 [elsearch@k8s-master elasticsearch-6.7.1]$ ps -ef | grep elasticsearch
 8 elsearch 105528      1 99 17:31 pts/6    00:00:30 /usr/local/soft/jdk1.8.0_271/bin/java -Xms1g -Xmx1g -XX: UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX: UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX: AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-1175646808970020260 -XX: HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX: PrintGCDetails -XX: PrintGCDateStamps -XX: PrintTenuringDistribution -XX: PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX: UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/usr/local/soft/elasticsearch-6.7.1 -Des.path.conf=/usr/local/soft/elasticsearch-6.7.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /usr/local/soft/elasticsearch-6.7.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
 9 elsearch 105639 105528  0 17:31 pts/6    00:00:00 /usr/local/soft/elasticsearch-6.7.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
10 elsearch 105821 100518  0 17:32 pts/6    00:00:00 grep --color=auto elasticsearch
11 [elsearch@k8s-master elasticsearch-6.7.1]$ 
12 [elsearch@k8s-master elasticsearch-6.7.1]$ ps -aux | grep elasticsearch
13 elsearch 105528  165 53.9 3629064 1264608 pts/6 Sl   17:31   0:56 /usr/local/soft/jdk1.8.0_271/bin/java -Xms1g -Xmx1g -XX: UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX: UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX: AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-1175646808970020260 -XX: HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX: PrintGCDetails -XX: PrintGCDateStamps -XX: PrintTenuringDistribution -XX: PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX: UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/usr/local/soft/elasticsearch-6.7.1 -Des.path.conf=/usr/local/soft/elasticsearch-6.7.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /usr/local/soft/elasticsearch-6.7.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
14 elsearch 105639  0.1  0.2  72136  5116 pts/6    Sl   17:31   0:00 /usr/local/soft/elasticsearch-6.7.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
15 elsearch 106022  0.0  0.0 112708   992 pts/6    R    17:32   0:00 grep --color=auto elasticsearch
16 [elsearch@k8s-master elasticsearch-6.7.1]$ 

使用curl localhost:9200可以看到访问成功了。也说明你的ElasticSearch启动成功了。

代码语言:javascript复制
 1 [elsearch@k8s-master elasticsearch-6.7.1]$ curl localhost:9200
 2 {
 3   "name" : "5q5VHg0",
 4   "cluster_name" : "elasticsearch",
 5   "cluster_uuid" : "0eaX1noKQC-BzqO3PZ5j2A",
 6   "version" : {
 7     "number" : "6.7.1",
 8     "build_flavor" : "default",
 9     "build_type" : "tar",
10     "build_hash" : "2f32220",
11     "build_date" : "2019-04-02T15:59:27.961366Z",
12     "build_snapshot" : false,
13     "lucene_version" : "7.7.0",
14     "minimum_wire_compatibility_version" : "5.6.0",
15     "minimum_index_compatibility_version" : "5.0.0"
16   },
17   "tagline" : "You Know, for Search"
18 }
19 [elsearch@k8s-master elasticsearch-6.7.1]$ 

外网访问,在防火墙开启9200端口命令。或者直接禁掉防火墙,如果本地学习的话。外网还无法访问的话就需要改下配置文件了。

代码语言:javascript复制
1 [elsearch@k8s-master soft]$ systemctl status firewalld
2 ● firewalld.service - firewalld - dynamic firewall daemon
3    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
4    Active: inactive (dead)
5      Docs: man:firewalld(1)
6 [elsearch@k8s-master soft]$ 
7 [elsearch@k8s-master soft]$ 
8 [elsearch@k8s-master soft]$ 

关于Centos7的防火墙知识,如下所示:

代码语言:javascript复制
 1 1、查看firewall服务状态
 2 systemctl status firewalld
 3 
 4 2、查看firewall的状态
 5 firewall-cmd --state
 6 
 7 3、开启、重启、关闭、firewalld.service服务
 8 # 开启
 9 service firewalld start
10 # 重启
11 service firewalld restart
12 # 关闭
13 service firewalld stop
14 
15 4、查看防火墙规则
16 firewall-cmd --list-all 
17 
18 
19 5、查询、开放、关闭端口
20 # 查询端口是否开放
21 firewall-cmd --query-port=8080/tcp
22 # 开放80端口
23 firewall-cmd --permanent --add-port=80/tcp
24 # 移除端口
25 firewall-cmd --permanent --remove-port=8080/tcp
26 
27 
28 #重启防火墙(修改配置后要重启防火墙)
29 firewall-cmd --reload
30 
31 # 参数解释
32 1、firwall-cmd:是Linux提供的操作firewall的一个工具;
33 2、--permanent:表示设置为持久;
34 3、--add-port:标识添加的端口;

修改elasticsearch下面的config/elasticsearch.yml文件,network.host: 0.0.0.0

代码语言:javascript复制
1 [elsearch@k8s-master elasticsearch-6.7.1]$ ls
2 bin  config  data  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.textile
3 [elsearch@k8s-master elasticsearch-6.7.1]$ cd config/
4 [elsearch@k8s-master config]$ ls
5 elasticsearch.keystore  elasticsearch.yml  jvm.options  log4j2.properties  role_mapping.yml  roles.yml  users  users_roles
6 [elsearch@k8s-master config]$ vim elasticsearch.yml 
7 [elsearch@k8s-master config]$ 

此时启动elasticsearch,curl 服务器的ip地址加端口还是localhos加端口,都可以正常返回信息,如下所示:

代码语言:javascript复制
 1 [elsearch@k8s-master soft]$ curl localhost:9200
 2 {
 3   "name" : "5q5VHg0",
 4   "cluster_name" : "elasticsearch",
 5   "cluster_uuid" : "0eaX1noKQC-BzqO3PZ5j2A",
 6   "version" : {
 7     "number" : "6.7.1",
 8     "build_flavor" : "default",
 9     "build_type" : "tar",
10     "build_hash" : "2f32220",
11     "build_date" : "2019-04-02T15:59:27.961366Z",
12     "build_snapshot" : false,
13     "lucene_version" : "7.7.0",
14     "minimum_wire_compatibility_version" : "5.6.0",
15     "minimum_index_compatibility_version" : "5.0.0"
16   },
17   "tagline" : "You Know, for Search"
18 }
19 [elsearch@k8s-master soft]$ curl 192.168.110.133:9200
20 {
21   "name" : "5q5VHg0",
22   "cluster_name" : "elasticsearch",
23   "cluster_uuid" : "0eaX1noKQC-BzqO3PZ5j2A",
24   "version" : {
25     "number" : "6.7.1",
26     "build_flavor" : "default",
27     "build_type" : "tar",
28     "build_hash" : "2f32220",
29     "build_date" : "2019-04-02T15:59:27.961366Z",
30     "build_snapshot" : false,
31     "lucene_version" : "7.7.0",
32     "minimum_wire_compatibility_version" : "5.6.0",
33     "minimum_index_compatibility_version" : "5.0.0"
34   },
35   "tagline" : "You Know, for Search"
36 }
37 [elsearch@k8s-master soft]$ 

也可以使用浏览器,输入请求地址进行访问,如下所示:

3、Elasticsearch配置说明,配置文件位于config目录中,其中elasticsearch.yml是es的相关参数的配置,jvm.options是jvm相关参数的配置,log4j2.properties日志相关的配置。

Development开发者模式与Production生产环境模式说明。

  1)、以transport的地址是否绑定在localhost(127.0.0.1)为判断标准network.host。   2)、Development模式下在启动时会以warning的方式提示配置检查异常。   3)、Production模式下在启动时会以error的方式提示配置检查异常并退出。

代码语言:javascript复制
  1 # ======================== Elasticsearch Configuration =========================
  2 #
  3 # NOTE: Elasticsearch comes with reasonable defaults for most settings.
  4 #       Before you set out to tweak and tune the configuration, make sure you
  5 #       understand what are you trying to accomplish and the consequences.
  6 #
  7 # The primary way of configuring a node is via this file. This template lists
  8 # the most important settings you may want to configure for a production cluster.
  9 #
 10 # Please consult the documentation for further information on configuration options:
 11 # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
 12 #
 13 # ---------------------------------- Cluster -----------------------------------
 14 #
 15 # Use a descriptive name for your cluster:
 16 #
 17 
 18 # 1、修改这里,是修改集群的名称,如果想将节点加入到集群中,所有节点都必须是这个名称的。
 19 # 集群名称,以此作为是否同一个集群的判断条件。
 20 # cluster.name: my-application
 21 
 22 
 23 #
 24 # ------------------------------------ Node ------------------------------------
 25 #
 26 # Use a descriptive name for the node:
 27 #
 28 
 29 # 2、给节点起一个名称。默认node-1,以此作为集群中不同节点的区分条件。
 30 #node.name: node-1
 31 
 32 
 33 #
 34 # Add custom attributes to the node:
 35 #
 36 #node.attr.rack: r1
 37 #
 38 # ----------------------------------- Paths ------------------------------------
 39 #
 40 # Path to directory where to store the data (separate multiple locations by comma):
 41 #
 42 
 43 # 3、path.data是存储的数据的路径。数据存储地址。
 44 #path.data: /path/to/data
 45 
 46 
 47 #
 48 # Path to log files:
 49 #
 50 
 51 # 4、path.logs是es运行产生的日志文件。日志存储地址。
 52 #path.logs: /path/to/logs
 53 
 54 
 55 #
 56 # ----------------------------------- Memory -----------------------------------
 57 #
 58 # Lock the memory on startup:
 59 #
 60 #bootstrap.memory_lock: true
 61 #
 62 # Make sure that the heap size is set to about half the memory available
 63 # on the system and that the owner of the process is allowed to use this
 64 # limit.
 65 #
 66 # Elasticsearch performs poorly when the system is swapping the memory.
 67 #
 68 # ---------------------------------- Network -----------------------------------
 69 #
 70 # Set the bind address to a specific IP (IPv4 or IPv6):
 71 #
 72 #network.host: 192.168.0.1
 73 
 74 # 5、绑定的ip地址和默认端口号9200。network.host/http.port网络地址和端口,用于http和transport服务使用。
 75 # network.host: 0.0.0.0
 76 
 77 
 78 
 79 # 下面这些配置是我自己加的,上面或者下面标数字的都是默认的。
 80 
 81 # 是否支持跨域
 82 http.cors.enabled: true
 83 #
 84 # *表示支持所有域名
 85 http.cors.allow-origin: "*"
 86 
 87 # 指定集群的名称
 88 cluster.name: biehl01
 89 # 给master起一个名称,叫master
 90 node.name: master
 91 # 告诉此节点,它就是master
 92 node.master: true
 93 # 绑定的ip地址和默认端口号9200
 94 network.host: 192.168.110.133
 95 
 96 discovery.zen.minimum_master_nodes: 2
 97 discovery.zen.ping.unicast.hosts: ["192.168.110.133"]
 98 
 99 
100 #
101 # Set a custom port for HTTP:
102 #
103 
104 # 6、默认端口号是9200的。
105 # http.port: 9200
106 
107 
108 
109 # 7、Discovery服务发现,配置集群的话,是需要进行修改的。
110 
111 
112 #
113 # For more information, consult the network module documentation.
114 #
115 # --------------------------------- Discovery ----------------------------------
116 #
117 # Pass an initial list of hosts to perform discovery when new node is started:
118 # The default list of hosts is ["127.0.0.1", "[::1]"]
119 #
120 
121 # 8、集群里面的节点都需要加到里面,如果是伪集群的话,可以使用ip:端口号或者主机名称的形式加进去的,如果是非伪集群,可以直接使用ip:port或者主机名称加进去。
122 # 注意,这里面加的主机节点,是有机会进行选举主节点的,其他未加进去,没有机会进行选择主节点的机会的。
123 #discovery.zen.ping.unicast.hosts: ["host1", "host2"]
124 #
125 # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2   1):
126 #
127 
128 # 9、主节点数/ 2   1,此值是这样计算的,上面的注释也说明了。此值是为了阻止没有节点做主节点或者都做子节点的情况发生。避免出现脑裂。
129 # 默认值是3,这样才可以选出主节点的。那么这就需要注意了,你的主节点数至少是4的,不然无法正常选举。通过配置这个参数来防止集群脑裂现象 (集群总节点数量/2) 1
130 #discovery.zen.minimum_master_nodes: 3
131 
132 
133 #
134 # For more information, consult the zen discovery module documentation.
135 #
136 
137 
138 
139 # ---------------------------------- Gateway -----------------------------------
140 #
141 # Block initial recovery after a full cluster restart until N nodes are started:
142 #
143 #gateway.recover_after_nodes: 3
144 #
145 # For more information, consult the gateway module documentation.
146 #
147 # ---------------------------------- Various -----------------------------------
148 #
149 # Require explicit names when deleting indices:
150 #
151 #action.destructive_requires_name: true

4、 Elasticsearch 6.7.1版本集群版安装,首先将刚才安装的jdk安装包,elasticsearch安装包传输到另外两个节点上面,这里没有配置免密登录,需要自己输入密码,如下所示:

环境配置:三台CentOS Linux release 7.6.1810 (Core),64位操作系统,主节点分配2.5G内存,两个从节点分配2G内存。

代码语言:javascript复制
 1 [root@k8s-master package]# scp -r jdk-8u271-linux-x64.tar.gz elasticsearch-6.7.1.tar.gz 192.168.110.134:/usr/local/package/
 2 The authenticity of host '192.168.110.134 (192.168.110.134)' can't be established.
 3 ECDSA key fingerprint is SHA256:wlKVKgUMLjMb6zTGJ7DPo36/9DXW7CFDOKeqxyv4kRk.
 4 ECDSA key fingerprint is MD5:cf:a2:d1:53:3a:2b:7e:dd:d7:19:e7:13:2a:26:fc:38.
 5 Are you sure you want to continue connecting (yes/no)? yes
 6 Warning: Permanently added '192.168.110.134' (ECDSA) to the list of known hosts.
 7 root@192.168.110.134's password: 
 8 jdk-8u271-linux-x64.tar.gz                                                                                                                                                     100%  137MB  26.4MB/s   00:05    
 9 elasticsearch-6.7.1.tar.gz                                                                                                                                                     100%  142MB  28.2MB/s   00:05    
10 [root@k8s-master package]# scp -r jdk-8u271-linux-x64.tar.gz elasticsearch-6.7.1.tar.gz 192.168.110.135:/usr/local/package/
11 The authenticity of host '192.168.110.135 (192.168.110.135)' can't be established.
12 ECDSA key fingerprint is SHA256:VUOxRp5owr2jizIOMqPvbp9ZmSoYKE2F2Un5Z5cmVTY.
13 ECDSA key fingerprint is MD5:21:a2:c3:d7:76:23:6a:70:15:3f:61:64:30:ce:c7:a9.
14 Are you sure you want to continue connecting (yes/no)? yes
15 Warning: Permanently added '192.168.110.135' (ECDSA) to the list of known hosts.
16 root@192.168.110.135's password: 
17 jdk-8u271-linux-x64.tar.gz                                                                                                                                                     100%  137MB  15.5MB/s   00:08    
18 elasticsearch-6.7.1.tar.gz                                                                                                                                                     100%  142MB  31.0MB/s   00:04    
19 [root@k8s-master package]# 

然后在另外两台机器上面分别安装jdk、elasticsearch,注意jdk可以使用root权限,然后配置全局的环境变量,然后elasticsearch需要使用elsearch的,所以另外两台机器上需要创建elsearch组和用户的。

代码语言:javascript复制
1 [root@k8s-node2 package]# tar -zxvf jdk-8u271-linux-x64.tar.gz -C /usr/local/soft/
2 
3 [root@k8s-node3 package]# tar -zxvf jdk-8u271-linux-x64.tar.gz -C /usr/local/soft/

然后在两台机器上分别进行配置环境变量,然后刷新环境变量,使其生效即可,此处忽略。

然后创建在两台机器上分别创建elsearch组和用户,切换账号进行操作,如下所示:

代码语言:javascript复制
 1 [root@k8s-node2 jdk1.8.0_271]# groupadd elsearch
 2 [root@k8s-node2 jdk1.8.0_271]# useradd elsearch -g elsearch
 3 [root@k8s-node2 jdk1.8.0_271]# passwd elsearch
 4 Changing password for user elsearch.
 5 New password: 
 6 BAD PASSWORD: The password contains the user name in some form
 7 Retype new password: 
 8 passwd: all authentication tokens updated successfully.
 9 [root@k8s-node2 jdk1.8.0_271]# cd ..
10 [root@k8s-node2 soft]# ls
11 jdk1.8.0_271
12 [root@k8s-node2 soft]# cd ../package/
13 [root@k8s-node2 package]# ls
14 elasticsearch-6.7.1.tar.gz  jdk-8u271-linux-x64.tar.gz
15 [root@k8s-node2 package]# chown -R elsearch:elsearch elasticsearch-6.7.1.tar.gz 
16 [root@k8s-node2 package]# ll
17 total 284852
18 -rw-r--r-- 1 elsearch elsearch 148542786 Jan  9 19:29 elasticsearch-6.7.1.tar.gz
19 -rw-r--r-- 1 root     root     143142634 Jan  9 19:29 jdk-8u271-linux-x64.tar.gz
20 [root@k8s-node2 package]# su elsearch
21 [elsearch@k8s-node2 package]$ 
22 [elsearch@k8s-node2 package]$ tar -zxvf elasticsearch-6.7.1.tar.gz -C /usr/local/soft/

修改主节点的配置文件/usr/local/soft/elasticsearch-6.7.1/config/elasticsearch.yml,添加如下所示的内容。

主节点的配置,如下所示:

代码语言:javascript复制
 1 # 是否支持跨域
 2 http.cors.enabled: true
 3 #
 4 # *表示支持所有域名
 5 http.cors.allow-origin: "*"
 6 
 7 # 指定集群的名称,三台节点的集群名称必须一致。
 8 cluster.name: elsearch_cluster
 9 # 给master起一个名称,叫master,每台节点的名称都必须不一样
10 node.name: master
11 # 告诉此节点,它就是master
12 node.master: true
13 # 绑定的ip地址和默认端口号9200
14 network.host: 192.168.110.133
15 # 默认端口号
16 http.port: 9200
17 
18 # 主节点数/ 2   1,此值是这样计算的,上面的注释也说明了。此值是为了阻止没有节点做主节点或者都做子节点的情况发生。避免出现脑裂。
19 # # 默认值是3,这样才可以选出主节点的。那么这就需要注意了,你的主节点数至少是4的,不然无法正常选举。通过配置这个参数来防止集群脑裂现象 (集群总节点数量/2) 1。
20 # 表示集群最少的master个数,如果集群的最少master个数少于指定的数,将无法启动,官方推荐node master数设置为集群数/2 1,我这里三台ES服务器,配置最少需要两台master,整个集群才可正常运行
21 discovery.zen.minimum_master_nodes: 2
22 # # 集群里面的节点都需要加到里面,如果是伪集群的话,可以使用ip:端口号或者主机名称的形式加进去的,如果是非伪集群,可以直接使用ip:port或者主机名称加进去。
23 # # 注意,这里面加的主机节点,是有机会进行选举主节点的,其他未加进去,没有机会进行选择主节点的机会的。
24 # 设置集群的初始节点列表,集群互通端口为9300。      
25 discovery.zen.ping.unicast.hosts: ["192.168.110.133:9300","192.168.110.134:9300","192.168.110.135:9300"]

两个从节点的配置如下所示:

代码语言:javascript复制
 1 # 是否支持跨域
 2 http.cors.enabled: true
 3 #
 4 # # # *表示支持所有域名
 5 http.cors.allow-origin: "*"
 6 #
 7 # # 从节点cluster.name要和master主节点的名称要保持一致
 8 cluster.name: elsearch_cluster
 9 # # 从节点起一个名称
10 node.name: slaver2
11 # 告诉此节点,它就是master
12 node.master: true
13 # # 绑定的ip地址和默认端口号9200
14 network.host: 192.168.110.134
15 #
16 # # 主节点数/ 2   1,此值是这样计算的,上面的注释也说明了。此值是为了阻止没有节点做主节点或者都做子节点的情况发生。避免出现脑裂。
17 # # 默认值是3,这样才可以选出主节点的。那么这就需要注意了,你的主节点数至少是4的,不然无法正常选举。通过配置这个参数来防止集群脑裂现象 (集群总节点数量/2) 1
18 discovery.zen.minimum_master_nodes: 2
19 # # 集群里面的节点都需要加到里面,如果是伪集群的话,可以使用ip:端口号或者主机名称的形式加进去的,如果是非伪集群,可以直接使用ip:port或者主机名称加进去。
20 # # 注意,这里面加的主机节点,是有机会进行选举主节点的,其他未加进去,没有机会进行选择主节点的机会的。
21 # 设置集群的初始节点列表,集群互通端口为9300。      
22 discovery.zen.ping.unicast.hosts: ["192.168.110.133:9300","192.168.110.134:9300","192.168.110.135:9300"]
23 #

第二个从节点,配置,如下所示:

代码语言:javascript复制
 1 # 是否支持跨域
 2 http.cors.enabled: true
 3 #
 4 # # # *表示支持所有域名
 5 http.cors.allow-origin: "*"
 6 #
 7 # # 从节点cluster.name要和master主节点的名称要保持一致
 8 cluster.name: elsearch_cluster
 9 # # 从节点起一个名称
10 node.name: slaver3
11 # 告诉此节点,它就是master
12 node.master: true
13 # # 绑定的ip地址和默认端口号9200
14 network.host: 192.168.110.135
15 #
16 # # 主节点数/ 2   1,此值是这样计算的,上面的注释也说明了。此值是为了阻止没有节点做主节点或者都做子节点的情况发生。避免出现脑裂。
17 # # 默认值是3,这样才可以选出主节点的。那么这就需要注意了,你的主节点数至少是4的,不然无法正常选举。通过配置这个参数来防止集群脑裂现象 (集群总节点数量/2) 1
18 discovery.zen.minimum_master_nodes: 2
19 # # 集群里面的节点都需要加到里面,如果是伪集群的话,可以使用ip:端口号或者主机名称的形式加进去的,如果是非伪集群,可以直接使用ip:port或者主机名称加进去。
20 # # 注意,这里面加的主机节点,是有机会进行选举主节点的,其他未加进去,没有机会进行选择主节点的机会的。
21 # 设置集群的初始节点列表,集群互通端口为9300。      
22 discovery.zen.ping.unicast.hosts: ["192.168.110.133:9300","192.168.110.134:9300","192.168.110.135:9300"]
23 #

注意:node.master参数,该节点是否有资格选举为master,如果上面discovery.zen.minimum_master_nodes参数设置的为2,也就是最少两个master节点,则集群中必须有两台es服务器的配置为node.master: true的配置,配置了2个节点的话,如果主服务器宕机,整个集群会不可用,所以三台服务器,需要配置3个node.masdter为true,这样三个master,宕了一个主节点的话,他又会选举新的master,还有两个节点可以用,只要配了node.master为true的ES服务器数正在运行的数量不少于discovery.zen.minimum_master_nodes的配置数,则整个集群继续可用,我这里则配置三台es node.master都为true,也就是三个master,master服务器主要管理集群状态,负责元数据处理,比如索引增加删除分片分配等,数据存储和查询都不会走主节点,压力较小,jvm内存可分配较低一点。

错误情况:

  如果报下面的错误,可能是因为你的elasticsearch正在运行着呢,比如我的第一个搭建的单节点就启动了,再次运行启动脚本就报下面的错误,如下所示:

代码语言:javascript复制
 1 [elsearch@k8s-master elasticsearch-6.7.1]$ ./bin/elasticsearch
 2 [2021-01-09T20:02:25,970][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [master] uncaught exception in thread [main]
 3 org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/local/soft/elasticsearch-6.7.1/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
 4     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.7.1.jar:6.7.1]
 5     at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.7.1.jar:6.7.1]
 6     at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.7.1.jar:6.7.1]
 7     at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.7.1.jar:6.7.1]
 8     at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.7.1.jar:6.7.1]
 9     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.7.1.jar:6.7.1]
10     at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.7.1.jar:6.7.1]
11 Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/local/soft/elasticsearch-6.7.1/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
12     at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:300) ~[elasticsearch-6.7.1.jar:6.7.1]
13     at org.elasticsearch.node.Node.<init>(Node.java:296) ~[elasticsearch-6.7.1.jar:6.7.1]
14     at org.elasticsearch.node.Node.<init>(Node.java:266) ~[elasticsearch-6.7.1.jar:6.7.1]
15     at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:212) ~[elasticsearch-6.7.1.jar:6.7.1]
16     at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:212) ~[elasticsearch-6.7.1.jar:6.7.1]
17     at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.7.1.jar:6.7.1]
18     at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.7.1.jar:6.7.1]
19     ... 6 more
20 [elsearch@k8s-master elasticsearch-6.7.1]$ 

如果启动报下面的错误,如下所示:

代码语言:javascript复制
 1 [elsearch@k8s-node2 elasticsearch-6.7.1]$ ./bin/elasticsearch
 2 [2021-01-09T20:16:38,505][INFO ][o.e.e.NodeEnvironment    ] [slaver2] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [8.8gb], net total_space [17.7gb], types [rootfs]
 3 [2021-01-09T20:16:38,512][INFO ][o.e.e.NodeEnvironment    ] [slaver2] heap size [1007.3mb], compressed ordinary object pointers [true]
 4 [2021-01-09T20:16:38,515][INFO ][o.e.n.Node               ] [slaver2] node name [slaver2], node ID [-7wc2zeFTJKYE93iD_E1rA]
 5 [2021-01-09T20:16:38,516][INFO ][o.e.n.Node               ] [slaver2] version[6.7.1], pid[50922], build[default/tar/2f32220/2019-04-02T15:59:27.961366Z], OS[Linux/3.10.0-957.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_271/25.271-b09]
 6 [2021-01-09T20:16:38,517][INFO ][o.e.n.Node               ] [slaver2] JVM arguments [-Xms1g, -Xmx1g, -XX: UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX: UseCMSInitiatingOccupancyOnly, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX: AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch-7249801658858545168, -XX: HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX: PrintGCDetails, -XX: PrintGCDateStamps, -XX: PrintTenuringDistribution, -XX: PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX: UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/usr/local/soft/elasticsearch-6.7.1, -Des.path.conf=/usr/local/soft/elasticsearch-6.7.1/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
 7 [2021-01-09T20:16:47,800][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [aggs-matrix-stats]
 8 [2021-01-09T20:16:47,801][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [analysis-common]
 9 [2021-01-09T20:16:47,802][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [ingest-common]
10 [2021-01-09T20:16:47,802][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [ingest-geoip]
11 [2021-01-09T20:16:47,802][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [ingest-user-agent]
12 [2021-01-09T20:16:47,802][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [lang-expression]
13 [2021-01-09T20:16:47,803][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [lang-mustache]
14 [2021-01-09T20:16:47,803][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [lang-painless]
15 [2021-01-09T20:16:47,804][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [mapper-extras]
16 [2021-01-09T20:16:47,804][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [parent-join]
17 [2021-01-09T20:16:47,805][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [percolator]
18 [2021-01-09T20:16:47,805][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [rank-eval]
19 [2021-01-09T20:16:47,805][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [reindex]
20 [2021-01-09T20:16:47,806][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [repository-url]
21 [2021-01-09T20:16:47,806][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [transport-netty4]
22 [2021-01-09T20:16:47,806][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [tribe]
23 [2021-01-09T20:16:47,806][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-ccr]
24 [2021-01-09T20:16:47,806][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-core]
25 [2021-01-09T20:16:47,807][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-deprecation]
26 [2021-01-09T20:16:47,807][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-graph]
27 [2021-01-09T20:16:47,807][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-ilm]
28 [2021-01-09T20:16:47,808][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-logstash]
29 [2021-01-09T20:16:47,808][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-ml]
30 [2021-01-09T20:16:47,808][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-monitoring]
31 [2021-01-09T20:16:47,808][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-rollup]
32 [2021-01-09T20:16:47,808][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-security]
33 [2021-01-09T20:16:47,809][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-sql]
34 [2021-01-09T20:16:47,809][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-upgrade]
35 [2021-01-09T20:16:47,809][INFO ][o.e.p.PluginsService     ] [slaver2] loaded module [x-pack-watcher]
36 [2021-01-09T20:16:47,811][INFO ][o.e.p.PluginsService     ] [slaver2] no plugins loaded
37 [2021-01-09T20:16:55,755][INFO ][o.e.x.s.a.s.FileRolesStore] [slaver2] parsed [0] roles from file [/usr/local/soft/elasticsearch-6.7.1/config/roles.yml]
38 [2021-01-09T20:17:02,422][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [slaver2] [controller/51396] [Main.cc@109] controller (64 bit): Version 6.7.1 (Build e1f492de67a719) Copyright (c) 2019 Elasticsearch BV
39 [2021-01-09T20:17:03,268][DEBUG][o.e.a.ActionModule       ] [slaver2] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
40 [2021-01-09T20:17:04,165][INFO ][o.e.d.DiscoveryModule    ] [slaver2] using discovery type [zen] and host providers [settings]
41 [2021-01-09T20:17:07,312][INFO ][o.e.n.Node               ] [slaver2] initialized
42 [2021-01-09T20:17:07,312][INFO ][o.e.n.Node               ] [slaver2] starting ...
43 [2021-01-09T20:17:08,535][INFO ][o.e.t.TransportService   ] [slaver2] publish_address {192.168.110.134:9300}, bound_addresses {192.168.110.134:9300}
44 [2021-01-09T20:17:08,570][INFO ][o.e.b.BootstrapChecks    ] [slaver2] bound or publishing to a non-loopback address, enforcing bootstrap checks
45 ERROR: [2] bootstrap checks failed
46 [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
47 [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
48 [2021-01-09T20:17:08,599][INFO ][o.e.n.Node               ] [slaver2] stopping ...
49 [2021-01-09T20:17:08,647][INFO ][o.e.n.Node               ] [slaver2] stopped
50 [2021-01-09T20:17:08,647][INFO ][o.e.n.Node               ] [slaver2] closing ...
51 [2021-01-09T20:17:08,671][INFO ][o.e.n.Node               ] [slaver2] closed
52 [2021-01-09T20:17:08,678][INFO ][o.e.x.m.p.NativeController] [slaver2] Native controller process has stopped - no new native processes can be started
53 [elsearch@k8s-node2 elasticsearch-6.7.1]$ 
54 [elsearch@k8s-node2 elasticsearch-6.7.1]$ 
55 [elsearch@k8s-node2 elasticsearch-6.7.1]$ 
56 [elsearch@k8s-node2 elasticsearch-6.7.1]$ 

上面的两个错误解决方法如下所示:

错误一,[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]。解决方法如下所示:

错误原因,每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量。

注意,切记,如果按照此方法修改,必须重启你的虚拟机,而且是root用户修改的配置文件,不然你解决完报的这两个错误,再次启动elasticsearch还是会报错误一,但是不会报错误二,所以重启虚拟机以后解决这两个错误。

代码语言:javascript复制
1 [root@k8s-node2 elasticsearch-6.7.1]# vim /etc/security/limits.conf
2 [root@k8s-node2 elasticsearch-6.7.1]# 

添加如下所示内容:

注意:解释如是,*是代表任何用户,此配置的意思是任何用户都可以打开文件的数量。

代码语言:javascript复制
1 *               soft    nofile          65536
2 *               hard    nofile          65536

错误二,max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]。

错误原因,应该是虚拟内存不足导致的错误。修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144。执行命令sysctl -p生效。

代码语言:javascript复制
1 [root@k8s-node2 elasticsearch-6.7.1]# vim /etc/sysctl.conf
2 [root@k8s-node2 elasticsearch-6.7.1]# sysctl -p
3 vm.max_map_count = 262144
4 [root@k8s-node2 elasticsearch-6.7.1]# 

添加内容如下所示:

代码语言:javascript复制
1 vm.max_map_count=262144

5、三台节点的Elasticsearch启动完成之后,可以通过一些方法进行简单的验证,如下所示:

第一种,访问http://192.168.110.133:9200/,可以查看版本状态,如下所示:

第二种,可以通过访问http://192.168.110.133:9200/_cat/nodes,来查看是否组成了集群,如下所示:

可以通过访问http://192.168.110.133:9200/_cat/nodes?v,来查看集群状态,如下所示:

也可以访问http://192.168.110.133:9200/_cluster/stats,查看elasticsearch的集群状态,如下所示:

0 人点赞