ELK部署实战

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ELK部署实战相关的知识,希望对你有一定的参考价值。

上海资邦集团战略发展部

目录

版本控制信息... 1

目录    i

1           ELK简介... 1

1.1                 ElasticSearch介绍... 1

1.2                 LogStash介绍... 1

1.3                 Kibana介绍... 1

2           开始部署ELK.. 1

2.1                 测试环境准备... 1

2.2                 安装前的准备工作... 1

2.2.1        系统yum源设置... 1

2.2.2        系统时间设置... 1

2.2.3        内核参数设置... 2

2.2.4        最大打开文件数设置... 2

2.2.5        JDK安装及设置... 2

2.2.6        ELK所需软件列... 2

2.3                 安装及配置ElasticSearch.. 3

2.3.1        下载ElasticSearch及安装... 3

2.3.2        配置ElasticSearch. 3

2.4                 ElasticSearch的使用... 6

2.5                 ElasticSearch插件的安装... 6

2.5.1        安装Marvel插件... 6

2.5.2        安装集群管理插件head. 9

2.6                 安装及配置Redis. 11

2.7                 安装及配置LogStash.. 13

2.7.1        下载及安装LogStash. 13

2.7.2        命令行简单使用LogStash. 13

2.7.3        LogStash配置示例... 13

2.8                 安装Kibana.. 22

3           遇到的问题... 25

3.1                 Logstashconcurrent过期提示... 25



1     ELK简介

1.1   ElasticSearch介绍

1.2   LogStash介绍

 

1.3   Kibana介绍

2     开始部署ELK

有了上面的介绍,接下来就可以实施部署ELK了。在部署之前,还需要做一些准备工作。

2.1   测试环境准备

接下来的测试将会在一台机器上做测试,操作系统为CentOS6.5 64位操作系统。

  1. 1.       操作系统:CentOS6.5 64

  2. 2.       关闭iptables

  3. 3.       关闭SELinux

主机名

IP地址

linux-node01.lavenliu.com

192.168.20.141

linux-node02.lavenliu.com

192.168.20.138

 

2.2   安装前的准备工作

操作系统的安装这里省略之。建议最小化安装操作系统。

2.2.1  系统yum源设置

替换系统原有的yum源,更改为阿里的yum源,这样下载软件包的速度会比较快,

# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

# yum makecache # 这一步可省略

2.2.2  系统时间设置

ntpdate ntp1.aliyun.com

date

echo "*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com &> /dev/null" >> /var/spool/cron/root

# crontab -l

2.2.3  内核参数设置

vm.max_map_count=262144

fs.file-max=65535

vm.swapness = 1

2.2.4  最大打开文件数设置

修改/etc/security/limits.conf配置文件,在文件的末尾增加如下两行:

* soft nofile 65535

* hard nofile 65535

然后重新退出当前系统登录,使用如下命令验证:

# ulimit -n

65535

2.2.5  JDK安装及设置

ElasticSearch需要JDK环境,JDK的版本建议是1.8.0_25以上的版本。编辑/etc/profile配置文件,在文件的末尾加入如下几行:

JAVA_HOME=/usr/local/jdk

JRE_HOME=${JAVA_HOME}/jre

CLASS_PATH=".:${JAVA_HOME}/lib:${JRE_HOME}/lib"

PATH=".:$JAVA_HOME/bin:$PATH"

export JAVA_HOME

export JRE_HOME

之后,重新读取/etc/profile配置文件,让配置生效,

# . /etc/profil

# java -version

java version "1.8.0_65"

Java(TM) SE Runtime Environment (build 1.8.0_65-b17)

Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

至此,Java环境已经配置完毕。

2.2.6  ELK所需软件列表

准备ELK所需的软件包,软件包如下表所示:

软件名

版本号

被安装主机

安装位置

JDK

1.8.0_65

linux-node01linux-node02

/usr/local/jdk

ElasticSearch

1.7.0

linux-node01linux-node02

/usr/local/elasticsearch

LogStash

1.5.3

linux-node01linux-node02

/usr/local/logstash

Kibana

4.1.1

linux-node01linux-node02

/usr/local/kibana

Redis

2.4.10

linux-node01linux-node02

yum默认安装位置

 

这里假设已经准备好以上软件,并放到了/home/lavenliu/tools目录下,

# ll

total 306020

-rw-r--r-- 1 root root  28501532 Jan 15 11:20 elasticsearch-1.7.0.tar.gz

-rw-r--r-- 1 root root 181260798 Nov 13 11:28 jdk-8u65-linux-x64.tar.gz

-rw-r--r-- 1 root root  11676499 Jan 15 11:20 kibana-4.1.1-linux-x64.tar.gz

-rw-r--r-- 1 root root  91914390 Jan 15 11:22 logstash-1.5.3.tar.gz

2.3   安装及配置ElasticSearch

2.3.1  下载ElasticSearch及安装

# wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.0.tar.gz

下载完毕,解压就可以运行了,

# tar -xf elasticsearch-1.7.0.tar.gz -C /usr/local/

# ln -s /usr/local/elasticsearch-1.7.0/ /usr/local/elasticsearch

 

下载ElasticSearch的启动脚本,以服务的形式管理ElasticSearch

# wget https://github.com/elasticsearch/elasticsearch-servicewrapper/archive/master.tar.gz

# tar -xf master.tar.gz

# mv elasticsearch-servicewrapper-master/service/ /usr/local/elasticsearch/bin/

# /usr/local/elasticsearch/bin/service/elasticsearch install

Detected RHEL or Fedora:

Installing the Elasticsearch daemon..

检查/etc/init.d/目录下是否已经存在elasticsearch启动脚本,

# ls /etc/init.d/elasticsearch

/etc/init.d/elasticsearch

# chkconfig --list |grep elastic

elasticsearch     0:off  1:off  2:on   3:on   4:on   5:on   6:off

2.3.2  配置ElasticSearch

接下来配置ElasticSearch,配置文件为/usr/local/elasticsearch/config/elasticsearch.yml,修改配置如下:

/usr/local/elasticsearch/config/elasticsearch.yml

# 如果在一个网络中存在多个集群环境,cluster.name名字要唯一

# 通过组播的方式

# 32

cluster.name: lavenliu

 

# 40

# 节点名名称:可以使用主机名

node.name: "linux-node1"

 

# 47

# 节点是否可以被选举为主节点

node.master: true

 

# 51

# 是否存储数据

node.data: true

 

# 107

# 默认分片为5个,分片后便于管理

index.number_of_shards: 5

 

# 111

# 分片的副本数量

index.number_of_replicas: 1

 

## 路径相关的配置

# 145

path.conf: /usr/local/elasticsearch/config

 

# 149

# ES索引文件存放位置

path.data: /usr/local/elasticsearch/data

 

# 159

# ES临时文件的存放路径

path.work: /usr/local/elasticsearch/work

 

# 163

# ES日志文件的存放路径

path.logs: /usr/local/elasticsearch/logs

 

# 167

# ES插件存放的目录

path.plugins: /usr/local/elasticsearch/plugins

 

## 内存相关的配置

# 184

bootstrap.mlockall: true

 

配置完毕,接下来就可以启动ES了,

# /etc/init.d/elasticsearch start

Starting Elasticsearch...

Waiting for Elasticsearch................

running: PID:19257

查看ES是否启动成功,

# netstat -antup | grep -E "9200|9300"

tcp        0      0 :::9200     :::*      LISTEN      18482/java

tcp        0      0 :::9300     :::*      LISTEN      18482/java

在命令行使用curl命令进行简单的命令行验证,

# curl http://192.168.20.141:9200

{

  "status" : 200,

  "name" : "linux-node01",

  "cluster_name" : "lavenliu",

  "version" : {

    "number" : "1.7.0",

    "build_hash" : "929b9739cae115e73c346cb5f9a6f24ba735a743",

    "build_timestamp" : "2015-07-16T14:31:07Z",

    "build_snapshot" : false,

    "lucene_version" : "4.10.4"

  },

  "tagline" : "You Know, for Search"

}

 

由于ESJava语言实现的,关于JVM相关参数的调优可以根据实际情况修改/usr/local/elasticsearch/bin/service/elasticsearch.conf配置文件。

2.4   ElasticSearch的使用

ElasticSearch服务已经启动,怎么与ElasticSearch进行交互呢?可以使用Java APIRESTful API

# curl -i -XGET ‘http://192.168.20.141:9200/_count?pretty‘ -d ‘

{

    "query": {

         match_all":{}

    }

}

HTTP/1.1 200 OK

Content-Type: application/json; charset=UTF-8

Content-Length: 95

 

{

  "count" : 0,

  "_shards" : {

    "total" : 0,

    "successful" : 0,

    "failed" : 0

  }

}

上面的命令行使用方式对于运维人员来说还可以。

2.5   ElasticSearch插件的安装

2.5.1  安装Marvel插件

linux-node01上进行安装Marvel插件,

# /usr/local/elasticsearch/bin/plugin -i elasticsearch/marvel/latest

-> Installing elasticsearch/marvel/latest...

Trying http://download.elasticsearch.org/elasticsearch/marvel/marvel-latest.zip...

Downloading ..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE

Installed elasticsearch/marvel/latest into /usr/local/elasticsearch/plugins/marvel

安装完毕marvel插件,可以无需重启ES服务,打开浏览器进行验证。在浏览器里输入:http://192.168.20.141:9200/_plugin/marvel,打开后界面如下:

技术分享

 

接下来点击右上角的"Dashboard->Sense",如下图所示:

技术分享


在左边窗口输入:

POST /myindex-demo/test

以上是关于ELK部署实战的主要内容,如果未能解决你的问题,请参考以下文章

ELK 安装部署文档-实战

ELK实战部署

ELK日志分析系统实战安装和部署

ELK——ELK日志分析系统部署搭建

Fluentd+Elasticsearch+kibana 日志收集部署实战

企业级ELK-架构与部署亲测可用!