Elasticsearch 5.x +Kibana 5.x 安装与配置

Elasticsearch官方建议使用 Oracle的JDK8

1、创建用户和用户组

[root@node1 ~]# groupadd elastic
[root@node1 ~]# useradd elastic -g elastic
[root@node1 ~]# passwd elastic
Changing password for user elastic.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@node1 ~]# 
[root@node1 ~]# visudo
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
elastic ALL=(ALL)       ALL

2、Elasticsearch下载与配置

[root@node1 ~]# tar -zxvf elasticsearch-5.6.5.tar.gz -C /opt
[root@node1 ~]# chown -R elastic:elastic /opt/elasticsearch-5.6.5
[root@node1 ~]# ll /opt/elasticsearch-5.6.5/
total 236
drwxr-xr-x  2 elastic elastic   4096 Apr  8 11:21 bin
drwxr-xr-x  2 elastic elastic   4096 Mar 13 18:08 config
drwxr-xr-x  2 elastic elastic   4096 Mar 13 18:08 lib
-rw-r--r--  1 elastic elastic  11358 Mar 13 18:02 LICENSE.txt
drwxr-xr-x  2 elastic elastic   4096 Mar 13 18:08 logs
drwxr-xr-x 16 elastic elastic   4096 Mar 13 18:08 modules
-rw-r--r--  1 elastic elastic 191887 Mar 13 18:07 NOTICE.txt
drwxr-xr-x  2 elastic elastic   4096 Mar 13 18:08 plugins
-rw-r--r--  1 elastic elastic   9268 Mar 13 18:02 README.textile
[root@node1 ~]#
[root@node1 ~] cd /opt/elasticsearch-5.6.5
[root@node1 elasticsearch-5.6.5]# vi config/elasticsearch.yml
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /tpdata/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: bigdata-es-test
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
[root@node1 ~] mkdir -p /var/log/elasticsearch
[root@node1 ~] mkdir -p /data/elasticsearch
[root@node1 ~] chown -R elastic:elastic /var/log/elasticsearch
[root@node1 ~] chown -R elastic:elastic /data/elasticsearch
[root@node1 ~]# vi /etc/sysctl.conf

在文件最后增加一行

vm.max_map_count=262144

生效

[root@node1 ~]# sysctl -p
vm.max_map_count = 262144
[root@node1 ~]# 
[root@node1 ~]#  vi /etc/security/limits.conf

增加4行

* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096

启动elasticsearch

[root@node1 ~]# su elastic
[elastic@node1 ~] cd /opt/elasticsearch-5.6.5
[elastic@node1 elasticsearch-5.6.5]$ bin/elasticsearch -d
[elastic@node1 elasticsearch-5.6.5]# jps
24364 Jps
23901 Elasticsearch
[elastic@node1 elasticsearch-5.6.5]#

3、Kibana安装与配置

[elastic@node1 ~] sudo tar -zxvf kibana-5.6.5-linux-x86_64.tar.gz -C /opt
[elastic@node1 ~] cd /opt 
[elastic@node1 opt] sudo mv kibana-5.6.5-linux-x86_64  kibana-5.6.5 
[elastic@node1 opt] sudo chown -R elastic:elastic kibana-5.6.5
[elastic@node1 opt] cd kibana-5.6.5
[elastic@node1 kibana-5.6.5]$ vi config/kibana.yml

修改

server.host: "node1"
elasticsearch.url: "http://node1:9200"
[elastic@node1 kibana-5.6.5]$ bin/kibana
  log   [07:16:16.429] [info][status][plugin:kibana@5.6.5] Status changed from uninitialized to green - Ready
  log   [07:16:16.551] [info][status][plugin:elasticsearch@5.6.5] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:16:16.595] [info][status][plugin:console@5.6.5] Status changed from uninitialized to green - Ready
  log   [07:16:16.620] [info][status][plugin:metrics@5.6.5] Status changed from uninitialized to green - Ready
  log   [07:16:16.906] [info][status][plugin:timelion@5.6.5] Status changed from uninitialized to green - Ready
  log   [07:16:16.912] [info][listening] Server running at http://bigdata-es-test:5601
  log   [07:16:16.915] [info][status][ui settings] Status changed from uninitialized to yellow - Elasticsearch plugin is yellow
  log   [07:16:21.984] [info][status][plugin:elasticsearch@5.6.5] Status changed from yellow to yellow - No existing Kibana index found
  log   [07:16:23.405] [info][status][plugin:elasticsearch@5.6.5] Status changed from yellow to green - Kibana index ready
  log   [07:16:23.407] [info][status][ui settings] Status changed from yellow to green - Ready

4、其他问题记录

[root@node1 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@node1 elasticsearch-5.1.1]# 

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

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

    [root@node1 elasticsearch-5.1.1]# useradd els

    [root@node1 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@node1 elasticsearch-5.1.1]# groupadd elasticsearch

分配els用户到elasticsearch用户组

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

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

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

更改目录的用户和用户组

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

    [root@node1 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@node1 opt]# 

3、修改host和port

    [root@node1 elasticsearch-5.1.1]# su els

    [els@node1 elasticsearch-5.1.1]$ 

    [els@node1 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@node1 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@node1 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@node1 elasticsearch-5.1.1]# vi /etc/security/limits.conf
添加如下内容:
    * soft nofile 65536

    * hard nofile 131072

    * soft nproc 2048

    * hard nproc 4096

5、启动与浏览器访问

    [root@node1 elasticsearch-5.1.1]# su els

    [els@node1 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@node1 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@node1 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@node1 elasticsearch-5.1.1]$ kill -9 82131
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值