Centos下安装ElasticSearch 6.5

1. 安装ES(官网有描述,这里再做个介绍吧)

打开ES官网https://www.elastic.co/downloads/elasticsearch,下载安装包

将下载好的tar.gz包放置到我们待安装的目录,这里以/opt目录为例,然后进行解压

[root@newbang1 opt]# tar -zxvf elasticsearch-6.5.4.tar.gz 

解压后会得到一个elasticsearch-6.5.4程序文件夹,里面的结构大概是这样子的

2. 创建ES用户

默认ES 6.X 是不允许root用户运行的,否则ES运行的时候会报错,所以我们需要创建新的用户

[root@newbang1 elasticsearch-6.5.4]# useradd wanghe


3. 修改ES目录权限

[root@newbang1 opt]# chown -R wanghe:wanghe elasticsearch-6.5.4/

4. 启动ES

 我们切换至我们之前新建的用户wanghe,然后以后台方式启动ElasticSearch

[root@newbang1 elasticsearch-6.5.4]# su wanghe
[wanghe@newbang1 elasticsearch-6.5.4]$ nohup ./bin/elasticsearch &

查看启动信息

[2018-12-30T14:55:05,128][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:140) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.4.jar:6.5.4]
	... 6 more
[2018-12-30T14:58:17,373][WARN ][o.e.b.JNANatives         ] [unknown] unable to install syscall filter: 
java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
	at org.elasticsearch.bootstrap.SystemCallFilter.linuxImpl(SystemCallFilter.java:341) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.SystemCallFilter.init(SystemCallFilter.java:616) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.JNANatives.tryInstallSystemCallFilter(JNANatives.java:258) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Natives.tryInstallSystemCallFilter(Natives.java:113) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:108) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) [elasticsearch-cli-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-cli-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) [elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) [elasticsearch-6.5.4.jar:6.5.4]
[2018-12-30T14:58:17,935][INFO ][o.e.e.NodeEnvironment    ] [ZTEsSJS] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.6gb], net total_space [17.3gb], types [rootfs]
[2018-12-30T14:58:17,936][INFO ][o.e.e.NodeEnvironment    ] [ZTEsSJS] heap size [1007.3mb], compressed ordinary object pointers [true]
[2018-12-30T14:58:17,939][INFO ][o.e.n.Node               ] [ZTEsSJS] node name derived from node ID [ZTEsSJSES8SfAl2BZ1gVpQ]; set [node.name] to override
[2018-12-30T14:58:17,939][INFO ][o.e.n.Node               ] [ZTEsSJS] version[6.5.4], pid[7611], build[default/tar/d2ef93d/2018-12-17T21:17:40.758843Z], OS[Linux/2.6.32-642.el6.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_161/25.161-b12]
[2018-12-30T14:58:17,940][INFO ][o.e.n.Node               ] [ZTEsSJS] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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.C1TuZUyQ, -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=/opt/elasticsearch-6.5.4, -Des.path.conf=/opt/elasticsearch-6.5.4/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[2018-12-30T14:58:21,778][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [aggs-matrix-stats]
[2018-12-30T14:58:21,779][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [analysis-common]
[2018-12-30T14:58:21,779][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [ingest-common]
[2018-12-30T14:58:21,779][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [lang-expression]
[2018-12-30T14:58:21,780][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [lang-mustache]
[2018-12-30T14:58:21,780][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [lang-painless]
[2018-12-30T14:58:21,780][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [mapper-extras]
[2018-12-30T14:58:21,781][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [parent-join]
[2018-12-30T14:58:21,781][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [percolator]
[2018-12-30T14:58:21,781][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [rank-eval]
[2018-12-30T14:58:21,782][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [reindex]
[2018-12-30T14:58:21,782][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [repository-url]
[2018-12-30T14:58:21,783][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [transport-netty4]
[2018-12-30T14:58:21,783][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [tribe]
[2018-12-30T14:58:21,783][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-ccr]
[2018-12-30T14:58:21,784][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-core]
[2018-12-30T14:58:21,785][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-deprecation]
[2018-12-30T14:58:21,785][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-graph]
[2018-12-30T14:58:21,785][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-logstash]
[2018-12-30T14:58:21,786][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-ml]
[2018-12-30T14:58:21,786][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-monitoring]
[2018-12-30T14:58:21,786][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-rollup]
[2018-12-30T14:58:21,787][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-security]
[2018-12-30T14:58:21,788][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-sql]
[2018-12-30T14:58:21,788][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-upgrade]
[2018-12-30T14:58:21,788][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] loaded module [x-pack-watcher]
[2018-12-30T14:58:21,789][INFO ][o.e.p.PluginsService     ] [ZTEsSJS] no plugins loaded
[2018-12-30T14:58:30,609][INFO ][o.e.x.s.a.s.FileRolesStore] [ZTEsSJS] parsed [0] roles from file [/opt/elasticsearch-6.5.4/config/roles.yml]
[2018-12-30T14:58:31,917][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [ZTEsSJS] [controller/7670] [Main.cc@109] controller (64 bit): Version 6.5.4 (Build b616085ef32393) Copyright (c) 2018 Elasticsearch BV
[2018-12-30T14:58:33,151][DEBUG][o.e.a.ActionModule       ] [ZTEsSJS] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2018-12-30T14:58:33,585][INFO ][o.e.d.DiscoveryModule    ] [ZTEsSJS] using discovery type [zen] and host providers [settings]
[2018-12-30T14:58:35,196][INFO ][o.e.n.Node               ] [ZTEsSJS] initialized
[2018-12-30T14:58:35,196][INFO ][o.e.n.Node               ] [ZTEsSJS] starting ...
[2018-12-30T14:58:35,446][INFO ][o.e.t.TransportService   ] [ZTEsSJS] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2018-12-30T14:58:35,499][WARN ][o.e.b.BootstrapChecks    ] [ZTEsSJS] system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[2018-12-30T14:58:38,584][INFO ][o.e.c.s.MasterService    ] [ZTEsSJS] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {ZTEsSJS}{ZTEsSJSES8SfAl2BZ1gVpQ}{dQ3pUwlfTf6SXIyoCcskEA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=6134722560, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2018-12-30T14:58:38,593][INFO ][o.e.c.s.ClusterApplierService] [ZTEsSJS] new_master {ZTEsSJS}{ZTEsSJSES8SfAl2BZ1gVpQ}{dQ3pUwlfTf6SXIyoCcskEA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=6134722560, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {ZTEsSJS}{ZTEsSJSES8SfAl2BZ1gVpQ}{dQ3pUwlfTf6SXIyoCcskEA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=6134722560, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-12-30T14:58:38,651][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [ZTEsSJS] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}
[2018-12-30T14:58:38,651][INFO ][o.e.n.Node               ] [ZTEsSJS] started
[2018-12-30T14:58:38,735][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [ZTEsSJS] Failed to clear cache for realms [[]]
[2018-12-30T14:58:38,919][INFO ][o.e.g.GatewayService     ] [ZTEsSJS] recovered [0] indices into cluster_state
[2018-12-30T14:58:39,280][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.watches] for index patterns [.watches*]
[2018-12-30T14:58:39,391][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.triggered_watches] for index patterns [.triggered_watches*]
[2018-12-30T14:58:39,552][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.watch-history-9] for index patterns [.watcher-history-9*]
[2018-12-30T14:58:39,619][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*]
[2018-12-30T14:58:39,731][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.monitoring-es] for index patterns [.monitoring-es-6-*]
[2018-12-30T14:58:39,836][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*]
[2018-12-30T14:58:39,905][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]
[2018-12-30T14:58:39,968][INFO ][o.e.c.m.MetaDataIndexTemplateService] [ZTEsSJS] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]
[2018-12-30T14:58:40,209][INFO ][o.e.l.LicenseService     ] [ZTEsSJS] license [b82e28c5-d68b-4b99-a3f1-2e90efcf0a7e] mode [basic] - valid

本机访问下是否启动正常

[wanghe@newbang1 elasticsearch-6.5.4]$ curl -i "http://localhost:9200"
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 493

{
  "name" : "ZTEsSJS",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "NC5-sTzXQM21DXEetN6lDw",
  "version" : {
    "number" : "6.5.4",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "d2ef93d",
    "build_date" : "2018-12-17T21:17:40.758843Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}


5. 配置ElasticSearch,让ElasticSearch支持外网访问,加入集群等

修改配置文件elasticsearch.yml

[wanghe@newbang1 elasticsearch-6.5.4]$ vi ./config/elasticsearch.yml

去掉以下注释,修改以下配置,cluster.name和node.name根据自己需要进行修改,network.host我这里配成了这台虚拟机的IP地址,http.port默认就是9200,可根据自己需要进行调整



修改后,再次启动ES后,会得到以下报错

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [es] 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]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[2018-12-30T15:06:34,926][INFO ][o.e.n.Node               ] [wanghe-es-node-1] stopping ...
[2018-12-30T15:06:34,975][INFO ][o.e.n.Node               ] [wanghe-es-node-1] stopped
[2018-12-30T15:06:34,975][INFO ][o.e.n.Node               ] [wanghe-es-node-1] closing ...
[2018-12-30T15:06:35,009][INFO ][o.e.n.Node               ] [wanghe-es-node-1] closed
[2018-12-30T15:06:35,018][INFO ][o.e.x.m.j.p.NativeController] [wanghe-es-node-1] Native controller process has stopped - no new native processes can be started


使用root身份,执行以下操作

解决问题【1】【2】

[root@newbang1 elasticsearch-6.5.4]# vi  /etc/security/limits.conf


在文件未添加以下内容(开头wanghe 为我们启动es的用户名)

wanghe soft nofile 65536

wanghe hard nofile 131072

wanghe soft nproc 4096

wanghe hard nproc 4096


解决问题【3】

[root@newbang1 elasticsearch-6.5.4]# sysctl -w vm.max_map_count=262144
[root@newbang1 elasticsearch-6.5.4]# vi  /etc/sysctl.conf

在文末加入以下内容后保存退出


解决问题【4】

Centos6不支持SecComp,而ES6默认bootstrap.system_call_filter为true

切回至es专用账户wanghe,然后编辑elasticsearch的配置文件

[wanghe@newbang1 elasticsearch-6.5.4]$ vi ./config/elasticsearch.yml 

禁用:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面: 

取消bootstrap.memory_lock的注释,添加bootstrap.system_call_filter 配置

再次启动es,成功启动

[2018-12-30T15:18:38,193][INFO ][o.e.n.Node               ] [wanghe-es-node-1] initialized
[2018-12-30T15:18:38,194][INFO ][o.e.n.Node               ] [wanghe-es-node-1] starting ...
[2018-12-30T15:18:38,458][INFO ][o.e.t.TransportService   ] [wanghe-es-node-1] publish_address {10.0.3.113:9300}, bound_addresses {10.0.3.113:9300}
[2018-12-30T15:18:38,498][INFO ][o.e.b.BootstrapChecks    ] [wanghe-es-node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2018-12-30T15:18:41,659][INFO ][o.e.c.s.MasterService    ] [wanghe-es-node-1] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {wanghe-es-node-1}{ZTEsSJSES8SfAl2BZ1gVpQ}{S4kReGQZQuCUWPxujEtlCA}{10.0.3.113}{10.0.3.113:9300}{ml.machine_memory=6134722560, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2018-12-30T15:18:41,669][INFO ][o.e.c.s.ClusterApplierService] [wanghe-es-node-1] new_master {wanghe-es-node-1}{ZTEsSJSES8SfAl2BZ1gVpQ}{S4kReGQZQuCUWPxujEtlCA}{10.0.3.113}{10.0.3.113:9300}{ml.machine_memory=6134722560, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {wanghe-es-node-1}{ZTEsSJSES8SfAl2BZ1gVpQ}{S4kReGQZQuCUWPxujEtlCA}{10.0.3.113}{10.0.3.113:9300}{ml.machine_memory=6134722560, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-12-30T15:18:41,715][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [wanghe-es-node-1] publish_address {10.0.3.113:9200}, bound_addresses {10.0.3.113:9200}
[2018-12-30T15:18:41,716][INFO ][o.e.n.Node               ] [wanghe-es-node-1] started
[2018-12-30T15:18:42,381][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [wanghe-es-node-1] Failed to clear cache for realms [[]]
[2018-12-30T15:18:42,488][INFO ][o.e.l.LicenseService     ] [wanghe-es-node-1] license [b82e28c5-d68b-4b99-a3f1-2e90efcf0a7e] mode [basic] - valid
[2018-12-30T15:18:42,521][INFO ][o.e.g.GatewayService     ] [wanghe-es-node-1] recovered [0] indices into cluster_state

最后,我们可以打开浏览器进行外部访问

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值