前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数据监控ElasticStack全家桶之容器化部署

数据监控ElasticStack全家桶之容器化部署

原创
作者头像
蒋老湿
修改2020-12-24 18:16:05
9210
修改2020-12-24 18:16:05
举报
文章被收录于专栏:技术栈

技术选型

Filebeat 7.3.0

kafka 1.1.0

logstash 7.3.0

elasticserarch 7.1.1

kibana 7.1.1

zookeeper

下载镜像

代码语言:txt
复制
docker pull wurstmeister/kafka:1.1.0
docker pull wurstmeister/zookeeper
docker pull kibana:7.1.1
docker pull logstash:7.3.0
docker pull grafana/grafana:6.3.2
docker pull elasticsearch:7.1.1
docker pull mobz/elasticsearch-head:5-alpine

创建容器

代码语言:txt
复制
# elasticsearch-head
docker run -d --name elasticsearch-head --network host mobz/elasticsearch-head:5-alpine
# elasticsearch
docker run -d --name elasticsearch --network host -e "discovery.type=single-node" elasticsearch:7.1.1
# kibana
docker run -d --name kibana --network host -p 5601:5601 kibana:7.1.1
# logstash
docker run -d --name logstash --network host -d logstash:7.3.0
# mysql
docker run --name mysql -e MYSQL_ROOT_PASSWORD=root --network host -d mysql:latest
# grafana
docker run -d --name grafana --network host grafana/grafana:6.3.2

# 查看docker 容器日志
docker logs -f [containerID]

## 应用访问
http://192.168.104.102:9100/   elasticsearch-head
http://192.168.104.102:9200/   elasticsearch      
http://192.168.104.102:3000/   grafana      admin/admin
http://192.168.104.102:3306/   mysql         root/root 

修改elasticsearchelasticsearch.yml,追加

代码语言:txt
复制
http.cors.enabled: true
http.cors.allow-origin: "*"

参考使用Docker快速搭建Kafka开发环境

filebeat的下载与安装

代码语言:txt
复制
# 下载filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.0-linux-x86_64.tar.gz
# 解压filebeat.tar.gz
tar -zxvf filebeat-7.3.0-linux-x86_64.tar.gz

## filebeat的多种启动方式
./filebeat test config -c my-filebeat.yml
./filebeat -e -c my-filebeat.yml -d "publish"
# 后台启动filebeat输出日志保存
nohup ./filebeat -e -c my-filebeat.yml > /tmp/filebeat.log 2>&1 &
# 不挂断后台运行 将所有标准输出及标准错误输出到/dev/null空设备,即没有任何输出
nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &  
# filebeat启动后,查看相关输出信息
./filebeat -e -c filebeat.yml -d "publish"

# 参数说明
-e:输出到标准输出,默认输出到syslog和logs下
-c:指定配置文件
-d:输出debug信息

filebeat的配置文件

代码语言:txt
复制
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /opt/test.log
  fields:
    serviceName: jp-filebeat
  fields_under_root: true
# 输出内容到kafka
output.kafka:
  enabled: true
  hosts: ["kafka1:9092"]
  topic: 'stream-in'
  required_acks: 1

## 注意
# kafka1为hostname, 可修改 etc/hosts文件,添加 kafka_cluster的ip -> kafka1
代码语言:txt
复制
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /opt/*.log
  fields:
    serviceName:jp-filebeat
  fields_under_root: true
# 输出内容到logstash
output.logstash:
  hosts: ["192.168.104.102:5045"]

查看filebeat与kafka的TCP连接

往测试的log文件里写内容echo '321312' >> test.log

logstash

  • logstash的linux安装
  • logstash的Docker安装

容器默认启动配置文件为

/usr/share/logstash/pipeline/logstash.conf

测试一个logstash(标准的输入输出)

bin/logatsh -e 'input{ stdin {}} output { stdout {}}

提示:

Logstash could not be started because there is already another instance using the configured data directory. If you wish to run multiple instances, you must change the "path.data" settingundefined在原命令bin/logstash -f config/logstash-sample.conf的末尾加上--path.data=/usr/share/logstash/jpdata

代码语言:txt
复制
# 启动多个logstash实例的命令
bin/logstash -f config/logstash-sample.conf --config.reload.automatic --path.data=/usr/share/logstash/jpdata
# 启动多个logstash实例的命令
bin/logstash -f config/test-logstash.conf --config.reload.automatic --path.data=/usr/share/logstash/jpdata
# 启动前先检查配置文件是否正确
bin/logstash -f logstash-sample.conf --config.test_and_exit

# 参数说明
--path.data是指存放数据的路径
--config.reload.automatic 热加载配置文件,修改配置文件后无需重新启动

logstash配置文件

test-logstash.conf

代码语言:txt
复制
# 从kafka中读取内容
input {
  kafka {
    bootstrap_servers => "192.168.104.102:9092"
    topics => ["stream-in"]
    codec => "json"
  }
}
# 内容过滤
filter {
  grok {
      match => {"message" => "%{COMBINEDAPACHELOG}"}
  }
}
#}
# 输出内容到控制台显示
output {
    stdout { codec => rubydebug}
}

logstash-es.conf

代码语言:txt
复制
# 从kafka中读取内容
input {
  kafka {
    bootstrap_servers => "192.168.104.102:9092"
    topics => ["stream-in"]
    codec => "json"
  }
}
# 内容过滤
filter {
  json {
      source => "message"
  }
}
# 输出内容到elasticsearch
output {
  elasticsearch {
    hosts => ["192.168.104.102:9200"]
    index => "logstash-%{+YYYY.MM.dd}"
  }
}

kafka

docker 中kafka的安装路径在/opt/kafka_2.12-2.3.0/bin下,

代码语言:txt
复制
# tree查看文件结构
yum -y install tree
# 查看kafka在zookeeper中的所有topic
kafka-topics.sh --zookeeper 192.168.104.102:2181 --list
# 此种方式查询到的是所有 topic 的所有 group.id ,  而没有根据 topic 查询 group.id 的方式。
kafka-consumer-groups.sh --bootstrap-server kafka1:9092 --list
# 给topic插入数据
kafka-console-producer.sh --broker-list kafka1:9092 --topic stream-in
# Kafka中启动Consumer来查询topic内容:
kafka-console-consumer.sh --bootstrap-server kafka1:9092 --topic stream-in -from-beginning

zookeeper

./zkCli.sh

其他

https://blog.csdn.net/s332755645/article/details/80180008

https://blog.csdn.net/wxlchinaren/article/details/83303708

https://www.elastic.co/guide/en/beats/filebeat/current/kafka-output.html

https://www.cnblogs.com/AcAc-t/p/kafka_topic_consumer_group_command.html

https://www.cnblogs.com/xiaodf/p/6093261.html#4

Kibana开启中文语言

mysql Client does not support authentication protocol

兼容性

代码语言:txt
复制
# 查看filebeat进程
ps -ef | grep filebeat

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 技术选型
  • 下载镜像
  • 创建容器
  • filebeat的下载与安装
    • filebeat的配置文件
      • 查看filebeat与kafka的TCP连接
      • logstash
        • logstash配置文件
        • kafka
        • zookeeper
        • 其他
        相关产品与服务
        容器镜像服务
        容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档