Elasticsearch 5.x 安装与配置

Elasticsearch官方建议使用 Oracle的JDK8

1、下载安装

[root@vnode0 opt]# tar -zxvf elasticsearch-5.1.1.tar.gz 

[root@vnode0 opt]# cd elasticsearch-5.1.1

[root@vnode0 elasticsearch-5.1.1]# ./bin/elasticsearch

[2016-12-20T02:53:36,188][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:125) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.cli.Command.main(Command.java:62) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.1.jar:5.1.1]

Caused by: java.lang.RuntimeException: can not run elasticsearch as root

at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:100) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:176) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.1.jar:5.1.1]

at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.1.jar:5.1.1]


[root@vnode0 elasticsearch-5.1.1]# 

2、为elasticsearch创建用户和用户组

因为版本的问题,最新的版本安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户。

    [root@vnode0 elasticsearch-5.1.1]# useradd els

    [root@vnode0 elasticsearch-5.1.1]# passwd els

    Changing password for user els.

    New password: 

    BAD PASSWORD: The password is shorter than 8 characters

    Retype new password: 

    passwd: all authentication tokens updated successfully.

创建用户组elasticsearch

    [root@vnode0 elasticsearch-5.1.1]# groupadd elasticsearch

分配els用户到elasticsearch用户组

    [root@vnode0 elasticsearch-5.1.1]# usermod -G elasticsearch els

给定用户权限。-R表示逐级(N层目录) , * 表示 任何文件

    [root@vnode0 elasticsearch-5.1.1]# chown  -R els.elasticsearch *

更改目录的用户和用户组

    [root@vnode0 opt]# chown -R els:elasticsearch elasticsearch-5.1.1

    [root@vnode0 opt]# ll

    total 244048

    drwxr-xr-x 9 els  elasticsearch       145 Dec 20 03:28 elasticsearch-5.1.1

    -rwxr-xr-x 1 root root           33196711 Dec 20 02:25 elasticsearch-5.1.1.rpm

    -rwxr-xr-x 1 root root           33291322 Dec 20 02:44 elasticsearch-5.1.1.tar.gz

    drwxr-xr-x 3 root root                 53 Feb 13  2016 elasticsearch-servicewrapper-master

    -rwxr-xr-x 1 root root            2054227 Dec 20 02:43 elasticsearch-servicewrapper-master.zip

    drwxr-xr-x 8   10           143      4096 Jun 22 06:13 jdk1.8.0_101

    -rw-r--r-- 1 root root          181352138 Dec 17 01:59 jdk-8u101-linux-x64.tar.gz

    [root@vnode0 opt]# 

3、修改host和port

    [root@vnode0 elasticsearch-5.1.1]# su els

    [els@vnode0 elasticsearch-5.1.1]$ 

    [els@vnode0 config]$ vi elasticsearch.yml

    # Set the bind address to a specific IP (IPv4 or IPv6):

    network.host: 192.168.1.180

    # Set a custom port for HTTP:

    http.port: 9200

    # 增加新的参数,这样head插件可以访问es。设置参数的时候:后面要有空格

    http.cors.enabled: true

    http.cors.allow-origin: "*"

4、修改limits.conf

    [els@vnode0 elasticsearch-5.1.1]$ ./bin/elasticsearch

    [2016-12-20T03:28:25,298][INFO ][o.e.n.Node               ] [] initializing ...

    [2016-12-20T03:28:25,368][INFO ][o.e.e.NodeEnvironment    ] [fzf84xy] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [22.2gb], net total_space [35.4gb], spins? [unknown], types [rootfs]

    [2016-12-20T03:28:25,368][INFO ][o.e.e.NodeEnvironment    ] [fzf84xy] heap size [1.9gb], compressed ordinary object pointers [true]

    [2016-12-20T03:28:25,370][INFO ][o.e.n.Node               ] node name [fzf84xy] derived from node ID [fzf84xyZR1eHEpm4P_TVOw]; set [node.name] to override

    [2016-12-20T03:28:25,372][INFO ][o.e.n.Node               ] version[5.1.1], pid[82041], build[5395e21/2016-12-06T12:36:15.409Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_101/25.101-b13]

    [2016-12-20T03:28:26,183][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [aggs-matrix-stats]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [ingest-common]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-expression]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-groovy]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-mustache]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-painless]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [percolator]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [reindex]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [transport-netty3]

    [2016-12-20T03:28:26,184][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [transport-netty4]

    [2016-12-20T03:28:26,185][INFO ][o.e.p.PluginsService     ] [fzf84xy] no plugins loaded

    [2016-12-20T03:28:27,822][INFO ][o.e.n.Node               ] initialized

    [2016-12-20T03:28:27,822][INFO ][o.e.n.Node               ] [fzf84xy] starting ...

    [2016-12-20T03:28:27,994][INFO ][o.e.t.TransportService   ] [fzf84xy] publish_address {192.168.1.180:9300}, bound_addresses {192.168.1.180:9300}

    [2016-12-20T03:28:28,001][INFO ][o.e.b.BootstrapCheck     ] [fzf84xy] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks

    ERROR: bootstrap checks failed

    max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

    [2016-12-20T03:28:28,006][INFO ][o.e.n.Node               ] [fzf84xy] stopping ...

    [2016-12-20T03:28:28,024][INFO ][o.e.n.Node               ] [fzf84xy] stopped

    [2016-12-20T03:28:28,025][INFO ][o.e.n.Node               ] [fzf84xy] closing ...

    [2016-12-20T03:28:28,036][INFO ][o.e.n.Node               ] [fzf84xy] closed

    [els@vnode0 elasticsearch-5.1.1]$ 

问题二:ERROR: bootstrap checks failed

    max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

    max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]

解决:切换到root用户,编辑limits.conf 添加类似如下内容

    [root@vnode0 elasticsearch-5.1.1]# vi /etc/security/limits.conf
添加如下内容:
    * soft nofile 65536

    * hard nofile 131072

    * soft nproc 2048

    * hard nproc 4096

5、启动与浏览器访问

    [root@vnode0 elasticsearch-5.1.1]# su els

    [els@vnode0 elasticsearch-5.1.1]$ ./bin/elasticsearch

    [2016-12-20T03:32:46,350][INFO ][o.e.n.Node               ] [] initializing ...

    [2016-12-20T03:32:46,427][INFO ][o.e.e.NodeEnvironment    ] [fzf84xy] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [22.2gb], net total_space [35.4gb], spins? [unknown], types [rootfs]

    [2016-12-20T03:32:46,428][INFO ][o.e.e.NodeEnvironment    ] [fzf84xy] heap size [1.9gb], compressed ordinary object pointers [true]

    [2016-12-20T03:32:46,430][INFO ][o.e.n.Node               ] node name [fzf84xy] derived from node ID [fzf84xyZR1eHEpm4P_TVOw]; set [node.name] to override

    [2016-12-20T03:32:46,433][INFO ][o.e.n.Node               ] version[5.1.1], pid[82131], build[5395e21/2016-12-06T12:36:15.409Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_101/25.101-b13]

    [2016-12-20T03:32:47,232][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [aggs-matrix-stats]

    [2016-12-20T03:32:47,233][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [ingest-common]

    [2016-12-20T03:32:47,233][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-expression]

    [2016-12-20T03:32:47,233][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-groovy]

    [2016-12-20T03:32:47,233][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-mustache]

    [2016-12-20T03:32:47,233][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [lang-painless]

    [2016-12-20T03:32:47,233][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [percolator]

    [2016-12-20T03:32:47,233][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [reindex]

    [2016-12-20T03:32:47,234][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [transport-netty3]

    [2016-12-20T03:32:47,234][INFO ][o.e.p.PluginsService     ] [fzf84xy] loaded module [transport-netty4]

    [2016-12-20T03:32:47,234][INFO ][o.e.p.PluginsService     ] [fzf84xy] no plugins loaded

    [2016-12-20T03:32:48,963][INFO ][o.e.n.Node               ] initialized

    [2016-12-20T03:32:48,963][INFO ][o.e.n.Node               ] [fzf84xy] starting ...

    [2016-12-20T03:32:49,081][INFO ][o.e.t.TransportService   ] [fzf84xy] publish_address {192.168.1.180:9300}, bound_addresses {192.168.1.180:9300}

    [2016-12-20T03:32:49,087][INFO ][o.e.b.BootstrapCheck     ] [fzf84xy] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks

    [2016-12-20T03:32:52,299][INFO ][o.e.c.s.ClusterService   ] [fzf84xy] new_master {fzf84xy}{fzf84xyZR1eHEpm4P_TVOw}{LBgU_8YfTDubnTfwQvh0uA}{192.168.1.180}{192.168.1.180:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)

    [2016-12-20T03:32:52,321][INFO ][o.e.h.HttpServer         ] [fzf84xy] publish_address {192.168.1.180:9200}, bound_addresses {192.168.1.180:9200}

    [2016-12-20T03:32:52,321][INFO ][o.e.n.Node               ] [fzf84xy] started

    [2016-12-20T03:32:52,331][INFO ][o.e.g.GatewayService     ] [fzf84xy] recovered [0] indices into cluster_state

浏览器中输入:http://192.168.1.180:9200/ 显示:

    {

      "name" : "fzf84xy",

      "cluster_name" : "elasticsearch",

      "cluster_uuid" : "OdR07tdQTq2Gj7X6VhDTKA",

      "version" : {

        "number" : "5.1.1",

        "build_hash" : "5395e21",

        "build_date" : "2016-12-06T12:36:15.409Z",

        "build_snapshot" : false,

        "lucene_version" : "6.3.0"

      },

      "tagline" : "You Know, for Search"

    }

6、停止

    ctrl+c停止:

    ^Z

    [1]+  Stopped                 ./bin/elasticsearch

7、再次启动:

    [els@vnode0 opt]$ ./elasticsearch-5.1.1/bin/elasticsearch

    [2016-12-20T03:55:26,222][INFO ][o.e.n.Node               ] [] initializing ...

    [2016-12-20T03:55:26,267][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]

    org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/opt/elasticsearch-5.1.1/data/elasticsearch]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?

        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.cli.Command.main(Command.java:62) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.1.jar:5.1.1]

    Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/opt/elasticsearch-5.1.1/data/elasticsearch]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?

        at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:259) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.node.Node.<init>(Node.java:249) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.node.Node.<init>(Node.java:229) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.bootstrap.Bootstrap$6.<init>(Bootstrap.java:214) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:214) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.1.jar:5.1.1]

        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.1.jar:5.1.1]

        ... 6 more
    [els@vnode0 elasticsearch-5.1.1]$ ps -ef | grep elastic

    els       82131  82118  0 03:32 pts/0    00:00:17 /opt/jdk1.8.0_101/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/opt/elasticsearch-5.1.1 -cp /opt/elasticsearch-5.1.1/lib/elasticsearch-5.1.1.jar:/opt/elasticsearch-5.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch

    els       85604  85399  0 04:45 pts/0    00:00:00 grep --color=auto elastic

    [els@vnode0 elasticsearch-5.1.1]$ kill -9 82131

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏搜云库

CentOs7.3 搭建 RabbitMQ 3.6 单机服务

CentOs7.3 搭建 RabbitMQ 3.6 单机服务 RabbitMQ简介 RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支...

22710
来自专栏后端技术探索

常用nginx配置项详解(一个简单的例子)

核心提示:Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器...

691
来自专栏北京马哥教育

60秒内快速搭建完整zabbix3.4.6监控系统

1585
来自专栏云技术分享

ElasticSearch实战:Linux日志对接Kibana

ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTFul web接口。ElasticSear...

2045
来自专栏搜云库

ElasticSearch 安装报错整理

ElasticSearch 安装报错整理 单机安装报错 初次启动服务 /opt/elasticsearch-5.5.2/bin/elasticsearch 当使...

9718
来自专栏Netkiller

Spring boot with HTTPS SSL

本文节选自《Netkiller Java 手札》 5.24. Spring boot with HTTPS SSL 5.24.1. 生成自签名证书 key...

3404
来自专栏左瞅瞅,右瞅瞅

centos7.x之yum安装zabbix_proxy以及自动注册

zabbix proxy就是所谓的分布式监控,主要是代理zabbix server进行采集数据,zabbix proxy端也需要搭建另外一个mysql数据库,并...

855
来自专栏电光石火

tengine+tomcat+php安装

在安装tengine之前,确认centos环境中有无gcc、pcre、openssl,如果没有按以下命令进行安装

1987
来自专栏JackieZheng

学习Spark——环境搭建(Mac版)

大数据情结 还记得上次跳槽期间,与很多猎头都有聊过,其中有一个猎头告诉我,整个IT跳槽都比较频繁,但是相对来说,做大数据的比较“懒”一些,不太愿意动。后来在一篇...

8328
来自专栏电光石火

tengine+tomcat+php安装

在安装tengine之前,确认centos环境中有无gcc、pcre、openssl,如果没有按以下命令进行安装 #yum install gcc #yu...

18610

扫码关注云+社区