ELK第一篇:Elasticsearch安装

来源:互联网 发布:北京seo田野博客 编辑:程序博客网 时间:2024/04/29 16:08

简介

准备

JDK和环境变量必装
Elasticsearch下载安装包:https://www.elastic.co/downloads/elasticsearch

可以在MAC,WINDOWS和linunx环境安装

本文环境:centos7.0,jdk1.8.03,Elasticsearch6.0

安装

下载并解压

1.Download and unzip Elasticsearch

[root@localhost elasticsearch-6.0.0]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.tar.gztar -xvf elasticsearch-6.0.0.tar.gz

Note

Elasticsearch can also be installed from our package repositories using apt or yum, or installed on Windows using an MSI installer package. See Repositories in the Guide.
也可以使用yum安装,或者在windows下使用msi安装

centos下创建用户并配置文件权限

创建一个工作组为 elsearch用户名为els的用户,默认密码为123456
并把该文件下所有权赋予该账号

groupadd elsearch[root@localhost elasticsearch-6.0.0]# useradd els -g elsearch -p 123456[root@localhost elasticsearch-6.0.0]# chown -R els:elasticsearch  elasticsearch-6.0.0

修改系统配置

以下修改都使用root权限

limits.conf

vi /etc/security/limits.conf

添加如下内容到文件末尾

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

*-nproc.conf

这里你需查看系统生成的文件名是什么(每个系统生成的数字各不一样),可以看到我这里是20-nproc.conf,然后编辑它

ls /etc/security/limits.d/20-nproc.confvi /etc/security/limits.d/20-nproc.conf

添加如下内容:

soft nproc 2048

如果你的文件里面本身已经有了这个配置,如果比2048小则修改为2048否则不变

sysctl.conf

vi /etc/sysctl.conf 

添加下面配置:

vm.max_map_count=655360

并执行命令:

sysctl -p

elasticsearch.yml

修改elasticsearch绑定的IP地址

 vi config/elasticsearch.yml

找到Network相关的配置天添加如下内容,IP修改为你自己的IP

 network.host: 192.168.0.91

注:如果你是配置的计算机访127.0.0.1则不需要修改,否则如果是其他计算机浏览器打开则无法访问的到,因为它默认绑定的ip是127.0.0.1

后台运行

3 Run bin/elasticsearch (or bin\elasticsearch.bat on Windows)
运行elasticsearch
切换账号到els

su elsbin/elasticsearch

Run curl http://localhost:9200/ or Invoke-RestMethod http://localhost:9200 with PowerShell
浏览器打开如上地址,如果你使用内网或者公网ip访问则需要修改它的绑定地址,因为它默认绑定的ip是127.0.0.1

当我们ctrl+c它就停止运行了
使用如下命令

./elasticsearch -d

若是es的后台运行,则用kill -9 进程号来停止。

$ jps24105 Jps24060 Elasticsearchkill -9 24060

说下遇到的坑

解决linux下root运行Elasticsearch异常

在CentOS 7.0 上运行Elasticsearch 6.0,异常如下:

[2017-11-27T11:33:58,909][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] []                                                                                                              uncaught exception in thread [main]org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can no                                                                                                             t run elasticsearch as root        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:134                                                                                                             ) ~[elasticsearch-6.0.0.jar:6.0.0]

异常描述为不能以root权限运行Elasticsearch.

解决办法是创建一个工作组为 elsearch用户名为els的用户,默认密码为123456
并把该文件下所有权赋予该账号

groupadd elsearch[root@localhost elasticsearch-6.0.0]# useradd els -g elsearch -p 123456[root@localhost elasticsearch-6.0.0]# chown -R els:elasticsearch  elasticsearch-6.0.0

切换账号到els

su els

运行bin/elasticsearch

ERROR: bootstrap checks failed

ERROR: [2] bootstrap checks failed[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536][2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

这个问题是Elasticsearch需要创建大量的线程数和文件数以及mmap的内存容量受到了操作系统配置的限制的最大数量,因此需要手动修改操作系统的相关配置,具体配置参考我上面【修改系统配置】

官方给出的文档说明参考:
https://www.elastic.co/guide/en/elasticsearch/reference/master/bootstrap-checks.html
这里写图片描述