当前位置: 首页 > news >正文

Splunk监控redhat特定日志文件

环境:被监控系统版本redhat7.9 splunk版本9.X.X splunk服务器地址10.10.10.10

前提条件:splunk服务器已经配置好了告警邮件服务器,接收9997端口数据,已新建索引testdata,终端可以访问splunk服务器的9997/tcp端口

一、被监控redhat系统安装客户端

1、将安装包上传到redhat系统/tmp目录

2、安装splunk客户端

rpm -ivh splunkforwarder-9.3.2-d8bb32809498.x86_64.rpm

安装过程中出现的下述错误对客户端基本功能使用不会造成影响

[root@XXX tmp]# rpm -ivh splunkforwarder-9.3.2-d8bb32809498.x86_64.rpm
warning: splunkforwarder-9.3.2-d8bb32809498.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID b3cd4420: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:splunkforwarder-9.3.2-d8bb3280949################################# [100%]
find: ‘/opt/splunkforwarder/lib/python3.7/site-packages’: No such file or directory
find: ‘/opt/splunkforwarder/lib/python3.9/site-packages’: No such file or directory
complete

3、配置客户端日志外发

新建并编辑outputs.conf文件

vi /opt/splunkforwarder/etc/system/local/outputs.conf

内容为:

[tcpout] defaultGroup = primary_splunkservers [tcpout:primary_splunkservers] server = 10.10.10.10:9997 compressed = true

4、配置客户端日志收集

新建并编辑inputs.conf文件

vi /opt/splunkforwarder/etc/system/local/inputs.conf

内容为:

[monitor:///var/log/messages] sourcetype = linux_messages_log index = testdata disabled = 0

5、运行splunk客户端

启动客户端服务

/opt/splunkforwarder/bin/splunk start

[root@xxxx tmp]# /opt/splunkforwarder/bin/splunk start
Warning: Attempting to revert the SPLUNK_HOME ownership
Warning: Executing "chown -R splunkfwd:splunkfwd /opt/splunkforwarder"
SPLUNK GENERAL TERMS

Last Updated: August 12, 2021

These Splunk General Terms ("General Terms") between Splunk Inc., a Delaware
corporation, with its principal place of business at 270 Brannan Street, San
Francisco, California 94107, U.S.A ("Splunk" or "we" or "us" or "our") and you
("Customer" or "you" or "your") apply to the purchase of licenses and
subscriptions for Splunk's Offerings. By clicking on the appropriate button,
or by downloading, installing, accessing or using the Offerings, you agree to
these General Terms. If you are entering into these General Terms on behalf of
Customer, you represent that you have the authority to bind Customer. If you
do not agree to these General Terms, or if you are not authorized to accept
the General Terms on behalf of the Customer, do not download, install, access,
or use any of the Offerings.

See the General Terms Definitions Exhibit attached for definitions of
capitalized terms not defined herein.

XXXXXXXXXXXXXXXXXXXXX中间有很多内容直接拖到底

"Splunk Preexisting IP" means, with respect to any C&I Services Materials, all
associated Splunk technology and all Intellectual Property Rights created or
acquired: (a) prior to the date of the Statement of Work that includes such
C&I Services Materials, or (b) after the date of such Statement of Work but
independently of the C&I Services provided under such Statement of Work.

"Statement of Work" means the statements of work and/or any and all applicable
Orders, that describe the specific services to be performed by Splunk,
including any materials and deliverables to be delivered by Splunk.

Do you agree with this license? [y/n]:

y

This appears to be your first time running this version of Splunk.

Splunk software must create an administrator account during startup. Otherwise, you cannot log in.
Create credentials for the administrator account.
Characters do not appear on the screen when you type in credentials.

Please enter an administrator username: admin

admin


Password must contain at least:
* 8 total printable ASCII character(s).
Please enter a new password:
Please confirm new password:

Password

Creating unit file...
Important: splunk will start under systemd as user: splunkfwd
The unit file has been created.


Splunk> CSI: Logfiles.

Checking prerequisites...
Checking mgmt port [8089]: open
Creating: /opt/splunkforwarder/var/lib/splunk
Creating: /opt/splunkforwarder/var/run/splunk
Creating: /opt/splunkforwarder/var/run/splunk/appserver/i18n
Creating: /opt/splunkforwarder/var/run/splunk/appserver/modules/static/css
Creating: /opt/splunkforwarder/var/run/splunk/upload
Creating: /opt/splunkforwarder/var/run/splunk/search_telemetry
Creating: /opt/splunkforwarder/var/run/splunk/search_log
Creating: /opt/splunkforwarder/var/spool/splunk
Creating: /opt/splunkforwarder/var/spool/dirmoncache
Creating: /opt/splunkforwarder/var/lib/splunk/authDb
Creating: /opt/splunkforwarder/var/lib/splunk/hashDb
Creating: /opt/splunkforwarder/var/run/splunk/sessions
New certs have been generated in '/opt/splunkforwarder/etc/auth'.
Checking conf files for problems...
Done
Checking default conf files for edits...
Validating installed files against hashes from '/opt/splunkforwarder/splunkforwarder-9.3.2-d8bb32809498-linux-2.6-x86_64-manifest'
All installed files intact.
Done
All preliminary checks passed.

Starting splunk server daemon (splunkd)...
Done
[ OK ]

客户端这边的账户密码正常情况下不会使用到,但建议记录到文档中留存。

二、将日志正文内容添加到message字段

1、在splunk平台查看收集到的日志

在新搜索中搜索index="testdata",即可搜索到/var/log/messages中的日志,此时正文内容不属于任何字段。

2、在当前页面右侧点击“+提取新字段”

3、在新出现的窗口中随便选择“我更喜欢自己编写正则表达式”

4、正则表达式填写 ^(?P<message>.+) 即获取日志的所有正文内容,点击预览查看是否所有的日志正文都变成message字段了,可以看到_raw字段中所有内容都变蓝了,且和message字段中的内容一致,这说明正则表达式的内容获取了日志的所有正文内容。

5、点击保存

6、在新出现的窗口查看信息是否正确,字段的提取名称默认即可

7、点击完成,会出现提示成功的窗口

8、再看之前的日志,已经多了一行message信息

三、根据message信息设置邮件告警

新建邮件告警搜索内容如下

根据上述内容设置系统日志中出现error字样发送告警效果如下

http://www.cnnetsun.cn/news/4286534.html

相关文章:

  • C语言实现匈牙利算法:从二分图匹配到数学建模实战
  • 北京本地打印机租赁与易点云差异对比 选型参考指南
  • 远程团队如何安排协作节奏
  • FPGA实现DDS信号发生器:从原理到工程实践
  • 5款本地LLM工具实测|GPT4All凭什么在低配机上跑起来
  • GPT4All本地大模型教程:5步装好并跑通第一次对话(无需GPU)
  • 用 Mermaid 打通 Confluence 图表管理:3 步落地,让文档里的图不再失控
  • Zvec向量索引类型总览:Flat/IVF/HNSW/DiskANN/Vamana完整指南
  • 当内存不再降价:从DRAM周期到RAM预算管理的优化实践
  • wigolo 10大工具速览:search、fetch、crawl、extract一站式网络工具集清单
  • 告别手动搬运:三步实现参考文献的智能识别与论文全文一键打包
  • Agent工具调用失败处理指南:从异常分类到容错兜底
  • Scrapling网络爬虫实战指南:从单页请求到整站采集的避坑教程
  • C++多线程编程:互斥锁与RAII锁管理器的原理与实践
  • 用Python和FastAPI构建个人健康管理系统:从数据库到可视化看板
  • Hermes Agent 浏览器自动化完整指南:如何 30 分钟跑通网页抓取与智能交互
  • Hoppscotch:三步装好免费上手的开源 API 测试工具
  • Whisper 微调指南:如何让语音识别模型听懂你的行业黑话
  • 清华同方TZ611-V3 Win10驱动适配实战指南
  • NAND与SSD价格持续下跌:供需逻辑、技术迭代与采购应对全解析
  • ISODATA算法实战:从数据预处理到动态聚类的完整流程与避坑指南
  • 数学建模竞赛论文写作模板:结构解析与高效实践指南
  • Grok Imagine Image 2.0实战:从AI图片生成到批量出图工作流
  • Dear ImGui 入门教程:零基础开发者如何 30 分钟画出第一个窗口
  • ADC转换点测试:从原理到实践,精准评估模数转换器性能
  • LSTM+高斯过程回归+贝叶斯优化:新能源汽车销量预测混合框架
  • Fira Code 连字字体安装教程:3 步装好并启用连字
  • DeepSeek API接入实战:从推理模型reasoning_content到http 400排错
  • C++模板编程深度解析:从泛型基础到STL实现原理
  • 智能体服务流量增长前要补哪些防线