java学习讨论群:725562382
1、下载
访问官网的下载地址:https://www.elastic.co/downloads/elasticsearch,windows版的下载ZIP格式的。
如果不想下载最新版的,可以点击“past releases”选择过去的版本。我这里下载的是6.8.6版本的。
这就是下载好的linux版本,将他上传到linux
2,这里我将下载下来的tar包上传至 /usr/local/software/ 路径下
3,解压缩
这里我将tar包解压缩到 /usr/local/java/ 目录下
解压缩:
tar -zxvf elasticsearch-6.8.6.tar.gz -C /usr/local/java/
修改elasticsearch.yml
修改elasticsearch.yml 配置文件为远程访问IP和端口
cd /usr/local/java/elasticsearch-6.8.6/config
vim elasticsearch.yml
4,启动
这里这安装好了吗?我们试试能不能启动
进入bin目录:
/usr/local/java/elasticsearch-6.8.6/bin
启动:
./elasticsearch
看见如下被自动killed
原因是因为:
查看日志也没有错误。
后来发现是内存不够了,由于ES是运行在JVM上,JVM本身除了分配的heap内存以外,还会用到一些堆外(off heap)内存。 在小内存的机器上跑ES,如果heap划分过多,累加上堆外内存后,总的JVM使用内存量可能超过物理内存限制。 如果swap又是关闭的情况下,就会被操作系统oom killer杀掉。
修改ES中config目录下的jvm.options文件
vim jvm.options
将
-Xms1g
-Xmx1g
改为
-Xms512m
-Xmx512m
找到问题了我们调整了jvm之后重新启动
网上找了资料解决方案;
继续按网上的解决方案再次启动还是报错
从日志看出我们不能用root启动,那需要新建一个用户组和用户专属EslasticSearch的,那我们就开始新建组合用户
[root@backup01 bin]# groupadd esgroup
[root@backup01 bin]# useradd esuser -g esgroup -p 123456
修改 elasticsearch-6.8.6 所属组以及用户 chown -R esuser:esgroup elasticsearch-6.8.6
切换es的专属用户重新启动
启动日志如下:
[root@backup01 bin]# su esuser
[esuser@backup01 bin]$ ./elasticsearch
[2019-12-25T21:20:55,797][INFO ][o.e.e.NodeEnvironment ] [XF1iu6t] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [25.4gb], net total_space [39.9gb], types [rootfs]
[2019-12-25T21:20:55,801][INFO ][o.e.e.NodeEnvironment ] [XF1iu6t] heap size [503.6mb], compressed ordinary object pointers [true]
[2019-12-25T21:20:55,802][INFO ][o.e.n.Node ] [XF1iu6t] node name derived from node ID [XF1iu6tZTT2SyUnPu6Ud2A]; set [node.name] to override
[2019-12-25T21:20:55,802][INFO ][o.e.n.Node ] [XF1iu6t] version[6.8.6], pid[27766], build[default/tar/3d9f765/2019-12-13T17:11:52.013738Z], OS[Linux/3.10.0-862.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_172/25.172-b11]
[2019-12-25T21:20:55,802][INFO ][o.e.n.Node ] [XF1iu6t] JVM arguments [-Xms512m, -Xmx512m, -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-3305798114182502653, -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/java/elasticsearch-6.8.6, -Des.path.conf=/usr/local/java/elasticsearch-6.8.6/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[2019-12-25T21:21:01,240][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [aggs-matrix-stats]
[2019-12-25T21:21:01,242][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [analysis-common]
[2019-12-25T21:21:01,242][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [ingest-common]
[2019-12-25T21:21:01,242][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [ingest-geoip]
[2019-12-25T21:21:01,242][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [ingest-user-agent]
[2019-12-25T21:21:01,242][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [lang-expression]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [lang-mustache]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [lang-painless]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [mapper-extras]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [parent-join]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [percolator]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [rank-eval]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [reindex]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [repository-url]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [transport-netty4]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [tribe]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-ccr]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-core]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-deprecation]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-graph]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-ilm]
[2019-12-25T21:21:01,243][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-logstash]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-ml]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-monitoring]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-rollup]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-security]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-sql]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-upgrade]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-watcher]
[2019-12-25T21:21:01,244][INFO ][o.e.p.PluginsService ] [XF1iu6t] no plugins loaded
[2019-12-25T21:21:10,294][INFO ][o.e.x.s.a.s.FileRolesStore] [XF1iu6t] parsed [0] roles from file [/usr/local/java/elasticsearch-6.8.6/config/roles.yml]
[2019-12-25T21:21:12,397][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [XF1iu6t] [controller/27821] [Main.cc@109] controller (64 bit): Version 6.8.6 (Build 73ed602c10c48e) Copyright (c) 2019 Elasticsearch BV
[2019-12-25T21:21:13,156][DEBUG][o.e.a.ActionModule ] [XF1iu6t] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-12-25T21:21:13,581][INFO ][o.e.d.DiscoveryModule ] [XF1iu6t] using discovery type [zen] and host providers [settings]
[2019-12-25T21:21:15,038][INFO ][o.e.n.Node ] [XF1iu6t] initialized
[2019-12-25T21:21:15,038][INFO ][o.e.n.Node ] [XF1iu6t] starting ...
[2019-12-25T21:21:15,674][INFO ][o.e.t.TransportService ] [XF1iu6t] publish_address {192.168.0.120:9300}, bound_addresses {192.168.0.120:9300}
[2019-12-25T21:21:15,707][INFO ][o.e.b.BootstrapChecks ] [XF1iu6t] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3764] for user [esuser] 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]
[2019-12-25T21:21:15,725][INFO ][o.e.n.Node ] [XF1iu6t] stopping ...
[2019-12-25T21:21:15,750][INFO ][o.e.n.Node ] [XF1iu6t] stopped
[2019-12-25T21:21:15,750][INFO ][o.e.n.Node ] [XF1iu6t] closing ...
[2019-12-25T21:21:15,790][INFO ][o.e.n.Node ] [XF1iu6t] closed
[2019-12-25T21:21:15,793][INFO ][o.e.x.m.p.NativeController] [XF1iu6t] Native controller process has stopped - no new native processes can be started
[esuser@backup01 bin]$
通过查看日志我们发现了ERROR
切换到root修改配置文件
错误[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[esuser@backup01 bin]$ su root
Password:
[root@backup01 bin]# vim /etc/security/limits.conf
[root@backup01 bin]#
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
* 表示通配符 这里可以使用es的专属用户
esuser soft nofile 65536
esuser hard nofile 65536
esuser soft nproc 4096
esuser hard nproc 4096
错误[2]:max number of threads [3764] for user [esuser] is too low, increase to at least [4096]
修改 修改XX-nproc.conf (不同机器XX不一样,可先到 cd /etc/security/limits.d/ 查看下)
vim 20-nproc.conf
* 表示通配符 这里可以使用es的专属用户
* soft nproc 4096 可以改为 esuser soft nproc 4096
错误[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
编辑 vim /etc/sysctl.conf,追加以下内容:
vm.max_map_count=655360
保存后,执行:
sysctl -p
重新启动:
[root@backup01 limits.d]# su esuser
[esuser@backup01 limits.d]$ cd /usr/local/java/elasticsearch-6.8.6/bin/
[esuser@backup01 bin]$ ./elasticsearch
[2019-12-25T21:55:16,315][INFO ][o.e.e.NodeEnvironment ] [XF1iu6t] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [25.4gb], net total_space [39.9gb], types [rootfs]
[2019-12-25T21:55:16,331][INFO ][o.e.e.NodeEnvironment ] [XF1iu6t] heap size [503.6mb], compressed ordinary object pointers [true]
[2019-12-25T21:55:16,334][INFO ][o.e.n.Node ] [XF1iu6t] node name derived from node ID [XF1iu6tZTT2SyUnPu6Ud2A]; set [node.name] to override
[2019-12-25T21:55:16,334][INFO ][o.e.n.Node ] [XF1iu6t] version[6.8.6], pid[34499], build[default/tar/3d9f765/2019-12-13T17:11:52.013738Z], OS[Linux/3.10.0-862.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_172/25.172-b11]
[2019-12-25T21:55:16,334][INFO ][o.e.n.Node ] [XF1iu6t] JVM arguments [-Xms512m, -Xmx512m, -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-534418274257154579, -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/java/elasticsearch-6.8.6, -Des.path.conf=/usr/local/java/elasticsearch-6.8.6/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[2019-12-25T21:55:21,978][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [aggs-matrix-stats]
[2019-12-25T21:55:21,978][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [analysis-common]
[2019-12-25T21:55:21,978][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [ingest-common]
[2019-12-25T21:55:21,978][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [ingest-geoip]
[2019-12-25T21:55:21,978][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [ingest-user-agent]
[2019-12-25T21:55:21,978][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [lang-expression]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [lang-mustache]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [lang-painless]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [mapper-extras]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [parent-join]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [percolator]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [rank-eval]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [reindex]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [repository-url]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [transport-netty4]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [tribe]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-ccr]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-core]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-deprecation]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-graph]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-ilm]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-logstash]
[2019-12-25T21:55:21,979][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-ml]
[2019-12-25T21:55:21,980][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-monitoring]
[2019-12-25T21:55:21,980][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-rollup]
[2019-12-25T21:55:21,980][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-security]
[2019-12-25T21:55:21,980][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-sql]
[2019-12-25T21:55:21,980][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-upgrade]
[2019-12-25T21:55:21,980][INFO ][o.e.p.PluginsService ] [XF1iu6t] loaded module [x-pack-watcher]
[2019-12-25T21:55:21,980][INFO ][o.e.p.PluginsService ] [XF1iu6t] no plugins loaded
[2019-12-25T21:55:31,445][INFO ][o.e.x.s.a.s.FileRolesStore] [XF1iu6t] parsed [0] roles from file [/usr/local/java/elasticsearch-6.8.6/config/roles.yml]
[2019-12-25T21:55:32,907][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [XF1iu6t] [controller/34621] [Main.cc@109] controller (64 bit): Version 6.8.6 (Build 73ed602c10c48e) Copyright (c) 2019 Elasticsearch BV
[2019-12-25T21:55:34,315][DEBUG][o.e.a.ActionModule ] [XF1iu6t] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-12-25T21:55:34,776][INFO ][o.e.d.DiscoveryModule ] [XF1iu6t] using discovery type [zen] and host providers [settings]
[2019-12-25T21:55:36,750][INFO ][o.e.n.Node ] [XF1iu6t] initialized
[2019-12-25T21:55:36,750][INFO ][o.e.n.Node ] [XF1iu6t] starting ...
[2019-12-25T21:55:37,242][INFO ][o.e.t.TransportService ] [XF1iu6t] publish_address {192.168.0.120:9300}, bound_addresses {192.168.0.120:9300}
[2019-12-25T21:55:37,265][INFO ][o.e.b.BootstrapChecks ] [XF1iu6t] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-12-25T21:55:40,380][INFO ][o.e.c.s.MasterService ] [XF1iu6t] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {XF1iu6t}{XF1iu6tZTT2SyUnPu6Ud2A}{d6YuCsV-Q32oZ5ECprc-Lg}{192.168.0.120}{192.168.0.120:9300}{ml.machine_memory=1021906944, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2019-12-25T21:55:40,385][INFO ][o.e.c.s.ClusterApplierService] [XF1iu6t] new_master {XF1iu6t}{XF1iu6tZTT2SyUnPu6Ud2A}{d6YuCsV-Q32oZ5ECprc-Lg}{192.168.0.120}{192.168.0.120:9300}{ml.machine_memory=1021906944, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {XF1iu6t}{XF1iu6tZTT2SyUnPu6Ud2A}{d6YuCsV-Q32oZ5ECprc-Lg}{192.168.0.120}{192.168.0.120:9300}{ml.machine_memory=1021906944, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2019-12-25T21:55:40,508][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [XF1iu6t] Failed to clear cache for realms [[]]
[2019-12-25T21:55:40,539][INFO ][o.e.h.n.Netty4HttpServerTransport] [XF1iu6t] publish_address {192.168.0.120:9200}, bound_addresses {192.168.0.120:9200}
[2019-12-25T21:55:40,539][INFO ][o.e.n.Node ] [XF1iu6t] started
[2019-12-25T21:55:40,625][INFO ][o.e.g.GatewayService ] [XF1iu6t] recovered [0] indices into cluster_state
[2019-12-25T21:55:41,115][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.triggered_watches] for index patterns [.triggered_watches*]
[2019-12-25T21:55:41,269][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.watch-history-9] for index patterns [.watcher-history-9*]
[2019-12-25T21:55:41,311][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.watches] for index patterns [.watches*]
[2019-12-25T21:55:41,381][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*]
[2019-12-25T21:55:41,605][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.monitoring-es] for index patterns [.monitoring-es-6-*]
[2019-12-25T21:55:41,661][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*]
[2019-12-25T21:55:41,710][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]
[2019-12-25T21:55:41,757][INFO ][o.e.c.m.MetaDataIndexTemplateService] [XF1iu6t] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]
[2019-12-25T21:55:41,969][INFO ][o.e.l.LicenseService ] [XF1iu6t] license [90241c6a-de4a-4bc7-93a5-4e0f5b0baedf] mode [basic] - valid
启动成功,我们知道ES是restful的那就用curl命令测试下是否真费成功,当我们看见下的信息说明已经成功
注意:ElasticSearch启动可以后台启动,我上面是前台启动,后台启动只需要加上 -d
同样是可以启动成功的