资讯专栏INFORMATION COLUMN

window环境下搭建简单ELK日志收集

Baaaan / 2116人阅读

摘要:部署环境依赖第三方组件下载地址官网简单的流程示意图跟都支持集群部署,本文只简单描述如何多带带部署部署步骤三件套版本最好一致,小版本可以高,但是不可以低。

window环境下搭建简单ELK日志收集

前言
本文主要介绍如何在window环境下部署elk日志收集,网络上大部分是linux的,刚好这边服务需要用到window 环境,配置方式有点不同,大体是一样的。

部署环境
window server 2008 R2
依赖第三方组件
JDK8+
elasticsearch-5.6.14
logstash-5.6.14
kibana-5.6.14-windows-x86
redis-3.2

下载地址官网: https://www.elastic.co/

简单的流程示意图
redis跟elasticsearch 都支持集群部署,本文只简单描述如何多带带部署

部署步骤

elk三件套版本最好一致,elasticsearch小版本可以高,但是不可以低。
关于elasticsearch 的搭建和配置可以参考之前的一篇文章
DUBBO监控环境搭建

启动redis

redis默认只允许本地访问,如果要redis可以远程需要修改redis.windows.conf
bind 127.0.0.1 注释掉,在redis3.2版本以上增加了一个保护模式,所以还需要修改protected-mode no

#bind 127.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

配置logstash

logstash的作用是将redis中的日志信息收集并保存到elasticsearch中,redis只是作为缓存保存数据,logstash取完之后会删除redis中的数据信息。

1.指定启动JDK

指定JDK信息,如果有多个JDK需要指定,如果系统默认1.8可以跳过
在 logstash-5.6.14bin的setup.bat 中加入这句
set JAVA_HOME=C:Program FilesJavajdk1.8.0_181

set JAVA_HOME=C:Program FilesJavajdk1.8.0_181
rem ### 1: determine logstash home

rem  to do this, we strip from the path until we
rem find bin, and then strip bin (there is an assumption here that there is no
rem nested directory under bin also named bin)

2.配置输入输出源

在 logstash-5.6.14bin中新建 logback.config(名字任意) 配置文件,定义输入输出
input接受数据的输入,这边指定到redis;
output输出文件到指定的地方, elasticsearch;这边的index索引会在kibana那边配置用到
这个输入和输出的配置支持的类型比较多,有兴趣专研的可以参考官网配置
logstash输入配置
logstash输出配置
另外logstash还支持filter过滤器设置

input {

    redis {
        data_type => "list"
        key => "logstash"
        host => "127.0.0.1"
        port => 6379
        threads => 5
        codec => "json"
    }
}
filter {

}
output {

    elasticsearch {
        hosts => ["127.0.0.1:9200"]
        index => "logstash-%{type}-%{+YYYY.MM.dd}"
        document_type => "%{type}"
        workers => 1
        flush_size => 20
        idle_flush_time => 1
        template_overwrite => true
    }
    stdout{}
}

启动logstash命令 logstash.bat -f logback.config

配置kibana

找到kibana-5.6.14-windows-x86config 中kibana.yml,1.配置host 0.0.0.0,运行外网访问,默认只能本地访问 2.配置es的地址。

server.host: "0.0.0.0"

# Enables you to specify a path to mount Kibana at if you are running behind a proxy. This only affects
# the URLs generated by Kibana, your proxy is expected to remove the basePath value before forwarding requests
# to Kibana. This setting cannot end in a slash.
#server.basePath: ""

# The maximum payload size in bytes for incoming server requests.
#server.maxPayloadBytes: 1048576

# The Kibana server"s name.  This is used for display purposes.
#server.name: "your-hostname"

# The URL of the Elasticsearch instance to use for all your queries.
elasticsearch.url: "http://localhost:9200"

启动Kibana.bat

跟logback的结合

添加maven支持,引入logback-redis-appender.jar包

        
            com.cwbase
            logback-redis-appender
            1.1.3
            
                
                    redis.clients
                    jedis
                
            
        

配置logback.xml,这里的key需要跟上面配置的logback.config配置文件中配置的key相匹配

    
        demo
        dubbo
        127.0.0.1
        logstash
        dev
        true
        true
        0
    
    
        
    
        
        
        
        
    

启动服务工程,logback会将日志发送到redis,打开kibana的页面,第一次打开会提示创建索引规则,就是logback.config中es配置的索引logstash-*,创建好之后就可以看到日志已经被采集到elasticsearch中,我们在页面就可以查看日志信息。
kibana默认端口http://127.0.0.1:5601

结尾

最后说明下关于清除日志,ElasticSearch 5.x版本中删除过期ttl属性,所以我们需要定时清理es的索引,在服务中建一个bat定时执行,以下为删除30天前的全部索引。
http://{Elasticsearch IP}:9200/_cat/indices?v 查看es的所有索引

set DATA=`date -d "-30 days" +%Y.%m.%d`
curl -XDELETE http://127.0.0.1:9200/*-${DATA}

以上

参考文档
http://www.cnblogs.com/ASPNET...
https://blog.csdn.net/xuezhan...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/73115.html

相关文章

  • ELK结合logback搭建日志中心

    摘要:日志监控和分析在保障业务稳定运行时,起到了很重要的作用。本文搭建的的是一个分布式的日志收集和分析系统。对于队列上的这些未处理的日志,有不同的几台进行接收和分析。再由统一的进行日志界面的展示。如等配置文件可以配置,等日志报表可视化熟练 ELK简介ELKStack即Elasticsearch + Logstash + Kibana。日志监控和分析在保障业务稳定运行时,起到了很重要的作用。比...

    tracy 评论0 收藏0
  • 利用ELK搭建Docker容器化应用日志中心

    摘要:概述应用一旦容器化以后,需要考虑的就是如何采集位于容器中的应用程序的打印日志供运维分析。 showImg(https://segmentfault.com/img/remote/1460000014146680); 概述 应用一旦容器化以后,需要考虑的就是如何采集位于Docker容器中的应用程序的打印日志供运维分析。典型的比如 SpringBoot应用的日志 收集。本文即将阐述如何利...

    周国辉 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<