ELK学习实验020:ELK使用kafka缓存
首先安装一个kafka集群,但是zookeeper使用单节点,可以让kafka快速跑起来,后续再研究kafka和zokkeeper的集群
1 安装Kafka集群
下面是三个节点都要做
[root@node1 src]# wget http://mirror.rise.ph/apache/kafka/2.4.0/kafka_2.11-2.4.0.tgz
[root@node1 src]# tar -xf kafka_2.11-2.4.0.tgz
[root@node1 src]# mv kafka_2.11-2.4.0 /usr/local/kafka
[root@node1 src]# cd /usr/local/kafka
就使用node1作为zooker节点
[root@node1 kafka]# nohup ./bin/zookeeper-server-start.sh ./config/zookeeper.properties &
三个节点的kafka配置文件
[root@node1 kafka]# grep -Ev "^$|[;#]" config/server.properties
broker.id=0
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://192.168.132.131:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.132.131:2181
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
[root@node2 kafka]# grep -Ev "^$|[;#]" config/server.properties
broker.id=1
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://192.168.132.132:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.132.131:2181
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
[root@node3 kafka]# grep -Ev "^$|[;#]" config/server.properties
broker.id=2
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://192.168.132.133:9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=192.168.132.131:2181
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0
都启动kafka
[root@node1 kafka]# nohup ./bin/kafka-server-start.sh ./config/server.properties &
[root@node2 kafka]# nohup ./bin/kafka-server-start.sh ./config/server.properties &
[root@node3 kafka]# nohup ./bin/kafka-server-start.sh ./config/server.properties &
2 检查kafka状态
查看端口

查看其他端口

使用一下
[root@node1 kafka]# ./bin/zookeeper-shell.sh 192.168.132.131:2181
3 测试zookeeper
连接到zookeeper
ls /brokers
[ids, seqid, topics]
ls /brokers/ids
[0, 1, 2]
create /test "hello"
Created /test
get /test
hello
4 测试kafka使用
创建一个topic
[root@node1 kafka]# ./bin/kafka-topics.sh --create --zookeeper 192.168.132.131:2181 --replication factor 3 --partitions 3 --topic kafkatest
Created topic kafkatest.
[root@node1 kafka]# ./bin/kafka-topics.sh --list --zookeeper 192.168.132.131:2181
kafkatest
[root@node1 kafka]# ./bin/kafka-topics.sh --describe --zookeeper 192.168.132.131:2181 --topic kafkatest
Topic: kafkatest PartitionCount: 3 ReplicationFactor: 3 Configs:
Topic: kafkatest Partition: 0 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2
Topic: kafkatest Partition: 1 Leader: 1 Replicas: 1,2,0 Isr: 1,2,0
Topic: kafkatest Partition: 2 Leader: 2 Replicas: 2,0,1 Isr: 2,0,1
测试发送消息
[root@node1 kafka]# ./bin/kafka-topics.sh --create --zookeeper 192.168.132.131:2181 --replication-factor 3 --partitions 3 --topic messagetest
Created topic messagetest.
[root@node1 kafka]# ./bin/kafka-console-producer.sh --broker-list 192.168.132.131:9092,192.168.132.132:9092,192.168.132.133:9092 --topic messagetest
这里可以输入消息
>helloworld
>hello
node2和node3查看
[root@node2 kafka]# ./bin/kafka-console-consumer.sh --bootstrap-server 192.168.132.131:9092 --topic messagetest --from-beginning
helloworld
hello
[root@node3 kafka]# ./bin/kafka-console-consumer.sh --bootstrap-server 192.168.132.131:9092 --topic messagetest --from-beginning
helloworld
hello
5 配置filebeat
配置filebeat文件
filebeat.inputs:
#####################################################
## Nginx log
#####################################################
- type: log
enabled: true
paths:
- /usr/local/nginx/logs/access.log
json.key_under_root: true
json.overwrite_keys: true
tags: ["access"] - type: log
enabled: true
paths:
- /usr/local/nginx/logs/error.log
tags: ["error"]
output.kafka:
hosts: ["192.168.132.131:9092","192.168.132.132:9092","192.168.132.133:9092"]
topic: "elklog"
[root@node4 ~]# systemctl restart filebeat
6 配置logstash
修改logstah
input {
kafka {
bootstrap_server => "192.168.132.131:9092"
topics=>["elklog"]
group_id=>"logstash"
codec => "json"
}
}
filter{
mutate {
convert => ["upstream_time","float"]
convert => ["request_time","float"]
}
}
output{
stdout {}
if "access" in [tags]{
elasticsearch {
hosts => "192.168.132.131:9200"
manage_template => false
index => "nginx_access-%{+yyyy.MM.dd}"
}
}
if "error" in [tags]{
elasticsearch {
hosts => "192.168.132.131:9200"
manage_template => false
index => "nginx_error-%{+yyyy.MM.dd}"
}
}
}
~
启动logstah
[root@node4 ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/logsatsh.conf
[INFO ] 2020-01-21 10:15:57.734 [[main]-pipeline-manager] javapipeline - Pipeline started {"pipeline.id"=>"main"}
[INFO ] 2020-01-21 10:15:57.931 [Agent thread] agent - Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[INFO ] 2020-01-21 10:15:58.630 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600}
7 测试整个环境
访问生成数据
查看topic
[root@node1 kafka]# ./bin/kafka-topics.sh --list --zookeeper 192.168.132.131:2181
__consumer_offsets
elklog #已经有定义好的topic
kafkatest
messagetest
查看索引

查看kinban
{
"_index": "nginx_access-2020.01.21",
"_type": "_doc",
"_id": "F1O0yG8BOF7DoSFd9EoQ",
"_version": 1,
"_score": null,
"_source": {
"ecs": {
"version": "1.1.0"
},
"@timestamp": "2020-01-21T15:24:58.441Z",
"agent": {
"type": "filebeat",
"version": "7.4.2",
"hostname": "node4",
"id": "bb3818f9-66e2-4eb2-8f0c-3f35b543e025",
"ephemeral_id": "af9e9e07-03a6-4869-a5ff-9476ccf00dae"
},
"json": {
"Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
"upstreamtime": "-",
"upstreamhost": "-",
"responsetime": 0,
"xff": "-",
"domain": "192.168.132.134",
"@timestamp": "2020-01-21T10:24:57-05:00",
"http_host": "192.168.132.134",
"size": 555,
"status": "404",
"referer": "-",
"url": "/tcp",
"host": "192.168.132.134",
"clientip": "192.168.132.1"
},
"tags": [
"access"
],
"input": {
"type": "log"
},
"@version": "1",
"log": {
"offset": 24522559,
"file": {
"path": "/usr/local/nginx/logs/access.log"
}
},
"host": {
"name": "node4"
}
},
"fields": {
"json.@timestamp": [
"2020-01-21T15:24:57.000Z"
],
"@timestamp": [
"2020-01-21T15:24:58.441Z"
]
},
"sort": [
1579620298441
]
}
实验完成
ELK学习实验020:ELK使用kafka缓存的更多相关文章
- ELK学习实验014:Nginx日志JSON格式收集
1 Kibana的显示配置 https://demo.elastic.co/app/kibana#/dashboard/welcome_dashboard 环境先处理干净 安装nginx和httpd- ...
- ELK学习实验019:ELK使用redis缓存
1 安装一个redis服务 [root@node4 ~]# yum -y install redis 直接启动 [root@node4 ~]# systemctl restart redis [roo ...
- ELK学习实验013:ELK的一个完整的配置操作
前面做了关于ELK组件的各个实验,但是并没有真正的把各个组件结合起来做一个实验,现在使用一个脚本简单的生成日志,模拟生产不断产生日志的效果 一 流程说明 使用脚本产生日志,模拟用户的操作 日志的格式 ...
- ELK学习实验002:Elasticsearch介绍及单机安装
一 简介 ElasticSearch是一个基于Luncene的搜索服务器.它提供了一个分布式多用户能力全文搜索引擎,基于RESTful web接口,ElsticSearch使用Java开发的,并作为A ...
- ELK学习实验001:Elastic Stack简介
1 背景介绍 在我们日常生活中,我们经常需要回顾以前发生的一些事情:或者,当出现了一些问题的时候,可以从某些地方去查找原因,寻找发生问题的痕迹.无可避免需要用到文字的.图像的等等不同形式的记录.用计算 ...
- ELK学习实验012:Logstash的安装和使用
一 logstash安装 1.1下载包 [root@node1 ~]# cd /usr/local/src/ [root@node1 src]# wget https://artifacts.elas ...
- ELK学习实验010:Logstash简介
Logstash是具有实时流水线功能的开源数据收集引擎.Logstash可以动态统一来自不同来源的数据,并将数据规范化为您选择的目标.清除所有数据并使其民主化,以用于各种高级下游分析和可视化用例. 虽 ...
- ELK学习实验008:Kibana的介绍
一 简介 Kiana是一款开源的数据分析和可视化平台,它是 Elastic Stack成员之一,设计用于和 Elasticsearch协作.您可以使用 Kiana对 Elasticsearch索引中的 ...
- ELK学习实验007:Nginx的日志分析系统之Metribeat配置
一 Metricbeat 简介 1.1 系统级监控,更简洁将 Metricbeat 部署到您的所有 Linux.Windows 和 Mac 主机,并将它连接到 Elasticsearch 就大功告成了 ...
随机推荐
- 史上最全jdk新特性总结,涵盖jdk8到jdk15!
前言 在本文中,我将描述自第8版以来Java最重要且对开发人员友好的功能.为什么会有这样的主意?在Web上,您可以找到许多文章,其中包含每种Java版本的新功能列表.但是,由于缺少文章,因此无法简要概 ...
- oo第四单元与课程总结
Part1 本单元三次作业架构设计总结 1.组织结构 由于官方代码中已经给我们提供了许多零散的类元素,如UmlClass``UmlAssociation``UmlParameter等,因此我首先将某些 ...
- thinkphp添加excel更新数据表数据(优化篇)
由于主管说使用saveAll更新数据效率太低,要改用sql语句一次执行现在修改 /** * excel开启上传 * author: panzhide * @return array * Date: 2 ...
- 期末考试复习c#时总结的抽象类与接口的一些区别
抽象类: (1)抽象类中可以定义抽象方法,属性,变量 (2)抽象类的派生类必须实现所有的抽象方法.要求所有的派生非抽象类都要用override重写实现抽象方法. (3)抽象类可以存放抽象方法,属性,也 ...
- Java(56-64)【IDEA】
1.IDEA的使用 集成开发软件 eclipse IDEA 第一步:创建新的项目 第二步:空白的project 第三步:modules->java 写在src中 src->package- ...
- hbuilderX打包苹果证书的申请方法
现在uniapp越来越火,hbuilderX和apicloud这些工具使用html+js语言就可以开发强大的app,大大降低了app开发的技术门槛. hbuilderX或apicloud在打包ios应 ...
- git推送代码报错:fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream
情景再现 远程新建仓库,然后本地 git bash执行以下代码 git init git add . git commit -m 'xxx' git remote add origin https:/ ...
- AdaBoostClassifier参数
[AdaBoostClassifier] Adaboost-参数: base_estimator:基分类器,默认是决策树,在该分类器基础上进行boosting,理论上可以是任意一个分类器,但是如果是其 ...
- JDK8新特性(二) 流式编程Stream
流式编程是1.8中的新特性,基于常用的四种函数式接口以及Lambda表达式对集合类数据进行类似流水线一般的操作 流式编程分为大概三个步骤:获取流 → 操作流 → 返回操作结果 流的获取方式 这里先了解 ...
- 基于golang分布式爬虫系统的架构体系v1.0
基于golang分布式爬虫系统的架构体系v1.0 一.什么是分布式系统 分布式系统是一个硬件或软件组件分布在不同的网络计算机上,彼此之间仅仅通过消息传递进行通信和协调的系统.简单来说就是一群独立计算机 ...