news 2026/8/29 12:18:29

Splunk监控redhat特定日志文件

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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字样发送告警效果如下

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/29 12:13:47

C语言实现匈牙利算法:从二分图匹配到数学建模实战

1. 项目概述&#xff1a;从数学建模到代码实现 最近在辅导几个学生准备数学建模竞赛&#xff0c;发现很多队伍在处理任务分配、资源调度这类优化问题时&#xff0c;第一反应是去套用复杂的智能算法&#xff0c;结果往往代码冗长、调试困难&#xff0c;最后效果还不一定好。其实…

作者头像 李华
网站建设 2026/8/29 12:12:40

北京本地打印机租赁与易点云差异对比 选型参考指南

打印机租赁服务商对比核心维度当前打印机租赁已成为北京各类企业降低办公成本、实现轻资产运营的主流选择&#xff0c;不同服务商的服务覆盖、响应能力、收费模式差异较大&#xff0c;选到适配的服务商可有效减少办公运维负担。对比打印机租赁服务商可从服务地域、响应时效、收…

作者头像 李华
网站建设 2026/8/29 12:11:39

远程团队如何安排协作节奏

远程团队如何安排协作节奏把“远程团队如何安排协作节奏”做扎实&#xff0c;先要放下对工具和框架的偏好&#xff0c;回到实际任务。团队决策与工程协作中的许多返工&#xff0c;并非某个组件能力不足&#xff0c;而是输入、状态和责任没有说透。文档如果只写正常流程&#xf…

作者头像 李华
网站建设 2026/8/29 12:11:12

FPGA实现DDS信号发生器:从原理到工程实践

1. 项目概述&#xff1a;从零开始理解FPGA上的DDS信号发生器 如果你刚开始接触FPGA&#xff0c;看到“DDS正弦信号发生器”这个标题&#xff0c;可能会觉得它既熟悉又陌生。熟悉是因为“信号发生器”是电子工程里最基础的仪器之一&#xff0c;陌生则是因为“DDS”和“FPGA”这两…

作者头像 李华
网站建设 2026/8/29 12:10:51

5款本地LLM工具实测|GPT4All凭什么在低配机上跑起来

5款本地LLM工具实测&#xff5c;GPT4All凭什么在低配机上跑起来 【免费下载链接】gpt4all GPT4All: Run Local LLMs on Any Device. Open-source and available for commercial use. 项目地址: https://gitcode.com/GitHub_Trending/gp/gpt4all 赶时间看这里&#xff1a;…

作者头像 李华