ELK2.x日志搜集系统服务

栏目: 后端 · 发布时间: 5年前

内容简介:Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。Logstash 主要是用来日志的搜集、分析、过滤日志的工具,支持大量的数据获取方式。一般工作方式为c/s架构,client端安装在需要收集日志的主机上,server端负责将收到的各节点日志进行过滤、修改等操作在一并发往elasticsearch上去。Kibana 也是一个开源和免费的工具,Kibana可以为

一、ELK工作原理

Elasticsearch

Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。

Logstash

Logstash 主要是用来日志的搜集、分析、过滤日志的工具,支持大量的数据获取方式。一般工作方式为c/s架构,client端安装在需要收集日志的主机上,server端负责将收到的各节点日志进行过滤、修改等操作在一并发往elasticsearch上去。

Kibana

Kibana 也是一个开源和免费的工具,Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助汇总、分析和搜索重要数据日志。

ELK官方网站

https://www.elastic.co/cn/

工作基本流程图

ELK2.x日志搜集系统服务

所需环境

主机名 IP地址 所需软件
node-1 192.168.144.114 jdk8、elasticsearch2.4.6、logstash2.1.3、kibana-4.3.1-linux-x64.tar.gz
node-2 192.168.144.117 jdk8、elasticsearch2.4.6

二、Elasticsearch及Elasticsearch群集部署

节点1安装elasticsearch并打开群集功能

  • 获取官方验证密匙

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

  • 配置yum安装源
vim 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
enable=1
  • 安装elasticsearch
yum install elasticsearch -y
yum install java -y (1.8版本)
  • 查看 java 版本
java -version
  • 修改配置文件
vim /etc/elasticsearch/elasticsearch.yml
17行 集群名称
cluster.name: yun

23行 节点名称
node.name: linux-node1

33行 工作目录
path.data: /data/es-data              //这两个目录建议更改,若采用默认格式,版本更新可能会被默认删除
path.logs: /var/log/elasticsearch/    //创建这两个目录后,注意目录属主属组权限

43行 防止交换swap分区
bootstrap.memory_lock: true

54行 监听网络
network.host: 0.0.0.0

58行 端口
http.port: 9200

69行 单播列表自动发现机制
discovery.zen.ping.unicast.hosts: ["127.0.0.1", "192.168.144.117"]    //一个本地IP,一个节点2IP
mkdir -p /data/es-data chown -R elasticsearch:elasticsearch /data/es-data/ systemctl start elasticsearch.service netstat -ntap | grep 9200

注意事项

在打开防止交换分区功能后,在es启动日志中可观察到如下信息:

vim /var/log/elasticsearch/abner.log
...
[2018-08-19 22:01:12,224][WARN ][bootstrap                ] 
These can be adjusted by modifying /etc/security/limits.conf, for example: 
    # allow user 'elasticsearch' mlockall
    elasticsearch soft memlock unlimited
    elasticsearch hard memlock unlimited
...
  • 针对如上情况,我们需要对系统内存进行相应优化
vim /etc/security/limits.conf
//末尾插入
# allow user 'elasticsearch' mlockall
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited

* soft nofile 65535        
* hard nofile 65535    //需重启生效

安装ES-head插件

/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
  • 查询已经安装的插件
/usr/share/elasticsearch/bin/plugin list
  • 插件默认安装位置
/usr/share/elasticsearch/plugins/head

页面测试

  • 未安装插件前

ELK2.x日志搜集系统服务

  • 安装head插件后

ELK2.x日志搜集系统服务

部署节点2群集节点

  • es配置方式如节点一
  • 编辑配置如下:
  • 查看配置文件
    cat /etc/elasticsearch/elasticsearch.yml | grep -v "^#" | grep -v "^$"
    
cluster.name: yun   //注意:统一群集下,使用的群集名称需相同
node.name: node-2
path.data: /data/es-data
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.144.117", "192.168.144.114"]

mkdir -p /data/es-data 创建工作目录

chown -R elasticsearch:elasticsearch /data/es-data/

systemctl start elasticsearch.service

netstat -ntap | grep 9200

ES群集测试

  • 访问节点一的head插件页面

ELK2.x日志搜集系统服务

ELK2.x日志搜集系统服务 ELK2.x日志搜集系统服务

监控组件插件kopf安装

  • 默认会在github.com 中查找 kopf
/usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
  • 监控页面测试

http://192.168.144.114:9200/_plugin/kopf/#!/cluster

ELK2.x日志搜集系统服务

三、部署logstash收集日志

为了试验方便起见,本次logstash服务部署在es节点1上。并且将收集到的日志传递给es进行处理。

logstash部署

  • 获取官方验证密匙

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

  • 创建软件yum源
vim /etc/yum.repos.d/logstash.repo
[logstash-2.1]
name=Logstash repository for 2.1.x packages
baseurl=http://packages.elastic.co/logstash/2.1/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enable=1
  • 安装logstash
yum install logstash -y
  • 将logstash命令能让系统识别
ln -s /opt/logstash/bin/logstash /usr/bin/

创建logstash启动配置文件

  • 创建logstash配置文件读取本机httpd服务的日志文件
vim file.conf
input {

      file {
          path => "/var/log/httpd/access_log"
          type => "accesslog"
          start_position => "beginning"
      }
      file {
          path => "/var/log/httpd/error_log"
          type => "errorlog"
          start_position => "beginning"
      }
}

output {

     if [type] == "accesslog" {
         elasticsearch {
             hosts => ["192.168.144.114:9200"]      //将日志收集数据传递给es
             index => "access-%{+YYYY.MM.dd}"
         }
     }

     if [type] == "errorlog" {
         elasticsearch {
             hosts => ["192.168.144.114:9200"]
             index => "error-%{+YYYY.MM.dd}"
         }
     }
}
  • 观察head插件,可观察到日志收集情况

ELK2.x日志搜集系统服务 ELK2.x日志搜集系统服务

四、部署kibana展示

  • 获取kibana软件包

wget https://download.elastic.co/kibana/kibana/kibana-4.3.1-linux-x64.tar.gz

tar zxvf kibana-4.3.1-linux-x64.tar.gz -C /opt/

mv kibana-4.3.1-linux-x64/ /usr/local/

mv kibana-4.3.1-linux-x64/ kibana

  • 编辑kibana配置文件
vim /usr/local/kibana/config/kibana.yml
//2行 
server.port: 5601

//5行
server.host: "0.0.0.0"

//12行 ES地址
elasticsearch.url: "http://192.168.175.132:9200"

//20行
kibana.index: ".kibana"

yum install screen -y

screen 换屏操作

  • 启动监听kibana
/usr/local/kibana/bin/kibana

ELK2.x日志搜集系统服务

  • 进行丢入后台

ctrl+a+d

kibana页面展示测试

http://192.168.144.114:5601/

ELK2.x日志搜集系统服务


以上所述就是小编给大家介绍的《ELK2.x日志搜集系统服务》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

High Performance Python

High Performance Python

Micha Gorelick、Ian Ozsvald / O'Reilly Media / 2014-9-10 / USD 39.99

If you're an experienced Python programmer, High Performance Python will guide you through the various routes of code optimization. You'll learn how to use smarter algorithms and leverage peripheral t......一起来看看 《High Performance Python》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试