Splunk入门与安装(Linux系统)

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 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

相关实践学习
通过日志服务实现云资源OSS的安全审计
本实验介绍如何通过日志服务实现云资源OSS的安全审计。
目录
相关文章
|
2月前
|
Ubuntu Linux
计算机基础知识:linux系统怎么安装?
在虚拟机软件中创建一个新的虚拟机,并选择相应操作系统类型和硬盘空间大小等参数。将下载的 ISO 镜像文件加载到虚拟机中。启动虚拟机,进入安装界面,并按照步骤进行安装。安装完成后,可以在虚拟机中使用 Linux 系统。
|
12天前
|
数据管理 Linux iOS开发
Splunk Enterprise 9.4.5 (macOS, Linux, Windows) - 机器数据管理和分析
Splunk Enterprise 9.4.5 (macOS, Linux, Windows) - 机器数据管理和分析
42 0
|
2月前
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
796 10
|
2月前
|
弹性计算 安全 Linux
阿里云服务器ECS安装宝塔Linux面板、安装网站(新手图文教程)
本教程详解如何在阿里云服务器上安装宝塔Linux面板,涵盖ECS服务器手动安装步骤,包括系统准备、远程连接、安装命令执行、端口开放及LNMP环境部署,手把手引导用户快速搭建网站环境。
|
2月前
|
安全 Linux 数据安全/隐私保护
为Linux系统的普通账户授予sudo访问权限的过程
完成上述步骤后,你提升的用户就能够使用 `sudo`命令来执行管理员级别的操作,而无需切换到root用户。这是一种更加安全和便捷的权限管理方式,因为它能够留下完整的权限使用记录,并以最小权限的方式工作。需要注意的是,随意授予sudo权限可能会使系统暴露在风险之中,尤其是在用户不了解其所执行命令可能带来的后果的情况下。所以在配置sudo权限时,必须谨慎行事。
335 0
|
2月前
|
Ubuntu Linux 开发者
国产 Linux 发行版再添新成员,CutefishOS 系统简单体验
当然,系统生态构建过程并不简单,不过为了帮助国产操作系统优化生态圈,部分企业也开始用国产操作系统替代 Windows,我们相信肯定会有越来越多的精品软件登录 Linux 平台。
122 0
|
2月前
|
Ubuntu 安全 Linux
Linux系统入门指南:从零开始学习Linux
Shell脚本是一种强大的自动化工具,可以帮助您简化重复的任务或创建复杂的脚本程序。了解Shell脚本的基本语法和常用命令,以及编写和运行Shell脚本的步骤,将使您更高效地处理日常任务。
220 0
|
2月前
|
Ubuntu Linux 图形学
Linux学习之Linux桌面系统有哪些?
Cinnamon:与MATE类似,Cinnamon 拥有 GNOME 和 Unity 等其它桌面环境所没有的种种功能,是高度可定制的桌面环境,不需要任何外部插件、窗口组件和调整工具来定制桌面。
128 0
|
2月前
|
Ubuntu 安全 Linux
十款常用Linux系统介绍
本文不是什么大盘点。市面上有好几百款发行版,每款发行版在某个方面都与众不同。不可能在此全部罗列,本文只罗列了十款最常见的Linux发行版(世界上只有两种人,一种是懂二进制的,另一种是不懂二进制的)。请宣传Linux的魅力或威力。
|
2月前
|
安全 Ubuntu Linux
如何安装Linux操作系统?
此时,您可以选择重新启动计算机,然后从硬盘上的Linux系统启动。以上是一个大致的安装过程。请注意,不同的Linux发行版可能会在细节上有所差异,因此在进行安装之前,请确保您阅读并理解了相应发行版的安装指南或文档。