Logstash Docker 部署 安装 logstash-output-jdbc

embedded/2024/9/20 15:36:18/

Logstash Docker 部署 安装 logstash-output-jdbc

前置步骤参考:https://blog.csdn.net/weixin_44121790/article/details/141305720

问题:

今天使用docker 部署logstash,遇到无法运行的问题,原因是因为配置问题使用了 logstash-output-jdbc ,但是镜像默认没有安装。

配置文件如下:

#注释方法#####
input {syslog {port => "5044"}	
}
filter {ruby {code => "event.set('timestamp', event.get('@timestamp').time.localtime + 8*60*60)"}if("WinFileService" in [message] or "FtpFileTransfer" in [message]){grok{match =>{"message"=>"%{WORD:opt_type} Event: %{DATA:opt_name}, Path: %{DATA:path}, File/Folder: %{WORD:file_type}, Size: %{BASE16FLOAT:size} %{WORD:size_unit}, User: %{DATA:username}, IP: %{IPV4:opt_ip}"}}grok{match=>{"path"=>"%{GREEDYDATA}/%{GREEDYDATA:file_name}"}}if("KB" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i * 1024)"}}if("MB" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i * 1024 * 1024)" }} if("GB" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i * 1024 * 1024 * 1024)"}}if("Bytes" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i)"}}}		 
}output {stdout {}if("FtpFileTransfer" in [opt_type]){jdbc{driver_jar_path => "/usr/share/logstash/config/jar/mysql-connector-j-8.4.0.jar"driver_class => "com.mysql.cj.jdbc.Driver"connection_string => "jdbc:mysql://192.168.10.23:3306/database_name?user=root&password=xxxxxxx&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true"statement => ["insert into t_ftp_log(level, event, full_path, file_size, event_time,app_source,user_name,source_ip,file_name) VALUES (?,?,?,?,?,?,?,?,?)","[log][syslog][priority]","opt_name","path","size_byte","@timestamp","[host][hostname]","username","opt_ip","file_name"]}   }
}

解决方法:

编辑logstash.yml

指定 config路径

http.host: "0.0.0.0"
# xpack.monitoring.elasticsearch.hosts: [ "http://127.0.0.1:9200" ]
path.logs: /usr/share/logstash/logs
path.config: /usr/share/logstash/config/conf.d/*.conf

重点
在此config路径下创建一个简单的config文件logstash.conf,内容如下:

input {syslog {port => 5044}
}output {stdout {codec => rubydebug}
}

然后启动容器

docker run --name logstash-sample -p 5044:5044 -p 9600:9600  -v /opt/docker/logstash/config:/usr/share/logstash/config -v /opt/docker/logstash/data:/usr/share/logstash/data -v /opt/docker/logstash/pipeline:/usr/share/logstash/pipeline -d docker.elastic.co/logstash/logstash:8.14.1

使用docker logs [container]查看是否启动成功,如果启动成功,则使用如下命令进入容器

docker exec -it --user root logstash-syslog-nas /bin/bash

进入容器后,需修改Gemfile source 源为国内镜像,否则可能会无法获取安装包

source "https://gems.ruby-china.com"

然后执行命令安装 logstash-output-jdbc

bin/logstash-plugin install logstash-output-jdbc

安装成功后,退出容器。记得配置 mysql-connector-j-8.4.0.jar路径,参考文章开头的配置文件

exit

重点
进入映射配置文件路径

cd /usr/share/logstash/config/conf.d/

将一开始配置的文件logstash.conf 替换为最初的配置:

#注释方法#####
input {syslog {port => "5044"}	
}
filter {ruby {code => "event.set('timestamp', event.get('@timestamp').time.localtime + 8*60*60)"}if("WinFileService" in [message] or "FtpFileTransfer" in [message]){grok{match =>{"message"=>"%{WORD:opt_type} Event: %{DATA:opt_name}, Path: %{DATA:path}, File/Folder: %{WORD:file_type}, Size: %{BASE16FLOAT:size} %{WORD:size_unit}, User: %{DATA:username}, IP: %{IPV4:opt_ip}"}}grok{match=>{"path"=>"%{GREEDYDATA}/%{GREEDYDATA:file_name}"}}if("KB" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i * 1024)"}}if("MB" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i * 1024 * 1024)" }} if("GB" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i * 1024 * 1024 * 1024)"}}if("Bytes" in [size_unit]){ruby{code =>"event.set('size_byte', event.get('size').to_i)"}}}		 
}output {stdout {}if("FtpFileTransfer" in [opt_type]){jdbc{driver_jar_path => "/usr/share/logstash/config/jar/mysql-connector-j-8.4.0.jar"driver_class => "com.mysql.cj.jdbc.Driver"connection_string => "jdbc:mysql://192.168.10.23:3306/database_name?user=root&password=xxxxxxx&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true"statement => ["insert into t_ftp_log(level, event, full_path, file_size, event_time,app_source,user_name,source_ip,file_name) VALUES (?,?,?,?,?,?,?,?,?)","[log][syslog][priority]","opt_name","path","size_byte","@timestamp","[host][hostname]","username","opt_ip","file_name"]}   }
}

然后重启容器

docker restart logstash

恭喜
大功告成!


http://www.ppmy.cn/embedded/99621.html

相关文章

2024网络安全学习路线 非常详细 推荐学习

关键词:网络安全入门、渗透测试学习、零基础学安全、网络安全学习路线 首先咱们聊聊,学习网络安全方向通常会有哪些问题 1、打基础时间太长 学基础花费很长时间,光语言都有几门,有些人会倒在学习 linux 系统及命令的路上&#…

EKS开源系列之XF_UTILS工具库

EKS开源系列之XF_UTILS工具库 为啥要写这个中间件这个中间件的特色xf_utils 有那些功能文件夹结构xf_utils API 有哪些xf_checkxf_lockxf_stdxf_utils_logxf_commonxf_attributexf_bit_defsxf_errxf_listxf_predefxf_version 开源链接移植教程 为啥要写这个中间件 当我们开发软…

支持redis和zookeeper的分布式锁组件lock4j

Lock4j是一个基于Spring AOP的分布式锁组件,它提供了多种底层实现(如RedisTemplate、Redisson、Zookeeper)以满足不同性能和环境的需求。 开源地址:GitHub - baomidou/lock4j: 基于Spring AOP 的声明式和编程式分布式锁&#xff…

Vue 2 项目升级到 Vue 3 操作手册

引言 Vue 3 是 Vue.js 框架的重大版本更新,引入了许多新特性和性能改进。本文将详细介绍如何将一个现有的 Vue 2 项目逐步升级到 Vue 3,并提供具体的步骤和示例代码。 1. Vue 3 的新特性 在开始升级之前,让我们先了解一下 Vue 3 中的一些重…

全新分支版本!微软推出Windows 11 Canary Build 27686版

已经很久没有看到 Windows 11 全新的分支版本了,今天微软发布 Windows 11 Canary 新版本,此次版本号已经转移到 Build 27xxx,首发版本为 Build 27686 版。 此次更新带来了多项改进,包括 Windows Sandbox 沙盒功能切换到 Microsof…

electron 官网速通

前言:参考Electron 中文网。 核心知识点:有哪些进程,进程之间的通信,electron API 分类及怎么调用。 一、快速开始 1. 新建一个 my-electron 的文件夹。 2. 运行 npm init 创建 package.json 文件。 3. 填写 author 和 descr…

DID测试套件

DID测试套件 介绍 名称 DID Test Suite 网址 https://github.com/w3c/did-test-suite 功能 用于验证DID实现是否符合W3C DID Core规范的一系列测试反映各DID方法(如did:orb、did:key、did:web等)的实现对DID Core规范的遵从程度确保不同DID方法、…

在Ubuntu 部署 Grafana且监控MySQL数据

一、安装 打开终端按顺序执行以下命令 1.添加 Grafana 的 APT 仓库: sudo apt-get install -y software-properties-common sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" 2.导入Grafana GPG key: wge…

easyexcel字典通用转化器

背景:日常开发中使用框架常常有字典功能,导出的时候每创建一个字典就创建一个转化器也比较麻烦,所以这里封装一个统一转化器 转化器: package com.tianyi.nppm.biz.commissioning.dto.supervision.auth.tool;import com.alibaba…

python脚本:输入基因名,通过爬虫的方式获取染色体上的location。

本团队提供生物医学领域专业的AI(机器学习、深度学习)技术支持服务。如果您有需求,请扫描文末二维码关注我们。 python脚本:输入基因名,通过爬虫的方式获取染色体上的location。 def get_gene_location(gene_symbol):…

MS SQL Server partition by 函数实战二 编排考场人员

目录 需求 输出效果 范例运行环境 表及视图样本设计 功能实现 生成考场数据 生成重复的SQL语句 封装为统计视图 编写存储过程实现统计 小结 需求 假设有若干已分配准考证号的考生,准考证号示例(01010001)共计8位,前4位…

SLAM学习笔记

从《slam十四讲开始》 slam十四讲推荐的其他书籍 《概率机器人》(Probabilistic robotics ) 《计算机视觉中的多视图几何》(Multiple View Geometry in Computer Vision ) 《机器人学中的状态估计》(State Estimation…

【DRAM存储器三十九】LPDDR4/DDR4的时序训练相关内容之读方向的训练

👉个人主页:highman110 👉作者简介:一名硬件工程师,持续学习,不断记录,保持思考,输出干货内容 参考资料:《镁光LPDDR4数据手册》 、《JESD209-4B》 跟写操作一样,一切跟读相关的训练都可以归结为read leveling,包括如下内容: read DQS gate training 我…

Arduino开源四足蜘蛛机器人制作教程

视频教程:手把手叫你做四足蜘蛛机器人——1零件介绍_哔哩哔哩_bilibili 一、项目介绍 1.1 项目介绍 Arduino主控,图形化编程,趣味学习 Arduino nano开发板舵机扩展底板 4.8V可充电电池,支持Arduino C语言编程和米思齐图形化编程…

XSS-DOM

文章目录 源码SVG标签Dom-Clobbringtostring 源码 <script>const data decodeURIComponent(location.hash.substr(1));;const root document.createElement(div);root.innerHTML data;// 这里模拟了XSS过滤的过程&#xff0c;方法是移除所有属性&#xff0c;sanitize…

ansible模块+playbook

scripts模块 script模块用于在远程机器上执行本地脚本。 [rootbb ~]# vim test000.sh [rootbb ~]# cat test000.sh #!/bin/bash mkdir /tmp/three touch /tmp/three/test echo i am echo,at mttt > /tmp/three/test echo well done [rootbb ~]# sh test000.sh mkdir: 无…

微知-ifconfig如何修改mtu?

ifconfig eth0 mtu 1500mtu 最大传输单元 &#xff08;Maximum Transmission Unit&#xff09;。是网络层能够传输的最大数据包大小。包括头部 在tcp里面还有MSS&#xff08;Maximum Segment Size&#xff09;。不包括头部。一般来说&#xff0c;MSS的值会设置为MTU减去20字节&…

鸿蒙内核源码分析(信号生产篇) | 注意结构体的名字和作用.

信号生产 关于信号篇&#xff0c;本只想写一篇&#xff0c;但发现把它想简单了&#xff0c;内容不多&#xff0c;难度极大.整理了好长时间&#xff0c;理解了为何<<深入理解linux内核>>要单独为它开一章&#xff0c;原因有二 信号相关的结构体多&#xff0c;而且…

配置EIGRP命名模式

背景資訊 傳統的配置EIGRP的方法要求在介面和EIGRP配置模式下配置各種引數。為了配置EIGRP IPV4和IPv6&#xff0c;需要配置單獨的EIGRP例項。傳統EIGRP在IPv6 EIGRP實施中不支援虛擬路由和轉發(VRF)。 對於命名模式EIGRP&#xff0c;所有配置都在EIGRP配置下的單個位置進行配…

el-tree多选的父子关联和父子不关联和拖拽功能

公用js变量&#xff1a; data () {return {// 绑定的数组treeData: [],// 多选选择的idids: []} }, 公用js方法&#xff1a; /*** 选择多选改变*/ nodeChange(data, checked, indeterminate) {let keys this.$refs.treeCategory.getCheckedKeys();this.ids keys; } 第一种…