splunk采集linux日志,splunk日志监控利器

日志处理引擎SPLUNK

Splunk分为免费Free版和企业Enterprise版。SplunkFree专供个人使用。SplunkEnterprise添加了支持多用户和分布式部署的功能,并包括警报、基于角色的安全、单一登录、预设的PDF交付以及对无限数据量的支持。

你可以使用浏览器访问http://zh-hans.splunk.com/download下载最新版的Splunk。如果你是第一次访问Splunk网站,需要先注册一个Splunk用户,默认下载的是60天Enterprise试用版,60天试用之后将自动转化为Free版,转化位Free版后每日处理的日志量最高位500M。

Splunk 192.168.0.116

客户端192.168.0.117

192.168.0.116配置

#rpm -ivh splunk-5.0.2-149561.i386.rpm

#/opt/splunk/bin/splunk start

#/opt/splunk/bin/splunk status

splunkdis running (PID: 7730).

splunkhelpers are running (PIDs: 7731).

splunkwebis running (PID: 7788).

开机启动Splunk

vim /root/.bashrc

export PATH=/opt/splunk/bin/:$PATH

. /root/.bashrc

#/opt/splunk/bin/splunkenableboot-start

Initscript installed at /etc/init.d/splunk.

Initscript is not configured to run at boot.可以忽略这句话

[root@splunk~]# chkconfig --list |grep splunk

splunk0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

#/etc/init.d/splunkstop

#/etc/init.d/splunk start

可以打开浏览器http://192.168.0.116:8000

实例:添加本地syslog到Splunk时时更新日志

管理--数据导入--添加数据---sysylog--下一步---路径--继续--保存--返回---联机

1.设置Splunk服务器允许接收Splunk Forwarder发送的数据。

进入“Splunk配置首页”,选点右上角的“管理器”,在“数据”类里找到“转

发和接收”。在“接收数据”项中,点击“新增”,Splunk默认接收转发器连接到端口是9997,我们需要将端口填入“输入框”中。点击保存后,Splunk服务默认会打开tcp的9997端口用于监听

2.配置Splunk Forwarder端客户端

安装软件:

# rpm -ivh splunkforwarder-5.0.2-149561.i386.rpm

启动:

#/opt/splunkforwarder/bin/splunk start

服务器端改的配置其转发到192.168.0.116主机的9997端口。默认用户名为admin,密码是changeme.

下面的都是客户端192.168.0.117

# /opt/splunkforwarder/bin/splunk add forward-server192.168.131.203:9997

改密码

#/opt/splunkforwarder/bin/splunk edit user admin -password123456–authadmin:changeme

[root@web ~]#vim ~/.bashrc

exportSPLUNK_HOME=/opt/splunkforwarder

exportPATH=$SPLUNK_HOME/bin:$PATH

配置转发文件

#pwd

/opt/splunkforwarder/etc/system/local

#ls

inputs.confoutputs.conf README server.conf

配置文件outputs.conf,配置服务器转发目标地址和转发状态:

[tcpout]

defaultGroup= default-autolb-group

[tcpout:default-autolb-group]

server= 192.168.131.150:9997

[tcpout-server://192.168.0.117:9997]

配置文件inputs.conf,配置本地需要转发的日志文件和日志文件类型:

[root@weblocal]# cat inputs.conf

[default]

host= web

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

sourcetype= access_common

修改inputs.conf文件后重启splunk forwarder

测试:登陆http://192.168.0.116:8000,点击“应用”-----〉“search”。

注意:0字节的日志文件不会被转发

多次访问网站后,日志会不断更新,splunk中也会不断更新。

Splunk应用扩展简介

Splunk作为一个可扩展的日志分析平台目前支持基于API的扩展,第三方可以基于Splunk的API编写Splunk应用扩展。通过Splunk应用扩展,可以增强Splunk对数据的

进一步分析。安装Splunk应用可以通过Splunk的web界面,也可以通过Splunk的文本控制界面。

连接https://192.168.0.116:8000,点选“管理器”:

点击“应用”,打开“应用管理界面”页:

我们可以通过三种方式安装或创建新应用:

1.联机查找更多应用:如果你可以连接互联网,这是一个方便的安装应用方式

2.从文件安装应用:如果你无法连接互联网,可以通过这种方式将下载好的应用安

装到Splunk中

3.创建应用:如果你是splunk第三方开发或是有自己的使用系统,可以通过这个选

型创建自己的应用

在此页中,我们可以控制“应用”的状态,可以通过web界面“启用”或“禁用”应用,并且配置应用的某些属性。

实例:Splunk Unix本地性能监视应用

可以在“联机查找更多应用”中

文件名为“unix.tar.gz”。在/splunk目录下的app下可以通过“从文件安装应用”来安装它。

点击“应用管理界面”页里的“从文件安装应用”,进入“上载应用”页。

splunk服务重启完成后,会要求你在浏览器中重新登陆。

登陆后在右上角的“应用”下拉菜单中,我们会发现一个新的应用“*NIX4.6”,点击“*NIX4.6”,进入“SplunkFor Unix and Linux”应用。由于是第一次进入,我们需要去设置这个应用:

安装完后提示你重启服务的-----〉Configure进入配置页面

-----------打开监控项目Enable打开所需的检测------save保存------过一会就会搜集完数据图表慢慢变化

实例:SplunkUnix异地性能监视应用

通过配置其他主机的splunk转发到服务器上汇总

在客户端同上安装Splunk_TA_nix.tar.gz

安装:下面都是在客户端操作的

#echo $SPLUNK_HOME

/opt/splunkforwarder

#tar xvzf Splunk_TA_nix.tar.gz -C $SPLUNK_HOME/etc/apps

#chown splunk.splunk $SPLUNK_HOME/etc/apps/Splunk_TA_nix –R

配置:

#mkdir $SPLUNK_HOME/etc/apps/Splunk_TA_nix/local

#cp $SPLUNK_HOME/etc/apps/Splunk_TA_nix/default/inputs.conf

$SPLUNK_HOME/etc/apps/Splunk_TA_nix/local

将inputs.conf文件从default目录下拷贝到local目录下,然后编辑inputs.conf文件。

将你需要转发的数据项disabled= 1改为disabled= 0。

你可以在末行:%s/1/0/g整体替换1到0

#Copyright (C) 2005-2011 Splunk Inc. All Rights Reserved.

[script://./bin/vmstat.sh]

interval= 60

sourcetype= vmstat

source= vmstat

index= os

disabled= 0

[script://./bin/iostat.sh]

interval= 60

sourcetype= iostat

source= iostat

index= os

disabled= 0

[script://./bin/ps.sh]

interval= 30

sourcetype= ps

source= ps

index= os

disabled= 0

[script://./bin/top.sh]

interval= 60

sourcetype= top

source= top

index= os

disabled= 0

[script://./bin/netstat.sh]

interval= 60

sourcetype= netstat

source= netstat

index= os

disabled= 0

[script://./bin/protocol.sh]

interval= 60

sourcetype= protocol

source= protocol

index= os

disabled= 0

[script://./bin/openPorts.sh]

interval= 300

sourcetype= openPorts

source= openPorts

index= os

disabled= 0

[script://./bin/time.sh]

interval= 21600

sourcetype= time

source= time

index= os

disabled= 1

[script://./bin/lsof.sh]

interval= 600

sourcetype= lsof

source= lsof

index= os

disabled= 0

[script://./bin/df.sh]

interval= 300

sourcetype= df

source= df

index= os

disabled= 0

#Shows current user sessions

[script://./bin/who.sh]

sourcetype= who

source= who

interval= 150

index= os

disabled= 1

#Lists users who could login (i.e., they are assigned a login shell)

[script://./bin/usersWithLoginPrivs.sh]

sourcetype= usersWithLoginPrivs

source= usersWithLoginPrivs

interval= 3600

index= os

disabled= 1

#Shows last login time for users who have ever logged in

[script://./bin/lastlog.sh]

sourcetype= lastlog

source= lastlog

interval= 300

index= os

disabled= 0

#Shows stats per link-level Etherner interface (simply, NIC)

[script://./bin/interfaces.sh]

sourcetype= interfaces

source= interfaces

interval= 60

index= os

disabled= 0

#Shows stats per CPU (useful for SMP machines)

[script://./bin/cpu.sh]

sourcetype= cpu

source= cpu

interval= 30

index= os

disabled= 0

#This script reads the auditd logs translated with ausearch

[script://./bin/rlog.sh]

sourcetype= auditd

source= auditd

interval= 60

index= os

disabled= 1

#Run package management tool collect installed packages

[script://./bin/package.sh]

sourcetype= package

source= package

interval= 3600

index= os

disabled= 0

[script://./bin/hardware.sh]

sourcetype= hardware

source= hardware

interval= 36000

index= os

disabled= 0

#splunk restart

如果你的配置一切正常,你会在http://192.168.0.116:8000上,“*NIX

4.6”应用页上看到“主机”部分新增服务器。

在“CPU by Host”标签页中,将看到两台主机cpu数据信息

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值