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 条评论
登录 后参与评论

相关文章

来自专栏技术小黑屋

Package Stopped State Since Android 3.1

Since Android 3.1, Android has introduced a LaunchControl mechanism. It’s call S...

861
来自专栏运维

linux文件树

以前有意找这方面的资料,今天突然发现在系统中就有 linux系统用man hier solaris用man  filesystem 其结果如下     ...

842
来自专栏蓝天

Fast Scatter-Gather I/O

Some applications may need to read or write data to multiple buffers, which are ...

914
来自专栏技术小黑屋

Build Android Packages From Command Line

A few months ago,I dealed with a task:To build a large amount of apk files. The...

1083
来自专栏everhad

转载:Package by feature, not layer

The first question in building an application is "How do I divide it up into pac...

1090
来自专栏大数据学习笔记

Hadoop基础教程-第9章 HA高可用(9.3 HDFS 高可用运行)(草稿)

第9章 HA高可用 9.3 HDFS 高可用运行 9.3.1 HA节点规划 节点 IP Zookeeper NameNode JournalNode Da...

2505
来自专栏CreateAMind

通俗易懂 empowered RL

Inspired by examples from the animal kingdom, social sciences and games the ...

721
来自专栏Kubernetes

kube-controller-manager最佳配置

kubernetes version: 1.6.2 Kube-controller-manager Configuration kube-controller-...

4539
来自专栏智能计算时代

Designing your SaaS Database for Scale with Postgres

? If you’re building a SaaS application, you probably already have the notion o...

2084
来自专栏Golang语言社区

在GO中编写一个简单的shell

In this post, we will write a minimalistic shell for UNIX(-like) operating syste...

1275

扫码关注云+社区