ELKStack简介
        对于日志来说,最常见的需求就是收集、存储、查询、展示,开源社区正好有相对应的开源项目:logstash(收集)、elasticsearch(存储+搜索)、kibana(展示),我们将这三个组合起来的技术称之为ELKStack,所以说ELKStack指的是Elasticsearch、Logstash、Kibana技术栈的结合,一个通用的架构如下图所示:

YUM安装ElasticSearch

1.下载并安装GPG key

[root@hadoop-node1 ~]# rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

2.添加yum仓库

[root@hadoop-node1 ~]# vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

3.安装elasticsearch

[root@hadoop-node1 ~]# yum install -y elasticsearch

LogStash部署与配置
    和Elasticsearch一样,在开始部署LogStash之前也需要你的环境中正确的安装的JDK。可以下载安装Oracle的JDK或者使用 yum安装openjdk。

安装JDK

[root@linux-node1 ~]# yum install -y java
[root@linux-node1 ~]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

YUM部署LogStash

1.下载并安装GPG key

[root@linux-node2 ~]# rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

2.添加yum仓库

[root@linux-node2 ~]# vim /etc/yum.repos.d/logstash.repo
[logstash-2.3]
name=Logstash repository for 2.3.x packages
baseurl=https://packages.elastic.co/logstash/2.3/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

3.安装logstash

[root@linux-node2 ~]# yum install -y logstash

Kibana简介
        Kibana 是为 Elasticsearch 设计的开源分析和可视化平台。你可以使用 Kibana 来搜索,查看存储在 Elasticsearch 索引中的数据并与之交互。你可以很容易实现高级的数据分析和可视化,以图表的形式展现出来。

Yum安装Kibana
1.下载并安装GPG key

[root@linux-node2 ~]# rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

2.添加yum仓库

[root@test ~]# vim /etc/yum.repos.d/kibana.repo
[kibana-4.5]
name=Kibana repository for 4.5.x packages
baseurl=http://packages.elastic.co/kibana/4.5/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

3.安装kibana

[root@test ~]# yum install -y kibana

修改配置文件
cd /etc/elasticsearch
vim vim elasticsearch.yml
以下是修改的内容

启动(启动前修改权限否则启动不了chown -R elasticsearch.elasticsearch /data/es-data/)

systemctl start elasticsearch

PS:如果启动报错无法分配内存把bootstrap.memory_lock: 参数true改成false

访问测试

搜索

安装插件marvel

/usr/share/elasticsearch/bin/plugin install marvel-agent安装好在这个目录/usr/share/elasticsearch/plugins/

安装head插件
/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head 这两插件是用来做集群管理
访问方式
http://106.75.156.245:9200/_plugin/head/ 安装插件bigdesk
/usr/share/elasticsearch/bin/plugin install lukas-vlcek/bigdesk
PS:安装不上,版本不支持
安装插件kopf
/usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
访问
http://106.75.156.245:9200/_plugin/kopf PS:如果安装插件失败启动elasticsearch可能报错
解决办法 去
/usr/share/elasticsearch 目录删掉对应的文件夹即可


打开head插入数据

ELKStack集群

另外一台服务器也安装相同

拷贝配置文件

scp /etc/elasticsearch/elasticsearch.yml root@10.13.141.148:/etc/elasticsearch/

修改一下

cluster.name要保持一致为myes

node-name改为linux-node2

network.host改为10.13.141.148

创建目录

mkdir /data/es-data

授权

chown -R elasticsearch.elasticsearch /data/es-data/

查看

启动

etc/init.d/elasticsearch start

elasticsearch使用组播的方式进行查找 根据cluster名称发送组播,选举出一个主节点(master用来管理集群的状态)

打开head查看是否组成了集群(如未组成改成单波模式)

PS:粗一点的是主分片前面是星号,细一点是从分片,前面是圆圈,任意一个节点故障都不会影响

监控集群健康状态

logstash实战

日志的收集

默认安装位置/opt/logstash

/opt/logstash/bin/logstash -e 'input { stdin{} } output { stdout{} }'

启动一会

标准输入什么输出什么

以json方式输出

/opt/logstash/bin/logstash -e 'input { stdin{} } output { stdout{ codec => rubydebug } }'

PS:这里等号是使用=>

输出到es

/opt/logstash/bin/logstash -e 'input { stdin{} } output { elasticsearch { hosts => ["10.13.85.9:9200"] index => "logstash-%{+YYYY.MM.dd}" } }'

输入hehe 不显示

页面显示

既在屏幕上面输出又输入到es

/opt/logstash/bin/logstash -e 'input { stdin{} } output { stdout { codec => rubydebug } elasticsearch { hosts => ["10.13.85.9:9200"] index => "logstash-%{+YYYY.MM.dd}" } }'

yum安装的配置文件位置/etc/logstash/conf.d

因为脚本 /etc/init.d/logstash 指定了

写一个配置文件

vim demo.conf

input{
stdin{} } filter{
} output{
elasticsearch{
hosts => ["10.13.85.9:9200"]
index => "logstash-%{+YYYY.MM.dd}"
}
stdout{
codec => rubydebug
}
}

加配置文件启动

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/demo.conf

PS:配置文件必须包含input和output filter是可选的,每个里面放置各自的插件,每个插件也有大括号包含。

写一个收集文件日志的配置文件

vim file.conf

input{
file{
path => ["/var/log/messages","/var/log/secure"]
type => "system-log"
start_position => "beginning"
} } filter{ } output{
elasticsearch{
hosts => ["10.13.85.9:9200"]
index => "system-log-%{+YYYY.MM}"
} }

启动

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/file.conf

查看数据

排错:启动logstash时候出现Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME

解决办法

export JAVACMD=`which java`

kibana简单使用

配置文件目录

/opt/kibana/config

启动

/etc/init.d/kibana start

访问

http://106.75.156.245:5601

根据索引导入日志数据

logstash-input-if判断

加一个文件收集日志

如果没有定下输出将和之前的system-log日志输出到一起,如果在output写一个对应的输出则会同时输出到两个设置里面

需要通过if判断来区分

修改后的配置文件file.conf

input{
file{
path => ["/var/log/messages","/var/log/secure"]
type => "system-log"
start_position => "beginning"
}
file{
path => "/var/log/elasticsearch/myer.log"
type => "es-log"
start_position => "beginning"
} } filter{ } output{
if [type] == "system-log" {
elasticsearch{
hosts => ["10.13.85.9:9200"]
index => "system-log-%{+YYYY.MM}"
}
}
if [type] == "es-log"{
elasticsearch{
hosts => ["10.13.85.9:9200"]
index => "es-log-%{+YYYY.MM}"
}
}
}

  

multiline插件

多行插件

先标准输出验证一下

vim /etc/logstash/conf.d/codec.conf

input{
stdin {
codec => multiline{
pattern => "^\["
negate => true
what => "previous"
}
}
} filter{
} output{
stdout{
codec => rubydebug
}
}

 运行/opt/logstash/bin/logstash -f /etc/logstash/conf.d/codec.conf

 

只要遇到中括号就把上面的合并

修改file.conf

input{
file{
path => ["/var/log/messages","/var/log/secure"]
type => "system-log"
start_position => "beginning"
}
file{
path => "/var/log/elasticsearch/myes.log"
type => "es-log"
start_position => "beginning"
codec => multiline{
pattern => "^\["
negate => true
what => "previous"
}
} } filter{ } output{
if [type] == "system-log" {
elasticsearch{
hosts => ["10.13.85.9:9200"]
index => "system-log-%{+YYYY.MM}"
}
}
if [type] == "es-log" {
elasticsearch{
hosts => ["10.13.85.9:9200"]
index => "es-log-%{+YYYY.MM}"
}
}
}

 删除掉原来的es-log

重新启动生成索引(需要重启elasticserach)

codes-json

把nginx访问日志改成json的输出

PS:还可使用文件直接收取 Redis  Python脚本读取Redis,写成Json,写入ES

重启nginx

写收集日志配置文件

先写屏幕输出的

input{
file{
path => "/usr/local/nginx/log/access_log_json.log"
codec => "json"
}
} filter{ } output{
stdout{
codec =>rubydebug
}
}

  启动 输出为

修改为输出到es

input{
file{
path => "/usr/local/nginx/log/access_log_json.log"
codec => "json"
}
} filter{ } output{
elasticsearch{
hosts => ["10.13.85.9:9200"]
index => "nginx-log-%{+YYYY.MM.dd}"
}
}

PS:如果之前做过屏幕输出测试需要删除sincedb否则可能收取不到,如果找不到哪里的问题可以在配置文件设置stdout进行调试,可以使用-t参数测试配置文件

加入kibana

ELKStack的更多相关文章

  1. ELKstack搭建

    开源实时日志分析ELK平台部署 官网地址:https://www.elastic.co/products 介绍: Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现 ...

  2. ELKStack的基础入门和中文指南

    一.ELKStack的中文指南 redhat系列配置repo源 rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch vi / ...

  3. ELKStack生产案例

    需求分析: 访问日志:apache访问日志,nginx访问日志,tomcat file 错误日志: error log,java日志 直接收 java异常需要处理 系统日志:/var/log/*   ...

  4. ELKStack入门篇(一)之ELK部署和使用

    一.ELKStack简介 1.ELK介绍 中文指南:https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details ELK Stack包 ...

  5. ELK-Stack 最后一次全篇文档

    简介: ELK-Stack 日志收集系统.最后一次全篇记录的笔记,之后关于 ELK 的笔记都将是片段型.针对性的.  环境介绍: ELK-Stack:192.168.1.25 ( Redis.LogS ...

  6. 二、ELKStack集群架构设计

    一.ELKStack介绍与入门实践 二.Elasticsearch 集群架构图 服务器配置:Centos6.6 x86_64 CPU:1核心 MEM:2G (做实验,配置比较低一些) 注:这里配置el ...

  7. 一、ELKStack介绍与入门实践

    第1章 ELKStack 对于日志来说,最常见的需求就是收集.存储.查询.展示,开源社区正好有相对应的开源项目:logstash(收集).elasticsearch(存储+搜索).kibana(展示) ...

  8. ELKstack 中文指南

    https://www.elastic.co/downloads ELKstack 中文指南 .net Elasticsearch 学习入门笔记   一. es安装相关1.elasticsearch安 ...

  9. 第一章·ELKstack介绍及Elasticsearch部署

    一.ELKstack课程大纲  二.ELKstack简介 什么是ELK? 通俗来讲,ELK是由Elasticsearch.Logstash.Kibana 三个开源软件的组成的一个组合体,这三个软件当 ...

随机推荐

  1. VSCode------搭建.net core 2.0,并配置到IIS服务器

    前奏 安装VSCode最新版: https://code.visualstudio.com/ 安装window server hosting,发布和部署到IIS使用: https://www.micr ...

  2. phonegap入门–2 Android phonegap工程建立

    一.环境要求: 需要安装Android ADT 二.支持Android相关设备列表: a)Android 2.1 (Deprecated May 2013) b)Android 2.2 c)Andro ...

  3. mongodb 搭建主从服务器

    mongodb 主从配置比较简单,只需要在启动的时候添加参数(-master.-slave -source IP:PORT). Ubuntu 16.04 系统环境 监听端口分别为:27010.2701 ...

  4. python爬虫系列:做一个简单的动态代理池

    自动 1.设置动态的user agent import urllib.request as ure import urllib.parse as upa import random from bs4 ...

  5. 利用shell脚本自动获取awr报表

    观察Oracle数据库性能,oracle自带的awr功能为我们提供了一个近乎完美的解决方案,通过awr特性我们可以随时从数据库提取awr报告.通过报告可以了解一个系统的整个运行情况,生成的报告包括多个 ...

  6. BootStrap Table显示行号,并且分页后依然递增

    bootStrap table 此处使用的是V1.9.0.在网上百度的方法是: { title: '序号', field: '', formatter: function (value, row, i ...

  7. Cookie利用神器:CookieHacker

    转自evilcos的博客 看到那么多苦逼的跨站师在问Cookie利用工具,不忍心,还是把自己写的Chrome扩展开源出来吧,功能极简,仿造<我的渗透利器>里提到的Original Cook ...

  8. samba 服务器

    1.apt-get install smaba 2.安装完成后apt-get install smbclient 然后就是配置那个.conf文件,这个到网上搜下ubuntu下配置smaba服务器就可以 ...

  9. 扩展方法以及LinQ的学习

    我们今天学习的内容其实还是蛮多的,学习了自动属性,扩展方法,复习初始化器,以及LinQ的一些方法,其实感觉有些还是很熟悉的,在前面的学习过程中有时间感觉学习的知识知道了怎么使用,但是还没有在项目中使用 ...

  10. [原]如何为SqlServer2008数据库分配用户

    前言: 当一个项目完成后,为了数据安全,总会对该项目的数据库分配一个用户,应该说总会创建一个用户来管理这个数据库,并且这个用户只能管理这个数据库.搞了好多次,每次都忘记怎么设置,所以写一篇博文记录一下 ...