elasticsearch5.5.1安装部署

安装环境:centos7+JDK1.8

创建安装目录,下载压缩包

[root@localhost hasin]# mkdir es
[root@localhost hasin]# cd es
[root@localhost es]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.1.zip

下载成功如下图

--2018-12-29 14:09:54--  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.1.zip
正在解析主机 artifacts.elastic.co (artifacts.elastic.co)... 23.21.67.46, 184.73.245.233, 107.21.202.15, ...
正在连接 artifacts.elastic.co (artifacts.elastic.co)|23.21.67.46|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:33511694 (32M) [binary/octet-stream]
正在保存至: “elasticsearch-5.5.1.zip”

100%[===================================================================================================================================================>] 33,511,694  2.23MB/s 用时 15s    

2018-12-29 14:10:12 (2.10 MB/s) - 已保存 “elasticsearch-5.5.1.zip” [33511694/33511694])

解压

[root@localhost es]# unzip elasticsearch-5.5.1.zip

修改配置文件的IP为本机地址

[root@localhost es]# vi elasticsearch-5.5.1/config/elasticsearch.yml

注意:后有空格。

启动es,报错如下,不能用root用户启动

[hasin@localhost es]$ ./elasticsearch-5.5.1/bin/elasticsearch
[2018-12-29T14:19:47,999][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:127) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.1.jar:5.5.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.1.jar:5.5.1]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.1.jar:5.5.1]
	... 6 more

切换非root用户再启动

[hasin@localhost es]$ ./elasticsearch-5.5.1/bin/elasticsearch
2018-12-29 14:22:07,484 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:585)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:322)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
	at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)
	at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)
	at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:556)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:206)
	at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:221)
	at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:197)
	at org.elasticsearch.common.logging.LogConfigurator.configureStatusLogger(LogConfigurator.java:175)
	at org.elasticsearch.common.logging.LogConfigurator.configureWithoutConfig(LogConfigurator.java:99)
	at org.elasticsearch.cli.Command.main(Command.java:85)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84)

Exception in thread "main" SettingsException[Failed to load settings from /home/hasin/es/elasticsearch-5.5.1/config/elasticsearch.yml]; nested: AccessDeniedException[/home/hasin/es/elasticsearch-5.5.1/config/elasticsearch.yml];
	at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:102)
	at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:72)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122)
	at org.elasticsearch.cli.Command.main(Command.java:88)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84)
Caused by: java.nio.file.AccessDeniedException: /home/hasin/es/elasticsearch-5.5.1/config/elasticsearch.yml
	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
	at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
	at java.nio.file.Files.newByteChannel(Files.java:361)
	at java.nio.file.Files.newByteChannel(Files.java:407)
	at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
	at java.nio.file.Files.newInputStream(Files.java:152)
	at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1033)
	at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:100)
	... 6 more

当前用户没有权限,切换到root用户给当前用户赋予操作权限

[hasin@localhost es]$ su root
[root@localhost es]# chown hasin /home/hasin/es/ -R

启动报错

[2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方法:

切换root用户,修改/etc/sysctl.conf,添加vm.max_map_count=262144

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=262144
[root@localhost es]# sysctl -p

启动es,报错

[hasin@localhost es]$ ./elasticsearch-5.5.1/bin/elasticsearch
[2018-12-29T14:42:36,207][INFO ][o.e.n.Node               ] [] initializing ...
[2018-12-29T14:42:36,300][INFO ][o.e.e.NodeEnvironment    ] [RwR2t49] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [11.4gb], net total_space [16.9gb], spins? [unknown], types [rootfs]
[2018-12-29T14:42:36,300][INFO ][o.e.e.NodeEnvironment    ] [RwR2t49] heap size [1.9gb], compressed ordinary object pointers [true]
[2018-12-29T14:42:36,302][INFO ][o.e.n.Node               ] node name [RwR2t49] derived from node ID [RwR2t49OSrK03kEpoFSMJg]; set [node.name] to override
[2018-12-29T14:42:36,302][INFO ][o.e.n.Node               ] version[5.5.1], pid[8392], build[19c13d0/2017-07-18T20:44:24.823Z], OS[Linux/3.10.0-862.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_161/25.161-b14]
[2018-12-29T14:42:36,302][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=/home/hasin/es/elasticsearch-5.5.1]
[2018-12-29T14:42:37,189][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [aggs-matrix-stats]
[2018-12-29T14:42:37,189][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [ingest-common]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-expression]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-groovy]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-mustache]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-painless]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [parent-join]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [percolator]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [reindex]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [transport-netty3]
[2018-12-29T14:42:37,190][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [transport-netty4]
[2018-12-29T14:42:37,191][INFO ][o.e.p.PluginsService     ] [RwR2t49] no plugins loaded
[2018-12-29T14:42:38,760][INFO ][o.e.d.DiscoveryModule    ] [RwR2t49] using discovery type [zen]
[2018-12-29T14:42:39,564][INFO ][o.e.n.Node               ] initialized
[2018-12-29T14:42:39,564][INFO ][o.e.n.Node               ] [RwR2t49] starting ...
[2018-12-29T14:42:39,725][INFO ][o.e.t.TransportService   ] [RwR2t49] publish_address {192.168.13.207:9300}, bound_addresses {192.168.13.207:9300}
[2018-12-29T14:42:39,736][INFO ][o.e.b.BootstrapChecks    ] [RwR2t49] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2018-12-29T14:42:39,815][INFO ][o.e.n.Node               ] [RwR2t49] stopping ...
[2018-12-29T14:42:39,936][INFO ][o.e.n.Node               ] [RwR2t49] stopped
[2018-12-29T14:42:39,936][INFO ][o.e.n.Node               ] [RwR2t49] closing ...
[2018-12-29T14:42:39,949][INFO ][o.e.n.Node               ] [RwR2t49] closed

解决方法

[hasin@localhost es]$ su root
密码:
[root@localhost es]# vi /etc/security/limits.conf

添加

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

再次启动es

[hasin@localhost es]$ ./elasticsearch-5.5.1/bin/elasticsearch
[2018-12-29T14:55:03,165][INFO ][o.e.n.Node               ] [] initializing ...
[2018-12-29T14:55:03,266][INFO ][o.e.e.NodeEnvironment    ] [RwR2t49] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [11.4gb], net total_space [16.9gb], spins? [unknown], types [rootfs]
[2018-12-29T14:55:03,266][INFO ][o.e.e.NodeEnvironment    ] [RwR2t49] heap size [1.9gb], compressed ordinary object pointers [true]
[2018-12-29T14:55:03,268][INFO ][o.e.n.Node               ] node name [RwR2t49] derived from node ID [RwR2t49OSrK03kEpoFSMJg]; set [node.name] to override
[2018-12-29T14:55:03,268][INFO ][o.e.n.Node               ] version[5.5.1], pid[8948], build[19c13d0/2017-07-18T20:44:24.823Z], OS[Linux/3.10.0-862.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_161/25.161-b14]
[2018-12-29T14:55:03,268][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=/home/hasin/es/elasticsearch-5.5.1]
[2018-12-29T14:55:04,106][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [aggs-matrix-stats]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [ingest-common]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-expression]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-groovy]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-mustache]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [lang-painless]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [parent-join]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [percolator]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [reindex]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [transport-netty3]
[2018-12-29T14:55:04,107][INFO ][o.e.p.PluginsService     ] [RwR2t49] loaded module [transport-netty4]
[2018-12-29T14:55:04,108][INFO ][o.e.p.PluginsService     ] [RwR2t49] no plugins loaded
[2018-12-29T14:55:05,758][INFO ][o.e.d.DiscoveryModule    ] [RwR2t49] using discovery type [zen]
[2018-12-29T14:55:06,415][INFO ][o.e.n.Node               ] initialized
[2018-12-29T14:55:06,415][INFO ][o.e.n.Node               ] [RwR2t49] starting ...
[2018-12-29T14:55:06,640][INFO ][o.e.t.TransportService   ] [RwR2t49] publish_address {192.168.13.207:9300}, bound_addresses {192.168.13.207:9300}
[2018-12-29T14:55:06,648][INFO ][o.e.b.BootstrapChecks    ] [RwR2t49] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2018-12-29T14:55:09,833][INFO ][o.e.c.s.ClusterService   ] [RwR2t49] new_master {RwR2t49}{RwR2t49OSrK03kEpoFSMJg}{4qVN3pYRSJeYbZ68vW6nTQ}{192.168.13.207}{192.168.13.207:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-12-29T14:55:09,866][INFO ][o.e.h.n.Netty4HttpServerTransport] [RwR2t49] publish_address {192.168.13.207:9200}, bound_addresses {192.168.13.207:9200}
[2018-12-29T14:55:09,866][INFO ][o.e.n.Node               ] [RwR2t49] started
[2018-12-29T14:55:09,897][INFO ][o.e.g.GatewayService     ] [RwR2t49] recovered [0] indices into cluster_state

启动成功。

打开浏览器192.168.13.207:9200

显示如下

如果连接失败关闭自己 的防火墙即可

sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service

后台启动

[hasin@localhost es]$ ./elasticsearch-5.5.1/bin/elasticsearch -d

猜你喜欢

转载自blog.csdn.net/qq_29410905/article/details/85334600