天天看點

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.可以忽略這句話

[[email protected]~]# 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

[[email protected] ~]#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,配置本地需要轉發的日志檔案和日志檔案類型:

[[email protected]]# 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資料資訊