Splunk入门与安装(Linux系统)

简介: 1、Splunk硬件需求2、Splunk架构图3、下载tgz: wget -O splunk-7.0.1-2b5b15c4ee89-Linux-x86_64.

1、Splunk硬件需求


img_32fdb4b0d217b48546a7449e5f2bc58a.png

2、Splunk架构图


img_84375070dba1b29877de20987ab1f692.png

3、下载tgz: wget -O splunk-7.0.1-2b5b15c4ee89-Linux-x86_64.tgz 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=7.0.1&product=splunk&filename=splunk-7.0.1-2b5b15c4ee89-Linux-x86_64.tgz&wget=true'

4、安装

   # rpm -ivhsplunk-5.0.2-149561-linux-2.6-x86_64.rpm

 -------------------------------------------------------------------------

Splunk has been installed in:

       /opt/splunk


To start Splunk, run thecommand:

/opt/splunk/bin/splunk start     #这一行命令要完整敲出来r


To use the Splunk Webinterface, point your browser to:

   http://localhost.localdomain:8000


Complete documentation is athttp://docs.splunk.com/Documentation/Splunk

-------------------------------------------------------------------------

5、启动服务

  /opt/splunk/bin/splunk start   

     //首次启动会有许可协议,按q,再输入y。


6、设置开机自启动

  /opt/splunk/bin/splunk enable boot-start

    #Init script installed at/etc/init.d/splunk.

    #Init script is configured to run atboot.



7、查看帮助

 /opt/splunk/bin/splunk help enable

 可以使用/etc/init.d/splunk管理splunk的启停

 /etc/init.d/splunkstatus


8、访问web页面

 firefox http://172.16.254.239:8000

 首次访问,会提示用户名密码admin/changeme

       登录后,设置新的密码



9、修改默认端口的配置文件

  # vim/opt/splunk/etc/system/default/web.conf

    httpport = 8000

splunk日志的导入

 数据源可以是本地的、远程的、Linux的、Unix的、windows的、交换机的、路由器的等等。也可以是web服务器的,IIS服务器的、ftp服务器的等等。


10、停止当前服务器的防火墙,使得splunk 可以远程访问

systemctl stopfirewalld.service


启动: systemctl start firewalld

查看状态: systemctl status firewalld 

停止: systemctl disable firewalld

禁用: systemctl stop firewalld

在开机时禁用一个服务:systemctl disable firewalld.service

CentOS7使用firewalld打开关闭防火墙与端口

1、firewalld的基本使用

启动:systemctl start firewalld

查看状态:systemctl status firewalld 

停止:systemctl disable firewalld

禁用:systemctl stop firewalld


2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl startfirewalld.service

关闭一个服务:systemctl stopfirewalld.service

重启一个服务:systemctl restartfirewalld.service

显示一个服务的状态:systemctl statusfirewalld.service

在开机时启用一个服务:systemctl enablefirewalld.service

在开机时禁用一个服务:systemctl disablefirewalld.service

查看服务是否开机启动:systemctl is-enabled firewalld.service

查看已启动的服务列表:systemctl list-unit-files|grepenabled

查看启动失败的服务列表:systemctl --failed

3.配置firewalld-cmd

查看版本:firewall-cmd --version

查看帮助:firewall-cmd --help

显示状态:firewall-cmd --state

查看所有打开的端口:firewall-cmd --zone=public --list-ports

更新防火墙规则: firewall-cmd --reload

查看区域信息: firewall-cmd --get-active-zones

查看指定接口所属区域:firewall-cmd --get-zone-of-interface=eth0

拒绝所有包:firewall-cmd--panic-on

取消拒绝状态:firewall-cmd --panic-off

查看是否拒绝:firewall-cmd --query-panic


那怎么开启一个端口呢

添加

firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

重新载入

firewall-cmd --reload

查看

firewall-cmd --zone= public --query-port=80/tcp

删除

firewall-cmd --zone= public --remove-port=80/tcp --permanent


数据导入


一、向splunk中导入本地日志  messages

 添加数据——>syslog——>使用此 Splunk 服务器上的任何 syslog 文件或目录——>服务器上文件的路径 /var/log/messages ——>默认——>默认 继续——>默认,保存


二、搜索想要的日志

 开始搜索——>输入aborting

 搜其他host="localhost"


练习:将secure日志导入到splunk中,并验证其搜索功能



三、向splunk导入远程日志

 环境:

splunkserver :172.16.254.239

      remoteapache:172.16.254.200 web.up.com

 开始配置:

 注意:导入远程日志需要远程主机安装通用转发器(splunkforwarder)。

    1、设置splunk服务器允许接收splunk转发器发送来的数据

 管理器——>转发和接收——>配置接收中“新增”——>9999(指定接收数据的端口)——> 保存

    2、在远程服务器上配置

 1)安装splunkforwarder包

    # rpm -ivh splunkforwarder-5.0.2-149561-linux-2.6-x86_64.rpm

 2)配置splunkforwarder转发apache的日志

    # /opt/splunkforwarder/bin/splunk start

    # /opt/splunkforwarder/bin/splunk add forward-server172.16.254.239:9999

     Splunk username: admin

     Password: changeme

     Added forwarding to: 172.16.254.239:9999.

    # cd /opt/splunkforwarder/etc/system/local/

    # vim inputs.conf

 [default]

 host = web.up.com

 [monitor:///var/log/httpd]

 sourcetype = access_common

 3)重启splunk转发器服务

    # /opt/splunkforwarder/bin/splunk restart

    3、验证结果

 如果在splunk服务器的web页面能够看到web.up.com的apache的日志,就成功了。

 简单搜索:

     host="web.up.com"

     host="web.up.com" error

  host="web.up.com"  OR error   //OR 或者


生成视图

导入测试数据

将Sampledata.zip放到splunk服务器上


继续浏览器操作

   管理器——>数据导入——>文件和目录“新增”——>跳过预览——>上载并索引文件 ——>保存


一、体验splunk强大的搜索功能

  sourcetype="access_combined_wcookie"

1、搜索源类型为access_combined_wcookie,并且IP为10.2.1.44的日志请求

 ——81条

  sourcetype="access_combined_wcookie" 10.2.1.44

2、进一步搜索关于“purchase”的请求—— 63条

  sourcetype="access_combined_wcookie" 10.2.1.44 purchase

3、进一步搜索http返回码不是200的购买请求

  sourcetype="access_combined_wcookie" 10.2.1.44 purchase NOT 200

4、进一步搜索不是404错误的请求

  sourcetype="access_combined_wcookie" 10.2.1.44 purchase NOT 200NOT 404


用关键字搜索

 搜索买花时间

  sourcetype="access_combined_wcookie" 10.2.1.44action=purchase category_id=flowers


|:前面的搜索结果作为后面的命令的输入

   1、搜索最热卖的商品  使用命令top

    sourcetype="access_combined_wcookie" action=purchase | topcategory_id

   2、有多少名不同的顾客买了鲜花

     需要使用stats命令和dc函数实现

    sourcetype="access_combined_wcookie" action=purchasecategory_id=flowers | stats dc(clientip)

   3、每个顾客分别买了多少花?

    sourcetype="access_combined_wcookie" action=purchasecategory_id=flowers | stats count by clientip

 需要使用stats命令和count函数并且使用by子句

   4、倒序显示每个顾客购买多少花?

     sourcetype="access_combined_wcookie"action=purchase category_id=flowers | stats count by clientip | sort -count

     sort-count:按照count字段倒序排序

     sortcount:按照正序排序

   5、给数据列起别名

    sourcetype="access_combined_wcookie" action=purchasecategory_id=flowers | stats count by clientip | sort count | rename clientip as"顾客", count as "购花总数"


二、将搜索结果保存为仪表盘

    1、创建一个空的仪表盘

 仪表板和视图——>创建仪表板——>ID:001 名称:每个顾客购花总数 ——> 创建

    2、将搜索结果保存到仪表盘

  sourcetype="access_combined_wcookie" action=purchase category_id=flowers| stats count by clientip | sort -count | rename clientip as "顾客" , count as"购花总数"

 搜索——>创建——>仪表板面板——>每个顾客购花总数——>现有仪表板——>下拉列表中选择需要的仪表板——> 默认


三、在收集结果时动态更新生成的图表

 创建报表

     搜索:sourcetype="access_combined_wcookie"action=purchase category_id=flowers | stats count by clientip | sort -count

     创建——>报表




日志转发器安装




Splunk日志服务器windows客户端安装

下载客户端http://www.splunk.com/download/universalforwarder




你懂的。

Splunk服务器地址和端口,必须写。





可以先不填,直接next。

直接下一步。





选择要上传的数据类型。这个只需要logs即可,右边那些是snmp干的活。

点击安装。





完成。

运行——cmd——回车不懂撞墙去。


cd {splunk安装目录}/bin/

        splunk.exe add forward-server 192.168.180.200:9997

用户名 admin  

密码 changeme

注:9997端口需要在splunk服务器上先设置好。

具体配置如下图:

重启splunk服务


检查设置splunk forwarder设置


Splunk.exe list forward-server

客户端计算机名称

使用查询功能。


搞定!!



Linux forward安装


1)、将通用转发器解压到opt目录下,Splunk转发器的安装方法和splunk一致,但它无UI界面。

tar zxvfsplunkforwarder-************-Linux-x86_64.tgz -C /opt

2)、切换到Splunkforwarder的bin目录下去启动通用转发器

cd/opt/splunkforwarder/bin/   #//切换到通用转发器的可执行程序目录

./splunkstart –accept-license    #//启动通用转发器一次启动有很长的 协议 使用回车键转到最后按”y” 同意在回车。


注意:如果splunk web和通用转发器安装在同一 服务器,通用转发器的管理端口也是8090,则会提示被splunk占用


3配置转发器需要转发的服务器ip和端口

./splunk addforward-server 192.168.180.200:9997

用户名 admin  

密码 changeme

注:9997端口需要在splunk服务器上先设置好监听端口。


4.设置开机自启动

/opt/splunkforwarder/bin/splunkenable boot-start


5.检查设置splunk forwarder设置


./Splunklist forward-server

相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
目录
相关文章
|
6月前
|
消息中间件 Kafka Linux
Linux下安装Kafka 3.9.1
本文介绍Kafka 3.9.1版本的安装与配置,包括通过ZooKeeper或KRaft模式启动Kafka。涵盖环境变量设置、日志路径修改、集群UUID生成、存储格式化及服务启停操作,适用于Linux环境下的部署实践。
776 0
|
6月前
|
安全 Linux iOS开发
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
422 6
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
|
7月前
|
数据管理 Linux iOS开发
Splunk Enterprise 9.4.5 (macOS, Linux, Windows) - 机器数据管理和分析
Splunk Enterprise 9.4.5 (macOS, Linux, Windows) - 机器数据管理和分析
218 0
|
7月前
|
Ubuntu Linux Anolis
Linux系统禁用swap
本文介绍了在新版本Linux系统(如Ubuntu 20.04+、CentOS Stream、openEuler等)中禁用swap的两种方法。传统通过注释/etc/fstab中swap行的方式已失效,现需使用systemd管理swap.target服务或在/etc/fstab中添加noauto参数实现禁用。方法1通过屏蔽swap.target适用于新版系统,方法2通过修改fstab挂载选项更通用,兼容所有系统。
613 3
Linux系统禁用swap
|
7月前
|
Linux
Linux系统修改网卡名为eth0、eth1
在Linux系统中,可通过修改GRUB配置和创建Udev规则或使用systemd链接文件,将网卡名改为`eth0`、`eth1`等传统命名方式,适用于多种发行版并支持多网卡配置。
1146 3
|
Ubuntu Linux 网络安全
Linux系统初始化脚本
一款支持Rocky、CentOS、Ubuntu、Debian、openEuler等主流Linux发行版的系统初始化Shell脚本,涵盖网络配置、主机名设置、镜像源更换、安全加固等多项功能,适配单/双网卡环境,支持UEFI引导,提供多版本下载与持续更新。
718 3
Linux系统初始化脚本
|
7月前
|
安全 Linux Shell
Linux系统提权方式全面总结:从基础到高级攻防技术
本文全面总结Linux系统提权技术,涵盖权限体系、配置错误、漏洞利用、密码攻击等方法,帮助安全研究人员掌握攻防技术,提升系统防护能力。
829 1
|
7月前
|
监控 安全 Linux
Linux系统提权之计划任务(Cron Jobs)提权
在Linux系统中,计划任务(Cron Jobs)常用于定时执行脚本或命令。若配置不当,攻击者可利用其提权至root权限。常见漏洞包括可写的Cron脚本、目录、通配符注入及PATH变量劫持。攻击者通过修改脚本、创建恶意任务或注入命令实现提权。系统管理员应遵循最小权限原则、使用绝对路径、避免通配符、设置安全PATH并定期审计,以防范此类攻击。
1242 1
|
Linux
手把手教会你安装Linux系统
手把手教会你安装Linux系统
346 0