zookeeper+kafka+logstash+elasticsearc+kibana

研究背景

1、之所以选用kafka是因为量起来的话单台logstash的抗压能力比较差

2、为了解决整个链路查询的问题,多个Feign传层的话,可以按照一个ID进行穿层,所以采用logback的MDC进行对唯一标识存储并且在Feign的调用链放在Header里,这里命名为TID

下载地址:

ZK+Kafka

https://mirrors.bfsu.edu.cn/apache/kafka/2.7.0/kafka_2.13-2.7.0.tgz

https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz

ELK

https://artifacts.elastic.co/downloads/kibana/kibana-7.12.0-windows-x86_64.zip

https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-windows-x86_64.zip

https://artifacts.elastic.co/downloads/logstash/logstash-7.12.0-windows-x86_64.zip

 

在拦截器里增加相对应的拦截代码

@Component
@Slf4j
public class ContextInterceptor implements HandlerInterceptor {RequestContext context = RequestContext.getCurrentContext();context.reset();log.debug("traceId:" + MDC.get("traceId"));String requestId = MDC.get("traceId");requestId = StringUtils.isEmpty(requestId) ? request.getHeader(RequestContext.REQUEST_ID) : requestId;requestId = StringUtils.isEmpty(requestId) ? request.getParameter(RequestContext.REQUEST_ID) : requestId;requestId = StringUtils.isEmpty(requestId) ? UUIDUtil.uuid() : requestId;MDC.put("TID", requestId);}

配置日志配置文件logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration><!-- springProfile用于指定当前激活的环境,如果spring.profile.active的值是哪个,就会激活对应节点下的配置 --><springProfile name="local"><!-- configuration to be enabled when the "staging" profile is active --><springProperty scope="context" name="module" source="spring.application.name"defaultValue="undefinded"/><!-- 该节点会读取Environment中配置的值,在这里我们读取application.yml中的值 --><springProperty scope="context" name="bootstrapServers" source="spring.kafka.bootstrap-servers"defaultValue="127.0.0.1:9092"/><appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><!-- encoders are assigned the typech.qos.logback.classic.encoder.PatternLayoutEncoder by default --><encoder><pattern>%boldYellow(${module})|%d|%highlight(%-5level)|%X{TID}|%cyan(%logger{15}) - %msg %n</pattern></encoder></appender><!-- kafka的appender配置 --><appender name="kafka" class="com.github.danielwegener.logback.kafka.KafkaAppender"><encoder><pattern>${module}|%d|%-5level|%X{TID}|%logger{15} - %msg</pattern></encoder><topic>test</topic><keyingStrategy class="com.github.danielwegener.logback.kafka.keying.NoKeyKeyingStrategy"/><deliveryStrategy class="com.github.danielwegener.logback.kafka.delivery.AsynchronousDeliveryStrategy"/><!-- Optional parameter to use a fixed partition --><!-- <partition>0</partition> --><!-- Optional parameter to include log timestamps into the kafka message --><!-- <appendTimestamp>true</appendTimestamp> --><!-- each <producerConfig> translates to regular kafka-client config (format: key=value) --><!-- producer configs are documented here: https://kafka.apache.org/documentation.html#newproducerconfigs --><!-- bootstrap.servers is the only mandatory producerConfig --><producerConfig>bootstrap.servers=${bootstrapServers}</producerConfig><!-- 如果kafka不可用则输出到控制台 --><appender-ref ref="STDOUT"/></appender><!-- 指定项目中的logger --><!--<logger name="org.springframework.test" level="INFO" ><appender-ref ref="kafka" /></logger>--><logger name="com.springcloudsite" level="INFO" ><appender-ref ref="kafka" /></logger><root level="info"><appender-ref ref="STDOUT" /></root></springProfile>
</configuration>

正则配置说明    

    pattern:为正则表达

    %boldYellow(${module}) : 黄色的模块名称

    %d :日期时间

   %highlight(%-5level):高亮的日志级别,如info error trace登

   %X{TID} : traceID 追踪使用的ID

   %cyan(%logger{15}) :简写类名路径

  %msg %n :具体日志信息

打印出来的效果如下:

 

配置zk+kafka

1. 安装JDK

1.1 安装文件:http://www.oracle.com/technetwork/java/javase/downloads/index.html 下载JDK
1.2 安装完成后需要添加以下的环境变量(右键点击“我的电脑” -> "高级系统设置" -> "环境变量" ):

  • JAVA_HOME: C:\Program Files\Java\jdk1.8.0_171 (jdk的安装路径)
  • Path: 在现有的值后面添加"; %JAVA_HOME%\bin"

1.3 打开cmd运行 "java -version" 查看当前系统Java的版本:

2. 安装ZOOKEEPER

Kafka的运行依赖于Zookeeper,所以在运行Kafka之前我们需要安装并运行Zookeeper

2.1 下载安装文件: http://zookeeper.apache.org/releases.html

2.2 解压文件 

2.3 打开zookeeper-3.4.13\conf,把zoo_sample.cfg重命名成zoo.cfg

2.4 从文本编辑器里打开zoo.cfg

2.5 把dataDir的值改成“./zookeeper-3.4.13/data”

2.6 添加如下系统变量:

  • ZOOKEEPER_HOME: C:\Users\localadmin\CODE\zookeeper-3.4.13 (zookeeper目录)
  • Path: 在现有的值后面添加 ";%ZOOKEEPER_HOME%\bin;"

2.7 运行Zookeeper: 打开cmd然后执行 zkserver

cmd 窗口不要关闭

3. 安装并运行KAFKA

3.1 下载安装文件: http://kafka.apache.org/downloads.html

3.2 解压文件

3.3 打开kafka_2.11-2.0.0\config

3.4 从文本编辑器里打开 server.properties

3.5 把 log.dirs的值改成 “./logs”

3.6 打开cmd

3.7 进入kafka文件目录: cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0(kafka目录)

3.8 输入并执行:  .\bin\windows\kafka-server-start.bat .\config\server.properties

cmd 窗口不要关闭

4. 创建TOPICS

4.1 打开cmd 并进入cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0\bin\windows

4.2 创建一个topic: kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

5. 打开一个PRODUCER:

cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0\bin\windows
kafka-console-producer.bat --broker-list localhost:9092 --topic test

6. 打开一个CONSUMER:

cd C:\Users\localadmin\CODE\kafka_2.11-2.0.0\bin\windows
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning

7. 测试:

配置ELK

kibana.yml

# Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "localhost"# Enables you to specify a path to mount Kibana at if you are running behind a proxy.
# Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
# from requests it receives, and to prevent a deprecation warning at startup.
# This setting cannot end in a slash.
#server.basePath: ""# Specifies whether Kibana should rewrite requests that are prefixed with
# `server.basePath` or require that they are rewritten by your reverse proxy.
# This setting was effectively always `false` before Kibana 6.3 and will
# default to `true` starting in Kibana 7.0.
#server.rewriteBasePath: false# Specifies the public URL at which Kibana is available for end users. If
# `server.basePath` is configured this URL should end with the same basePath.
#server.publicBaseUrl: ""# 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 URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["http://localhost:9200"]# Kibana uses an index in Elasticsearch to store saved searches, visualizations and
# dashboards. Kibana creates a new index if the index doesn't already exist.
#kibana.index: ".kibana"# The default application to load.
#kibana.defaultAppId: "home"# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
#elasticsearch.username: "kibana_system"
#elasticsearch.password: "pass"# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# These settings enable SSL for outgoing requests from the Kibana server to the browser.
#server.ssl.enabled: false
#server.ssl.certificate: /path/to/your/server.crt
#server.ssl.key: /path/to/your/server.key# Optional settings that provide the paths to the PEM-format SSL certificate and key files.
# These files are used to verify the identity of Kibana to Elasticsearch and are required when
# xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
#elasticsearch.ssl.certificate: /path/to/your/client.crt
#elasticsearch.ssl.key: /path/to/your/client.key# Optional setting that enables you to specify a path to the PEM file for the certificate
# authority for your Elasticsearch instance.
#elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]# To disregard the validity of SSL certificates, change this setting's value to 'none'.
#elasticsearch.ssl.verificationMode: full# Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
# the elasticsearch.requestTimeout setting.
#elasticsearch.pingTimeout: 1500# Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
# must be a positive integer.
elasticsearch.requestTimeout: 30000# List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
# headers, set this value to [] (an empty list).
#elasticsearch.requestHeadersWhitelist: [ authorization ]# Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
# by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
#elasticsearch.customHeaders: {}# Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
#elasticsearch.shardTimeout: 30000# Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
#elasticsearch.logQueries: false# Specifies the path where Kibana creates the process ID file.
#pid.file: /run/kibana/kibana.pid# Enables you to specify a file where Kibana stores log output.
#logging.dest: stdout# Set the value of this setting to true to suppress all logging output.
#logging.silent: false# Set the value of this setting to true to suppress all logging output other than error messages.
#logging.quiet: false# Set the value of this setting to true to log all events, including system usage information
# and all requests.
#logging.verbose: false# Set the interval in milliseconds to sample system and process performance
# metrics. Minimum is 100ms. Defaults to 5000.
#ops.interval: 5000# Specifies locale to be used for all localizable strings, dates and number formats.
# Supported languages are the following: English - en , by default , Chinese - zh-CN .
#i18n.locale: "en"

然后到对应bin目录下启动,直接点击 kibana.bat启动即可,或者在CMD命令启动

之后是启动效果

配置elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
cluster.name: "docker-cluster"
node.name: "node-1"
node.master: true
network.host: 0.0.0.0#xpack.license.self_generated.type: trial
#xpack.security.enabled: true
#xpack.monitoring.collection.enabled: true #
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

启动bin目录下的elasticsearch.bat

以下是启动效果

配置logstash.conf

# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.input {kafka {bootstrap_servers => "localhost:9092"topics => ["test"]group_id => "test"}
}filter { mutate {split => { "message" => "|" }}if [message][0] {mutate {                add_field =>   {"apiname" => "%{[message][0]}"}}}if [message][1] {mutate {                add_field =>   {"current_time" => "%{[message][1]}"}}} if [message][2] {mutate {                add_field =>   {"current_level" => "%{[message][2]}"}}}  	if [message][3] {mutate {                add_field =>   {"traceid" => "%{[message][3]}"}}}}output {elasticsearch {hosts => ["http://localhost:9200"]#index => "local-purchase-order | %{+YYYY-MM-dd}"index => "logstash-%{+YYYY-MM-dd}"#template_name => "logstash"#template_overwrite => true#index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"#user => "elastic"#password => "changeme"}stdout{codec => rubydebug}
}

配置logstash.yml

#/usr/share/logstash/config/logstash.yml
#jvm.options  log4j2.properties  logstash-sample.conf  logstash.yml  pipelines.yml  startup.options
http.host: "0.0.0.0"
# [ "http://elasticsearch:9200" ]
xpack.monitoring.elasticsearch.hosts: ${ELASTICSEARCH_URL}

启动使用命令

可以进到bin下

D:\app\elk\logstash\bin

输入命令:logstash -f D:\app\elk\logstash\config\logstash.conf

最后打开地址

http://localhost:9600/

http://localhost:9200/

http://localhost:5601/

分别验证结果

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/386447.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

还没吃透内存缓存LruCache实现原理的看这篇文章,跳槽薪资翻倍

目前情况&#xff1a;10届某民办大学本科生&#xff0c;实际接触Android年限6年多了&#xff0c;工作年限五年半&#xff08;注意&#xff0c;我说的是工作年限&#xff0c;不是工作经验&#xff09;&#xff0c;今年1月份裸辞后歇了大半年&#xff0c;经常一周也收不到几个off…

利用 Docker 搭建单机的 Cloudera CDH 以及使用实践

利用 Docker 搭建单机的 Cloudera CDH 以及使用实践 想用 CDH 大礼包&#xff0c;于是先在 Mac 上和 Centos7.4 上分别搞个了单机的测试用。其实操作的流和使用到的命令差不多就一并说了: 首先前往官方下载包&#xff1a; https://www.cloudera.com/downloads/quickstart_vm…

还没吃透内存缓存LruCache实现原理的看这篇文章,面试必会

前言 这篇文章主要是分享今年上半年的面试心得&#xff0c;现已就职于某大厂有三个月了&#xff0c;近期有很多公司均已启动秋招&#xff0c;也祝大家在 2020 的下半年面试顺利&#xff0c;获得理想的offer&#xff01; 之前找工作的那段时间感想颇多&#xff0c;总结一点面试…

fastjson反序列化漏洞原理及利用

重要漏洞利用poc及版本 我是从github上的参考中直接copy的exp&#xff0c;这个类就是要注入的类 import java.lang.Runtime; import java.lang.Process; public class Exploit { public Exploit() { try{ // 要执行的命令 String commands "calc.exe"; Process pc …

这个回答让我错失offer!offer拿到手软

开头 每到“金三银四”的季节&#xff0c;总人很多人去寻找名叫“面经”一样的东西&#xff0c;其实就是一个个具体的题目&#xff0c;然后临阵磨枪&#xff0c;去“背”答案&#xff0c;如果一直是这样的话&#xff0c;我相信你的能力不会有任何提高&#xff0c;即使工作三年…

Spark Windows

本文主要是讲解Spark在Windows环境是如何搭建的 一、JDK的安装 1、1 下载JDK 首先需要安装JDK&#xff0c;并且将环境变量配置好&#xff0c;如果已经安装了的老司机可以忽略。JDK&#xff08;全称是JavaTM Platform Standard Edition Development Kit&#xff09;的安装&…

这个回答让我错失offer!成功收获美团,小米安卓offer

前言 我们移动开发程序员应该首先明白一个要点&#xff0c;能够学习的东西可以区分为『知识』和『技能』。 知识&#xff0c;就是你知道就知道、不知道就不知道的东西&#xff0c;比如『计算机系统中一个字节是包含8个bit』&#xff0c;你知道了之后就算掌握了。 技能&#…

这么香的技术还不快点学起来,不吃透都对不起自己

大家应该看过很多分享面试成功的经验&#xff0c;但根据幸存者偏差的理论&#xff0c;也许多看看别人面试失败在哪里&#xff0c;对自己才更有帮助。 最近跟一个朋友聊天&#xff0c;他准备了几个月&#xff0c;刚刚参加完字节跳动面试&#xff0c;第二面结束后&#xff0c;嗯&…

Unity3D热更新之LuaFramework篇[06]--Lua中是怎么实现脚本生命周期的

前言 用c#开发的时候&#xff0c;新建的脚本都默认继承自Monobehaviour, 因此脚本才有了自己的生命周期函数&#xff0c;如Awake,Start, Update, OnDestroy等。 在相应的方法中实现游戏逻辑&#xff0c;引擎会适时调用。 而Lua在这里做为c#的一个外延语言&#xff0c;自然是不受…

这么香的技术还不快点学起来,含BATJM大厂

前言 北京字节跳动科技有限公司成立于2012年3月&#xff0c;是最早将人工智能应用于移动互联网场景的科技企业之一。其独立研发的“今日头条”客户端&#xff0c;开创了一种全新的新闻阅读模式。 我一直很向往这样有创新精神&#xff0c;并做出了巨大成果的大公司&#xff0c…

这些Android高级必会知识点你能答出来几个?含BATJM大厂

前言 首先介绍一下自己&#xff0c;计算机水本&#xff0c;考研与我无缘。之前在帝都某公司算法部实习&#xff0c;公司算大公司吧&#xff0c;然而个人爱好偏开发&#xff0c;大二的时候写个一个app&#xff0c;主要是用各种框架。 一、掌握架构师筑基必备技能 二、掌握Andr…

这些年Android面试的那些套路,社招面试心得

前言 说不焦虑其实是假的&#xff0c;因为无论是现在还是最近几年&#xff0c;很早就有人察觉Android开发的野蛮生长时代已经过去。过去的优势是市场需要&#xff0c;这个技术少有人有&#xff0c;所以在抢占市场的时候&#xff0c;基本上满足需要就已经可以了。但是现在&…

安卓开发入门到精通!免费Android高级工程师学习资源,系列篇

前言 2017年进大学开始接触Android&#xff0c;从刚开始接触就不断地听到Android市场饱和&#xff0c;工作难找等消息。虽然当时也非常迷茫&#xff0c;不过由于第一次深入接触编程语言&#xff0c;再加上自己的一点兴趣&#xff0c;就一直坚持下来了。 到现在要毕业了&#…

安卓开发基础面试题,9次Android面试经验总结,面试必备

前言 上回承诺过大家&#xff0c;一定会出 HTTP 的系列文章&#xff0c;今天终于整理完成了。作为一个 web 开发&#xff0c;HTTP 几乎是天天要打交道的东西&#xff0c;但我发现大部分人对 HTTP 只是浅尝辄止&#xff0c;对更多的细节及原理就了解不深了&#xff0c;在面试的…

基于TCP的在线聊天程序

在线聊天服务端 import tkinter import tkinter.font as tkFont import socket import threading import time import sys class ServerUI():local127.0.0.1port5505global serverSock;flagFalsedef __init__(self):self.roottkinter.Tk()self.root.title(在线聊天-服务端v1.0)…

Docker安装Confluence

Docker安装Confluence 参考链接: https://my.oschina.net/u/2289161/blog/1648587 https://hub.docker.com/r/cptactionhank/atlassian-confluence/dockerfile https://my.oschina.net/u/2289161/blog/1647061 https://my.oschina.net/u/2289161/blog/838218 https://hub.…

安卓开发基础面试题,Android面试必备的集合源码详解,附小技巧

去年无疑是 Flutter 技术如火如荼发展的一年。 每一个移动开发者都在为 Flutter 带来的“快速开发、富有表现力和灵活的 UI、原生性能”的特色和理念而痴狂&#xff0c;从超级 App 到独立应用&#xff0c;从纯 Flutter 到混合栈&#xff0c;开发者们在不同的场景下乐此不疲的探…

『算法』读书笔记 1.4算法分析 Part1

Chapter 1 本章结构 1.1Java语法 1.2数据抽象 1.3集合类抽象数据类型&#xff1a;背包 (Bags) 、队列 (Queues) 、栈 (Stacks) 1.4算法分析 1.5连通性问题&#xff0d;Case Study: Union - Find ADT 本节开篇使用了一个ThreeSum程序进行示例&#xff1a; ThreeSum所起到的作用…

安卓开发工程师面试题!春招我借这份PDF的复习思路,不吃透都对不起自己

写在前面 身边有不少去大厂面试的朋友&#xff0c;其中小金面试字节跳动的经历很有意义&#xff0c;在这里分享给大家。小金是末流211计算机专业大三本科生&#xff0c;前几天面试了字节跳动的广州Android开发实习生。下面是他的面试经历&#xff0c;还有一些他自己的经验。 …

安卓开发必须会的技能!浅谈Android消息机制原理,威力加强版

目录 想要成为一名优秀的Android开发&#xff0c;你需要一份完备的知识体系&#xff0c;在这里&#xff0c;让我们一起成长为自己所想的那样。 PagerAdapter 介绍ViwePager 缓存策略ViewPager 布局处理ViewPager 事件处理相关内容 Android 基础 1.Activity 1、 什么是 Activi…