(一)centos7.3安装elasticsearch7.0.0
下载
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
安装
linux下usr/local目录下创建elasticsearch目录
cd usr/local
mkdir elasticsearch
解压elasticsearch压缩包
将elasticsearch-7.0.0-linux-x86_64.tar.gz拷贝到usr/local/elasticsearch目录下,并解压
tar -avxf elasticsearch-7.0.0-linux-x86_64.tar.gz -C /usr/local/elasticsearch
编辑config/elasticsearch.yml
取消下列注释并修改
#取消以下注释
cluster.name: my-application
node.name: node-1
#添加数据和日志的存储目录(启动之前要先创建好data目录)
path.data: /usr/local/elasticsearch/elasticsearch-7.0.0/data
path.logs: /usr/local/elasticsearch/elasticsearch-7.0.0/logs
#取消以下注释并修改
#设置绑定的ip,设置为0.0.0.0以后就可以让任何计算机节点访问到了
network.host: 0.0.0.0
#取消注释
http.port: 9200
#取消以下注释并修改
#设置在集群中的所有节点名称,这个节点名称就是之前所修改的,当然你也可以采用默认的也行,目前是单机,放入一个节点即可
cluster.initial_master_nodes: ["node-1"]
在elasticsearch-7.0.0创建data目录给予上一步的添加数据和日志的存储目录使用
cd usr/local/elasticsearch/elasticsearch-7.0.0/
mkdir data
启动elasticsearch(前台启动)
./bin/elasticsearch
elasticsearch是不允许使用root用户启动,需要创建新的用户
[root@localhost elasticsearch-7.0.0]# ./bin/elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2019-10-30T07:20:20,304][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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:163) ~[elasticsearch-7.0.0.jar:7.0.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.0.0.jar:7.0.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.0.0.jar:7.0.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.0.0.jar:7.0.0]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.0.0.jar:7.0.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.0.0.jar:7.0.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.0.0.jar:7.0.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:102) ~[elasticsearch-7.0.0.jar:7.0.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:169) ~[elasticsearch-7.0.0.jar:7.0.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:325) ~[elasticsearch-7.0.0.jar:7.0.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.0.0.jar:7.0.0]
... 6 more
创建用户,并设置密码
useradd 用户名
passwd 用户名
su 用户名 #切换用户
错误都解决之后再次启动,启动成功,日志如下:
[admin@localhost elasticsearch-7.0.0]$ ./bin/elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2019-10-30T08:14:16,497][INFO ][o.e.e.NodeEnvironment ] [node-1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [33gb], net total_space [37.4gb], types [rootfs]
[2019-10-30T08:14:16,499][INFO ][o.e.e.NodeEnvironment ] [node-1] heap size [1015.6mb], compressed ordinary object pointers [true]
[2019-10-30T08:14:16,501][INFO ][o.e.n.Node ] [node-1] node name [node-1], node ID [gbGfCsMOQTekbaItmumwQw]
[2019-10-30T08:14:16,501][INFO ][o.e.n.Node ] [node-1] version[7.0.0], pid[2830], build[default/tar/b7e28a7/2019-04-05T22:55:32.697037Z], OS[Linux/3.10.0-514.10.2.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/12/12+33]
[2019-10-30T08:14:16,502][INFO ][o.e.n.Node ] [node-1] JVM home [/usr/local/elasticsearch/elasticsearch-7.0.0/jdk]
[2019-10-30T08:14:16,502][INFO ][o.e.n.Node ] [node-1] 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-2451934697114904436, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -Dio.netty.allocator.type=unpooled, -Des.path.home=/usr/local/elasticsearch/elasticsearch-7.0.0, -Des.path.conf=/usr/local/elasticsearch/elasticsearch-7.0.0/config, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=true]
[2019-10-30T08:14:20,851][INFO ][o.e.p.PluginsService ] [node-1] loaded module [aggs-matrix-stats]
[2019-10-30T08:14:20,858][INFO ][o.e.p.PluginsService ] [node-1] loaded module [analysis-common]
[2019-10-30T08:14:20,859][INFO ][o.e.p.PluginsService ] [node-1] loaded module [ingest-common]
[2019-10-30T08:14:20,859][INFO ][o.e.p.PluginsService ] [node-1] loaded module [ingest-geoip]
[2019-10-30T08:14:20,859][INFO ][o.e.p.PluginsService ] [node-1] loaded module [ingest-user-agent]
[2019-10-30T08:14:20,859][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-expression]
[2019-10-30T08:14:20,860][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-mustache]
[2019-10-30T08:14:20,860][INFO ][o.e.p.PluginsService ] [node-1] loaded module [lang-painless]
[2019-10-30T08:14:20,860][INFO ][o.e.p.PluginsService ] [node-1] loaded module [mapper-extras]
[2019-10-30T08:14:20,861][INFO ][o.e.p.PluginsService ] [node-1] loaded module [parent-join]
[2019-10-30T08:14:20,861][INFO ][o.e.p.PluginsService ] [node-1] loaded module [percolator]
[2019-10-30T08:14:20,861][INFO ][o.e.p.PluginsService ] [node-1] loaded module [rank-eval]
[2019-10-30T08:14:20,861][INFO ][o.e.p.PluginsService ] [node-1] loaded module [reindex]
[2019-10-30T08:14:20,862][INFO ][o.e.p.PluginsService ] [node-1] loaded module [repository-url]
[2019-10-30T08:14:20,862][INFO ][o.e.p.PluginsService ] [node-1] loaded module [transport-netty4]
[2019-10-30T08:14:20,862][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-ccr]
[2019-10-30T08:14:20,862][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-core]
[2019-10-30T08:14:20,863][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-deprecation]
[2019-10-30T08:14:20,863][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-graph]
[2019-10-30T08:14:20,864][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-ilm]
[2019-10-30T08:14:20,864][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-logstash]
[2019-10-30T08:14:20,864][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-ml]
[2019-10-30T08:14:20,864][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-monitoring]
[2019-10-30T08:14:20,865][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-rollup]
[2019-10-30T08:14:20,865][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-security]
[2019-10-30T08:14:20,865][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-sql]
[2019-10-30T08:14:20,865][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-watcher]
[2019-10-30T08:14:20,866][INFO ][o.e.p.PluginsService ] [node-1] no plugins loaded
[2019-10-30T08:14:28,503][INFO ][o.e.x.s.a.s.FileRolesStore] [node-1] parsed [0] roles from file [/usr/local/elasticsearch/elasticsearch-7.0.0/config/roles.yml]
[2019-10-30T08:14:30,602][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [node-1] [controller/2894] [Main.cc@109] controller (64 bit): Version 7.0.0 (Build cdaa022645f38d) Copyright (c) 2019 Elasticsearch BV
[2019-10-30T08:14:31,672][DEBUG][o.e.a.ActionModule ] [node-1] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-10-30T08:14:32,068][INFO ][o.e.d.DiscoveryModule ] [node-1] using discovery type [zen] and seed hosts providers [settings]
[2019-10-30T08:14:33,717][INFO ][o.e.n.Node ] [node-1] initialized
[2019-10-30T08:14:33,717][INFO ][o.e.n.Node ] [node-1] starting ...
[2019-10-30T08:14:34,013][INFO ][o.e.t.TransportService ] [node-1] publish_address {192.168.6.166:9300}, bound_addresses {[::]:9300}
[2019-10-30T08:14:34,025][INFO ][o.e.b.BootstrapChecks ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-10-30T08:14:34,061][INFO ][o.e.c.c.Coordinator ] [node-1] setting initial configuration to VotingConfiguration{gbGfCsMOQTekbaItmumwQw}
[2019-10-30T08:14:34,397][INFO ][o.e.c.s.MasterService ] [node-1] elected-as-master ([1] nodes joined)[{node-1}{gbGfCsMOQTekbaItmumwQw}{ZtFeS0BdQ2Cac1qhXostlA}{192.168.6.166}{192.168.6.166:9300}{ml.machine_memory=1929347072, xpack.installed=true, ml.max_open_jobs=20} elect leader, _BECOME_MASTER_TASK_, _FINISH_ELECTION_], term: 1, version: 1, reason: master node changed {previous [], current [{node-1}{gbGfCsMOQTekbaItmumwQw}{ZtFeS0BdQ2Cac1qhXostlA}{192.168.6.166}{192.168.6.166:9300}{ml.machine_memory=1929347072, xpack.installed=true, ml.max_open_jobs=20}]}
[2019-10-30T08:14:34,564][INFO ][o.e.c.s.ClusterApplierService] [node-1] master node changed {previous [], current [{node-1}{gbGfCsMOQTekbaItmumwQw}{ZtFeS0BdQ2Cac1qhXostlA}{192.168.6.166}{192.168.6.166:9300}{ml.machine_memory=1929347072, xpack.installed=true, ml.max_open_jobs=20}]}, term: 1, version: 1, reason: Publication{term=1, version=1}
[2019-10-30T08:14:34,714][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [node-1] Failed to clear cache for realms [[]]
[2019-10-30T08:14:34,811][INFO ][o.e.h.AbstractHttpServerTransport] [node-1] publish_address {192.168.6.166:9200}, bound_addresses {[::]:9200}
[2019-10-30T08:14:34,812][INFO ][o.e.n.Node ] [node-1] started
[2019-10-30T08:14:35,004][INFO ][o.e.g.GatewayService ] [node-1] recovered [0] indices into cluster_state
[2019-10-30T08:14:35,640][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.triggered_watches] for index patterns [.triggered_watches*]
[2019-10-30T08:14:35,743][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.watches] for index patterns [.watches*]
[2019-10-30T08:14:35,905][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.watch-history-9] for index patterns [.watcher-history-9*]
[2019-10-30T08:14:35,950][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-7-*]
[2019-10-30T08:14:36,021][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.monitoring-es] for index patterns [.monitoring-es-7-*]
[2019-10-30T08:14:36,160][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.monitoring-beats] for index patterns [.monitoring-beats-7-*]
[2019-10-30T08:14:36,260][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.monitoring-alerts-7] for index patterns [.monitoring-alerts-7]
[2019-10-30T08:14:36,341][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-1] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-7-*]
[2019-10-30T08:14:36,470][INFO ][o.e.x.i.a.TransportPutLifecycleAction] [node-1] adding index lifecycle policy [watch-history-ilm-policy]
[2019-10-30T08:14:36,805][INFO ][o.e.l.LicenseService ] [node-1] license [7f0b75ad-4d3c-4c6e-ad68-f6f387980733] mode [basic] - valid
访问ip地址:http://192.168.6.166:9200/ ,访问成功
启动elasticsearch(后台启动)
./bin/elasticsearch -d
(二)解决elasticsearch配置network.host: 0.0.0.0导致elasticsearch服务启动不成功的问题
一、问题概述
本人在本地的虚拟机linux上安装的elasticsearch。
当修改 elasticsearch.yml 文件的 network.host: 0.0.0.0 时,引起了一系列异常,导致服务无法成功启动。
network.host: 0.0.0.0
引起的问题:elasticsearch服务进程启动一会之后,通过jps命令查看到进程关闭,命令行不提示错误。打开另一个命令行窗口,输入 curl 127.0.0.1:9200 提示 curl: (7) couldn’t connect to host 错误。
二、解决思路
elasticsearch下有个logs包,里面有个elasticsearch.log 日志文件,可查看错误日志排查问题。
错误日志如下:
9-04-26T03:28:02,929][DEBUG][o.e.a.ActionModule ] [localhost.localdomain] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-04-26T03:28:03,778][INFO ][o.e.d.DiscoveryModule ] [localhost.localdomain] using discovery type [zen] and seed hosts providers [settings]
[2019-04-26T03:28:05,374][INFO ][o.e.n.Node ] [localhost.localdomain] initialized
[2019-04-26T03:28:05,374][INFO ][o.e.n.Node ] [localhost.localdomain] starting ...
[2019-04-26T03:28:05,856][INFO ][o.e.t.TransportService ] [localhost.localdomain] publish_address {192.168.33.121:9300}, bound_addresses {192.168.33.121:9300}
[2019-04-26T03:28:05,862][INFO ][o.e.b.BootstrapChecks ] [localhost.localdomain] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-04-26T03:28:05,915][ERROR][o.e.b.Bootstrap ] [localhost.localdomain] node validation exception
[4] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3818] for user [admin] 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]
[4]: 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
[2019-04-26T03:28:05,928][INFO ][o.e.n.Node ] [localhost.localdomain] stopping ...
[2019-04-26T03:28:05,939][INFO ][o.e.n.Node ] [localhost.localdomain] stopped
[2019-04-26T03:28:05,940][INFO ][o.e.n.Node ] [localhost.localdomain] closing ...
[2019-04-26T03:28:05,955][INFO ][o.e.n.Node ] [localhost.localdomain] closed
[2019-04-26T03:28:05,956][INFO ][o.e.x.m.p.NativeController] [localhost.localdomain] Native controller process has stopped - no new native processes can be started
主要关注以下错误日志
异常1:
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
vim /etc/security/limits.conf文件,添加以以下两行即可解决
* soft nofile 65535
* hard nofile 65535
异常2
[2]: max number of threads [3818] for user [admin] is too low, increase to at least [4096]
vim /etc/security/limits.conf文件,添加以下两行即可解决
* soft nproc 4096
* hard nproc 4096
异常3
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
vim /etc/sysctl.conf 文件,添加以下一行即可解决,注意,这里配置完之后需要重启一下linux,否则不一定起效果
vm.max_map_count=262144
异常4
[4]: 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
vim /usr/local/elasticsearch/elasticsearch-7.0.0/config/elasticsearch.yml 文件,添加一下行即可解决
cluster.initial_master_nodes: ["node-1"]