Elasticsearch 5.x 安装与配置

2018-01-02 16:54:27 浏览数 (1)

Elasticsearch官方建议使用 Oracle的JDK8

1、下载安装

代码语言:javascript复制
[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帐号启动,所以我们要添加一个用户。

代码语言:javascript复制
    [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

代码语言:javascript复制
    [root@vnode0 elasticsearch-5.1.1]# groupadd elasticsearch

分配els用户到elasticsearch用户组

代码语言:javascript复制
    [root@vnode0 elasticsearch-5.1.1]# usermod -G elasticsearch els

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

代码语言:javascript复制
    [root@vnode0 elasticsearch-5.1.1]# chown  -R els.elasticsearch *

更改目录的用户和用户组

代码语言:javascript复制
    [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

代码语言:javascript复制
    [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

代码语言:javascript复制
    [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

代码语言:javascript复制
    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 添加类似如下内容

代码语言:javascript复制
    [root@vnode0 elasticsearch-5.1.1]# vi /etc/security/limits.conf
代码语言:javascript复制
添加如下内容:
代码语言:javascript复制
    * soft nofile 65536

    * hard nofile 131072

    * soft nproc 2048

    * hard nproc 4096

5、启动与浏览器访问

代码语言:javascript复制
    [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/ 显示:

代码语言:javascript复制
    {

      "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、停止

代码语言:javascript复制
    ctrl c停止:

    ^Z

    [1]   Stopped                 ./bin/elasticsearch

7、再次启动:

代码语言:javascript复制
    [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
代码语言:javascript复制
    [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 人点赞