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

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
4天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
22 0
|
1天前
|
关系型数据库 MySQL Java
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
13 2
|
1天前
|
负载均衡 Java 应用服务中间件
nginx安装在linux上
nginx安装在linux上
21 2
|
2天前
|
Ubuntu Linux
Linux(Ubuntu)系统临时IP以及静态IP配置(关闭、启动网卡等操作)
请注意,以上步骤是在临时基础上进行配置的。如果要永久保存静态IP地址,通常还需要修改 `/etc/network/interfaces`文件,以便在系统重启后保持配置。同时,确保备份相关配置文件以防止出现问题。
13 1
|
2天前
|
Linux 数据安全/隐私保护
Linux系统忘记密码的三种解决办法
这篇博客介绍了三种在Linux忘记密码时重置登录密码的方法:1) 使用恢复模式,通过控制台界面以管理员权限更改密码;2) 利用Linux Live CD/USB启动,挂载硬盘分区并使用终端更改密码;3) 进入单用户模式,自动以管理员身份登录后重置密码。每个方法都提供了详细步骤,提醒用户在操作前备份重要数据。
|
2天前
|
JSON Unix Linux
Linux系统之jq工具的基本使用
Linux系统之jq工具的基本使用
30 2
|
2天前
|
数据采集 监控 安全
linux系统被×××后处理经历
linux系统被×××后处理经历
|
3天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
41 2
|
3天前
|
缓存 Linux
linux系统缓存机制
linux系统缓存机制
|
3天前
|
存储 Linux Android开发
RK3568 Android/Linux 系统动态更换 U-Boot/Kernel Logo
RK3568 Android/Linux 系统动态更换 U-Boot/Kernel Logo
18 0