第二章 ElasticSearch在Centos7上的安装

下面是安装的操作步骤,前提是已经安装jdk

1.下载 elasticsearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.16.tar.gz

2. 解压elasticsearch-5.6.16.tar.gz

[root@centos-linux-1 opt]# tar -zxvf elasticsearch-5.6.16.tar.gz 
elasticsearch-5.6.16/
elasticsearch-5.6.16/lib/
elasticsearch-5.6.16/lib/elasticsearch-5.6.16.jar
elasticsearch-5.6.16/lib/lucene-core-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-analyzers-common-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-backward-codecs-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-grouping-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-highlighter-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-join-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-memory-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-misc-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-queries-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-queryparser-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-sandbox-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-spatial-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-spatial-extras-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-spatial3d-6.6.1.jar
elasticsearch-5.6.16/lib/lucene-suggest-6.6.1.jar
elasticsearch-5.6.16/lib/securesm-1.2.jar
elasticsearch-5.6.16/lib/jopt-simple-5.0.2.jar
elasticsearch-5.6.16/lib/hppc-0.7.1.jar
elasticsearch-5.6.16/lib/joda-time-2.10.jar
elasticsearch-5.6.16/lib/snakeyaml-1.15.jar
elasticsearch-5.6.16/lib/jackson-core-2.8.6.jar
elasticsearch-5.6.16/lib/jackson-dataformat-smile-2.8.6.jar
elasticsearch-5.6.16/lib/jackson-dataformat-yaml-2.8.6.jar
elasticsearch-5.6.16/lib/jackson-dataformat-cbor-2.8.6.jar
elasticsearch-5.6.16/lib/t-digest-3.0.jar
elasticsearch-5.6.16/lib/HdrHistogram-2.1.9.jar
elasticsearch-5.6.16/lib/spatial4j-0.6.jar
elasticsearch-5.6.16/lib/jts-1.13.jar
elasticsearch-5.6.16/lib/log4j-api-2.11.1.jar
elasticsearch-5.6.16/lib/log4j-core-2.11.1.jar
elasticsearch-5.6.16/lib/log4j-1.2-api-2.11.1.jar
elasticsearch-5.6.16/lib/jna-4.4.0-1.jar
elasticsearch-5.6.16/lib/java-version-checker-5.6.16.jar
elasticsearch-5.6.16/lib/plugin-cli-5.6.16.jar
elasticsearch-5.6.16/config/
elasticsearch-5.6.16/config/jvm.options
elasticsearch-5.6.16/config/elasticsearch.yml
elasticsearch-5.6.16/config/log4j2.properties
elasticsearch-5.6.16/bin/
elasticsearch-5.6.16/bin/elasticsearch-plugin
elasticsearch-5.6.16/bin/elasticsearch
elasticsearch-5.6.16/bin/elasticsearch.in.sh
elasticsearch-5.6.16/bin/elasticsearch-keystore
elasticsearch-5.6.16/bin/elasticsearch-systemd-pre-exec
elasticsearch-5.6.16/bin/elasticsearch-translog
elasticsearch-5.6.16/bin/elasticsearch-plugin.bat
elasticsearch-5.6.16/bin/elasticsearch-keystore.bat
elasticsearch-5.6.16/bin/elasticsearch.bat
elasticsearch-5.6.16/bin/elasticsearch-service.bat
elasticsearch-5.6.16/bin/elasticsearch-translog.bat
elasticsearch-5.6.16/bin/elasticsearch.in.bat
elasticsearch-5.6.16/README.textile
elasticsearch-5.6.16/LICENSE.txt
elasticsearch-5.6.16/NOTICE.txt
elasticsearch-5.6.16/bin/elasticsearch-service-x64.exe
elasticsearch-5.6.16/bin/elasticsearch-service-mgr.exe
elasticsearch-5.6.16/bin/elasticsearch-service-x86.exe
elasticsearch-5.6.16/modules/
elasticsearch-5.6.16/modules/lang-painless/
elasticsearch-5.6.16/modules/lang-painless/plugin-security.policy
elasticsearch-5.6.16/modules/lang-painless/lang-painless-5.6.16.jar
elasticsearch-5.6.16/modules/lang-painless/asm-debug-all-5.1.jar
elasticsearch-5.6.16/modules/lang-painless/antlr4-runtime-4.5.1-1.jar
elasticsearch-5.6.16/modules/lang-painless/plugin-descriptor.properties
elasticsearch-5.6.16/modules/reindex/
elasticsearch-5.6.16/modules/reindex/httpcore-nio-4.4.5.jar
elasticsearch-5.6.16/modules/reindex/reindex-5.6.16.jar
elasticsearch-5.6.16/modules/reindex/httpclient-4.5.2.jar
elasticsearch-5.6.16/modules/reindex/httpasyncclient-4.1.2.jar
elasticsearch-5.6.16/modules/reindex/plugin-security.policy
elasticsearch-5.6.16/modules/reindex/commons-codec-1.10.jar
elasticsearch-5.6.16/modules/reindex/elasticsearch-rest-client-5.6.16.jar
elasticsearch-5.6.16/modules/reindex/plugin-descriptor.properties
elasticsearch-5.6.16/modules/reindex/commons-logging-1.1.3.jar
elasticsearch-5.6.16/modules/reindex/httpcore-4.4.5.jar
elasticsearch-5.6.16/modules/transport-netty4/
elasticsearch-5.6.16/modules/transport-netty4/netty-resolver-4.1.13.Final.jar
elasticsearch-5.6.16/modules/transport-netty4/netty-buffer-4.1.13.Final.jar
elasticsearch-5.6.16/modules/transport-netty4/netty-codec-http-4.1.13.Final.jar
elasticsearch-5.6.16/modules/transport-netty4/netty-common-4.1.13.Final.jar
elasticsearch-5.6.16/modules/transport-netty4/plugin-security.policy
elasticsearch-5.6.16/modules/transport-netty4/netty-codec-4.1.13.Final.jar
elasticsearch-5.6.16/modules/transport-netty4/transport-netty4-5.6.16.jar
elasticsearch-5.6.16/modules/transport-netty4/netty-transport-4.1.13.Final.jar
elasticsearch-5.6.16/modules/transport-netty4/netty-handler-4.1.13.Final.jar
elasticsearch-5.6.16/modules/transport-netty4/plugin-descriptor.properties
elasticsearch-5.6.16/modules/parent-join/
elasticsearch-5.6.16/modules/parent-join/parent-join-5.6.16.jar
elasticsearch-5.6.16/modules/parent-join/plugin-descriptor.properties
elasticsearch-5.6.16/modules/percolator/
elasticsearch-5.6.16/modules/percolator/percolator-5.6.16.jar
elasticsearch-5.6.16/modules/percolator/plugin-descriptor.properties
elasticsearch-5.6.16/modules/lang-mustache/
elasticsearch-5.6.16/modules/lang-mustache/lang-mustache-5.6.16.jar
elasticsearch-5.6.16/modules/lang-mustache/plugin-security.policy
elasticsearch-5.6.16/modules/lang-mustache/compiler-0.9.3.jar
elasticsearch-5.6.16/modules/lang-mustache/plugin-descriptor.properties
elasticsearch-5.6.16/modules/transport-netty3/
elasticsearch-5.6.16/modules/transport-netty3/transport-netty3-5.6.16.jar
elasticsearch-5.6.16/modules/transport-netty3/plugin-security.policy
elasticsearch-5.6.16/modules/transport-netty3/netty-3.10.6.Final.jar
elasticsearch-5.6.16/modules/transport-netty3/plugin-descriptor.properties
elasticsearch-5.6.16/modules/ingest-common/
elasticsearch-5.6.16/modules/ingest-common/joni-2.1.6.jar
elasticsearch-5.6.16/modules/ingest-common/ingest-common-5.6.16.jar
elasticsearch-5.6.16/modules/ingest-common/jcodings-1.0.12.jar
elasticsearch-5.6.16/modules/ingest-common/plugin-descriptor.properties
elasticsearch-5.6.16/modules/aggs-matrix-stats/
elasticsearch-5.6.16/modules/aggs-matrix-stats/aggs-matrix-stats-5.6.16.jar
elasticsearch-5.6.16/modules/aggs-matrix-stats/plugin-descriptor.properties
elasticsearch-5.6.16/modules/lang-groovy/
elasticsearch-5.6.16/modules/lang-groovy/plugin-security.policy
elasticsearch-5.6.16/modules/lang-groovy/groovy-2.4.6-indy.jar
elasticsearch-5.6.16/modules/lang-groovy/lang-groovy-5.6.16.jar
elasticsearch-5.6.16/modules/lang-groovy/plugin-descriptor.properties
elasticsearch-5.6.16/modules/lang-expression/
elasticsearch-5.6.16/modules/lang-expression/asm-commons-5.0.4.jar
elasticsearch-5.6.16/modules/lang-expression/plugin-security.policy
elasticsearch-5.6.16/modules/lang-expression/lucene-expressions-6.6.1.jar
elasticsearch-5.6.16/modules/lang-expression/antlr4-runtime-4.5.1-1.jar
elasticsearch-5.6.16/modules/lang-expression/plugin-descriptor.properties
elasticsearch-5.6.16/modules/lang-expression/asm-5.0.4.jar
elasticsearch-5.6.16/modules/lang-expression/asm-tree-5.0.4.jar
elasticsearch-5.6.16/modules/lang-expression/lang-expression-5.6.16.jar
elasticsearch-5.6.16/plugins/
[root@centos-linux-1 Desktop]#

3. 解压完成,进入各个文件查看,以及怎么启动,启动遇到问题,怎么解决?

[root@centos-linux-1 ysq]# cd elasticsearch-5.6.16/
[root@centos-linux-1 elasticsearch-5.6.16]# ls
bin config lib LICENSE.txt modules NOTICE.txt plugins README.textile
[root@centos-linux-1 elasticsearch-5.6.16]# cd config/
[root@centos-linux-1 config]# ls
elasticsearch.yml jvm.options log4j2.properties
[root@centos-linux-1 config]# cd ..
[root@centos-linux-1 elasticsearch-5.6.16]# cd bin/
[root@centos-linux-1 bin]# ls
elasticsearch elasticsearch.in.sh elasticsearch-plugin elasticsearch-service-mgr.exe elasticsearch-systemd-pre-exec
elasticsearch.bat elasticsearch-keystore elasticsearch-plugin.bat elasticsearch-service-x64.exe elasticsearch-translog
elasticsearch.in.bat elasticsearch-keystore.bat elasticsearch-service.bat elasticsearch-service-x86.exe elasticsearch-translog.bat
[root@centos-linux-1 bin]# ./elasticsearch
[2019-03-31T15:57:08,343][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:136) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.6.16.jar:5.6.16]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.16.jar:5.6.16]
… 6 more
[root@centos-linux-1 bin]#

3.1 启动失败原因: 不能使用root用户来进行启动

失败问题

解决办法:首先查看是否是root用户启动的。

[root@centos-linux-1 bin]# ls -l
总用量 348
-rwxr-xr-x. 1 root root 8075 3月 13 23:31 elasticsearch
-rw-r--r--. 1 root root 3344 3月 13 23:31 elasticsearch.bat
-rw-r--r--. 1 root root 1023 3月 13 23:31 elasticsearch.in.bat
-rwxr-xr-x. 1 root root 367 3月 13 23:31 elasticsearch.in.sh
-rwxr-xr-x. 1 root root 2550 3月 13 23:31 elasticsearch-keystore
-rw-r--r--. 1 root root 744 3月 13 23:31 elasticsearch-keystore.bat
-rwxr-xr-x. 1 root root 2540 3月 13 23:31 elasticsearch-plugin
-rw-r--r--. 1 root root 732 3月 13 23:31 elasticsearch-plugin.bat
-rw-r--r--. 1 root root 11263 3月 13 23:31 elasticsearch-service.bat
-rw-r--r--. 1 root root 104448 3月 13 23:31 elasticsearch-service-mgr.exe
-rw-r--r--. 1 root root 103936 3月 13 23:31 elasticsearch-service-x64.exe
-rw-r--r--. 1 root root 80896 3月 13 23:31 elasticsearch-service-x86.exe
-rwxr-xr-x. 1 root root 223 3月 13 23:31 elasticsearch-systemd-pre-exec
-rwxr-xr-x. 1 root root 2514 3月 13 23:31 elasticsearch-translog
-rw-r--r--. 1 root root 1436 3月 13 23:31 elasticsearch-translog.bat
[root@centos-linux-1 bin]#

的确是root用户。解决版本有两个。

3.1.1 解决办法1 :允许root用户启动。

bin/elasticsearch -Des.insecure.allow.root=true
再次出现失败

这是出于系统安全考虑设置的条件,由于Elasticsearch可以接收用户输入的脚本并且执行,为了系统安全考虑,建议创建一个单独的用户来运行Elasticsearch

创建用户组和用户:

下面是创建esgroup组,esuser用户,设置密码espassword

groupadd esgroup
useradd esuser -g esgroup -p espassword

更改elasticsearch 文件夹及内部文件的所属用户及组:

[root@centos-linux-1 ysq]# chown -R esuser:esgroup elasticsearch-5.6.16
[root@centos-linux-1 ysq]# cd elasticsearch-5.6.16/
[root@centos-linux-1 elasticsearch-5.6.16]# ls -l
总用量 240
drwxr-xr-x. 2 esuser esgroup 4096 3月 31 15:55 bin
drwxr-xr-x. 2 esuser esgroup 4096 3月 13 23:35 config
drwxr-xr-x. 2 esuser esgroup 4096 3月 13 23:34 lib
-rw-r--r--. 1 esuser esgroup 11358 3月 13 23:31 LICENSE.txt
drwxr-xr-x. 2 esuser esgroup 4096 3月 31 15:57 logs
drwxr-xr-x. 13 esuser esgroup 4096 3月 13 23:35 modules
-rw-r--r--. 1 esuser esgroup 194187 3月 13 23:34 NOTICE.txt
drwxr-xr-x. 2 esuser esgroup 4096 3月 13 23:34 plugins
-rw-r--r--. 1 esuser esgroup 9491 3月 13 23:31 README.textile
[root@centos-linux-1 elasticsearch-5.6.16]#

[root@centos-linux-1 opt]# su esuser
[esuser@centos-linux-1 opt]$ cd elasticsearch-5.6.16/
[esuser@centos-linux-1 elasticsearch-5.6.16]$ ./bin/elasticsearch
[2019-03-31T16:58:54,729][INFO ][o.e.n.Node ] [] initializing …
[2019-03-31T16:58:55,091][INFO ][o.e.e.NodeEnvironment ] [bgboDjz] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [40.6gb], net total_space [49gb], spins? [unknown], types [rootfs]
[2019-03-31T16:58:55,091][INFO ][o.e.e.NodeEnvironment ] [bgboDjz] heap size [1.9gb], compressed ordinary object pointers [true]
[2019-03-31T16:58:55,093][INFO ][o.e.n.Node ] node name [bgboDjz] derived from node ID [bgboDjz0SaSK091pz_vAUg]; set [node.name] to override
[2019-03-31T16:58:55,093][INFO ][o.e.n.Node ] version[5.6.16], pid[12864], build[3a740d1/2019-03-13T15:33:36.565Z], OS[Linux/3.10.0-693.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_201/25.201-b09]
[2019-03-31T16:58:55,094][INFO ][o.e.n.Node ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/opt/elasticsearch-5.6.16]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [aggs-matrix-stats]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [ingest-common]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [lang-expression]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [lang-groovy]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [lang-mustache]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [lang-painless]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [parent-join]
[2019-03-31T16:58:56,640][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [percolator]
[2019-03-31T16:58:56,641][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [reindex]
[2019-03-31T16:58:56,641][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [transport-netty3]
[2019-03-31T16:58:56,641][INFO ][o.e.p.PluginsService ] [bgboDjz] loaded module [transport-netty4]
[2019-03-31T16:58:56,641][INFO ][o.e.p.PluginsService ] [bgboDjz] no plugins loaded
[2019-03-31T16:58:59,215][INFO ][o.e.d.DiscoveryModule ] [bgboDjz] using discovery type [zen]
[2019-03-31T16:58:59,729][INFO ][o.e.n.Node ] initialized
[2019-03-31T16:58:59,729][INFO ][o.e.n.Node ] [bgboDjz] starting …
[2019-03-31T16:59:00,146][INFO ][o.e.t.TransportService ] [bgboDjz] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-03-31T16:59:00,167][WARN ][o.e.b.BootstrapChecks ] [bgboDjz] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2019-03-31T16:59:00,167][WARN ][o.e.b.BootstrapChecks ] [bgboDjz] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2019-03-31T16:59:03,302][INFO ][o.e.c.s.ClusterService ] [bgboDjz] new_master {bgboDjz}{bgboDjz0SaSK091pz_vAUg}{yC7gNd62QtmRXCig3Q5wlg}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2019-03-31T16:59:03,357][INFO ][o.e.h.n.Netty4HttpServerTransport] [bgboDjz] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-03-31T16:59:03,358][INFO ][o.e.n.Node ] [bgboDjz] started
[2019-03-31T16:59:03,369][INFO ][o.e.g.GatewayService ] [bgboDjz] recovered [0] indices into cluster_state

表示启动成功。

另外开启一个终端检测: curl 127.0.0.1:9200

4.现实远程访问: 需要对config/elasticsearch.yml进行配置:network.host:912.168.25.131,

再次启动报错

错误有2个
这个案例错误有3个

问题1:max file descriptors 4096……

解决方法:vim /etc/security/limits.conf 文件最后加入

esuser soft nofile 65536
esuser hard nofile 65536
esuser soft nproc 4096
esuser hard nproc 4096

问题2:进入limits.d目录下修改配置文件

vim /etc/secrity/limits.d/20-nproc.conf 修改为 esuser soft nproc 4096

问题3: max vitual memory….

解决办法如下:

vim /etc/sysctl.conf
//增加:vm.max_map_count=655360
执行以下命令生效 sysctl -p

关闭防火墙:systemctl stop firewalld.service 再次重新启动。如果还是失败则关机再启动。启动成功界面

成功界面

测试curl

注意更改了ip,就不能使用127.0.0.1

Leave a comment

您的电子邮箱地址不会被公开。 必填项已用 * 标注