1、Splunk硬件需求
2督禽、Splunk架構(gòu)圖
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?? ??#這一行命令要完整敲出來(lái)r
To use the Splunk Webinterface, point your browser to:
? ?http://localhost.localdomain:8000
Complete documentation is athttp://docs.splunk.com/Documentation/Splunk
-------------------------------------------------------------------------
??/opt/splunk/bin/splunk start ??
? ? ?//首次啟動(dòng)會(huì)有許可協(xié)議,按q鹦马,再輸入y胧谈。
??/opt/splunk/bin/splunk enable boot-start
??? #Init script installed at/etc/init.d/splunk.
??? #Init script is configured to run atboot.
?/opt/splunk/bin/splunk help enable
?可以使用/etc/init.d/splunk管理splunk的啟停
?/etc/init.d/splunkstatus
?firefox http://172.16.254.239:8000
?首次訪問(wèn),會(huì)提示用戶名密碼admin/changeme
? ? ? ?登錄后试溯,設(shè)置新的密碼
??# vim/opt/splunk/etc/system/default/web.conf
??? httpport = 8000
splunk日志的導(dǎo)入
?數(shù)據(jù)源可以是本地的、遠(yuǎn)程的、Linux的键袱、Unix的燎窘、windows的、交換機(jī)的蹄咖、路由器的等等褐健。也可以是web服務(wù)器的,IIS服務(wù)器的澜汤、ftp服務(wù)器的等等蚜迅。
10、停止當(dāng)前服務(wù)器的防火墻俊抵,使得splunk 可以遠(yuǎn)程訪問(wèn)
systemctl stopfirewalld.service
啟動(dòng): systemctl start firewalld
查看狀態(tài): systemctl status firewalld?
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
在開機(jī)時(shí)禁用一個(gè)服務(wù):systemctl disable firewalld.service
CentOS7使用firewalld打開關(guān)閉防火墻與端口
1谁不、firewalld的基本使用
啟動(dòng):systemctl start firewalld
查看狀態(tài):systemctl status firewalld?
停止:systemctl disable firewalld
禁用:systemctl stop firewalld
2.systemctl是CentOS7的服務(wù)管理工具中主要的工具,它融合之前service和chkconfig的功能于一體徽诲。
啟動(dòng)一個(gè)服務(wù):systemctl startfirewalld.service
關(guān)閉一個(gè)服務(wù):systemctl stopfirewalld.service
重啟一個(gè)服務(wù):systemctl restartfirewalld.service
顯示一個(gè)服務(wù)的狀態(tài):systemctl statusfirewalld.service
在開機(jī)時(shí)啟用一個(gè)服務(wù):systemctl enablefirewalld.service
在開機(jī)時(shí)禁用一個(gè)服務(wù):systemctl disablefirewalld.service
查看服務(wù)是否開機(jī)啟動(dòng):systemctl is-enabled firewalld.service
查看已啟動(dòng)的服務(wù)列表:systemctl list-unit-files|grepenabled
查看啟動(dòng)失敗的服務(wù)列表:systemctl --failed
3.配置firewalld-cmd
查看版本:firewall-cmd --version
查看幫助:firewall-cmd --help
顯示狀態(tài):firewall-cmd --state
查看所有打開的端口:firewall-cmd --zone=public?--list-ports
更新防火墻規(guī)則: firewall-cmd --reload
查看區(qū)域信息:?firewall-cmd --get-active-zones
查看指定接口所屬區(qū)域:firewall-cmd --get-zone-of-interface=eth0
拒絕所有包:firewall-cmd--panic-on
取消拒絕狀態(tài):firewall-cmd --panic-off
查看是否拒絕:firewall-cmd --query-panic
那怎么開啟一個(gè)端口呢
添加
firewall-cmd?--zone=public?--add-port=80/tcp?--permanent ? ?(--permanent永久生效刹帕,沒有此參數(shù)重啟后失效)
重新載入
firewall-cmd?--reload
查看
firewall-cmd?--zone=?public?--query-port=80/tcp
刪除
firewall-cmd?--zone=?public?--remove-port=80/tcp?--permanent
一、向splunk中導(dǎo)入本地日志 ?messages
?添加數(shù)據(jù)——>syslog——>使用此 Splunk 服務(wù)器上的任何 syslog 文件或目錄——>服務(wù)器上文件的路徑 /var/log/messages ——>默認(rèn)——>默認(rèn) 繼續(xù)——>默認(rèn)谎替,保存
二偷溺、搜索想要的日志
?開始搜索——>輸入aborting
?搜其他host="localhost"
練習(xí):將secure日志導(dǎo)入到splunk中,并驗(yàn)證其搜索功能
三钱贯、向splunk導(dǎo)入遠(yuǎn)程日志
?環(huán)境:
splunkserver?:172.16.254.239
? ? ? remoteapache:172.16.254.200?web.up.com
?開始配置:
?注意:導(dǎo)入遠(yuǎn)程日志需要遠(yuǎn)程主機(jī)安裝通用轉(zhuǎn)發(fā)器(splunkforwarder)挫掏。
? ? 1、設(shè)置splunk服務(wù)器允許接收splunk轉(zhuǎn)發(fā)器發(fā)送來(lái)的數(shù)據(jù)
?管理器——>轉(zhuǎn)發(fā)和接收——>配置接收中“新增”——>9999(指定接收數(shù)據(jù)的端口)——> 保存
? ? 2秩命、在遠(yuǎn)程服務(wù)器上配置
?1)安裝splunkforwarder包
??? # rpm -ivh splunkforwarder-5.0.2-149561-linux-2.6-x86_64.rpm
?2)配置splunkforwarder轉(zhuǎn)發(fā)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轉(zhuǎn)發(fā)器服務(wù)
??? # /opt/splunkforwarder/bin/splunk restart
? ? 3尉共、驗(yàn)證結(jié)果
?如果在splunk服務(wù)器的web頁(yè)面能夠看到web.up.com的apache的日志,就成功了硫麻。
?簡(jiǎn)單搜索:
??? ?host="web.up.com"
??? ?host="web.up.com" error
??host="web.up.com" ?OR error ??//OR?或者
生成視圖
導(dǎo)入測(cè)試數(shù)據(jù)
將Sampledata.zip放到splunk服務(wù)器上
繼續(xù)瀏覽器操作
? ?管理器——>數(shù)據(jù)導(dǎo)入——>文件和目錄“新增”——>跳過(guò)預(yù)覽——>上載并索引文件 ——>保存
一爸邢、體驗(yàn)splunk強(qiáng)大的搜索功能
??sourcetype="access_combined_wcookie"
1、搜索源類型為access_combined_wcookie拿愧,并且IP為10.2.1.44的日志請(qǐng)求
?——81條
??sourcetype="access_combined_wcookie" 10.2.1.44
2杠河、進(jìn)一步搜索關(guān)于“purchase”的請(qǐng)求—— 63條
??sourcetype="access_combined_wcookie" 10.2.1.44 purchase
3、進(jìn)一步搜索http返回碼不是200的購(gòu)買請(qǐng)求
??sourcetype="access_combined_wcookie" 10.2.1.44 purchase NOT 200
4浇辜、進(jìn)一步搜索不是404錯(cuò)誤的請(qǐng)求
??sourcetype="access_combined_wcookie" 10.2.1.44 purchase NOT 200NOT 404
用關(guān)鍵字搜索
?搜索買花時(shí)間
??sourcetype="access_combined_wcookie" 10.2.1.44action=purchase category_id=flowers
|:前面的搜索結(jié)果作為后面的命令的輸入
? ?1券敌、搜索最熱賣的商品 ?使用命令top
? ??sourcetype="access_combined_wcookie" action=purchase | topcategory_id
? ?2、有多少名不同的顧客買了鮮花
? ? ?需要使用stats命令和dc函數(shù)實(shí)現(xiàn)
? ??sourcetype="access_combined_wcookie" action=purchasecategory_id=flowers | stats dc(clientip)
? ?3柳洋、每個(gè)顧客分別買了多少花待诅?
? ??sourcetype="access_combined_wcookie" action=purchasecategory_id=flowers | stats count by clientip
?需要使用stats命令和count函數(shù)并且使用by子句
? ?4、倒序顯示每個(gè)顧客購(gòu)買多少花熊镣?
? ? ?sourcetype="access_combined_wcookie"action=purchase category_id=flowers | stats count by clientip | sort -count
? ? ?sort-count:按照count字段倒序排序
? ? ?sortcount:按照正序排序
? ?5卑雁、給數(shù)據(jù)列起別名
? ??sourcetype="access_combined_wcookie" action=purchasecategory_id=flowers | stats count by clientip | sort count | rename clientip as"顧客", count as "購(gòu)花總數(shù)"
二募书、將搜索結(jié)果保存為儀表盤
? ? 1、創(chuàng)建一個(gè)空的儀表盤
?儀表板和視圖——>創(chuàng)建儀表板——>ID:001?名稱:每個(gè)顧客購(gòu)花總數(shù) ——> 創(chuàng)建
? ? 2测蹲、將搜索結(jié)果保存到儀表盤
??sourcetype="access_combined_wcookie" action=purchase category_id=flowers| stats count by clientip | sort -count | rename clientip as "顧客" , count as"購(gòu)花總數(shù)"
?搜索——>創(chuàng)建——>儀表板面板——>每個(gè)顧客購(gòu)花總數(shù)——>現(xiàn)有儀表板——>下拉列表中選擇需要的儀表板——> 默認(rèn)
三莹捡、在收集結(jié)果時(shí)動(dòng)態(tài)更新生成的圖表
?創(chuàng)建報(bào)表
? ? ?搜索:sourcetype="access_combined_wcookie"action=purchase category_id=flowers | stats count by clientip | sort -count
? ? ?創(chuàng)建——>報(bào)表
下載客戶端http://www.splunk.com/download/universalforwarder
你懂的。
Splunk服務(wù)器地址和端口扣甲,必須寫篮赢。
可以先不填,直接next琉挖。
直接下一步启泣。
選擇要上傳的數(shù)據(jù)類型。這個(gè)只需要logs即可示辈,右邊那些是snmp干的活寥茫。
點(diǎn)擊安裝。
完成顽耳。
運(yùn)行——cmd——回車不懂撞墻去坠敷。
cd {splunk安裝目錄}/bin/
?? ? ? ?splunk.exe add forward-server 192.168.180.200:9997
用戶名 admin ?
密碼 changeme
注:9997端口需要在splunk服務(wù)器上先設(shè)置好。
具體配置如下圖:
重啟splunk服務(wù)
檢查設(shè)置splunk forwarder設(shè)置
Splunk.exe list forward-server
客戶端計(jì)算機(jī)名稱
使用查詢功能射富。
搞定!粥帚!
1)胰耗、將通用轉(zhuǎn)發(fā)器解壓到opt目錄下,Splunk轉(zhuǎn)發(fā)器的安裝方法和splunk一致芒涡,但它無(wú)UI界面柴灯。
tar zxvfsplunkforwarder-************-Linux-x86_64.tgz -C /opt
2)、切換到Splunkforwarder的bin目錄下去啟動(dòng)通用轉(zhuǎn)發(fā)器
cd/opt/splunkforwarder/bin/ ??#//切換到通用轉(zhuǎn)發(fā)器的可執(zhí)行程序目錄
./splunkstart?–accept-license ???#//啟動(dòng)通用轉(zhuǎn)發(fā)器一次啟動(dòng)有很長(zhǎng)的 協(xié)議 使用回車鍵轉(zhuǎn)到最后按”y” 同意在回車费尽。
注意:如果splunk web和通用轉(zhuǎn)發(fā)器安裝在同一 服務(wù)器赠群,通用轉(zhuǎn)發(fā)器的管理端口也是8090,則會(huì)提示被splunk占用
3配置轉(zhuǎn)發(fā)器需要轉(zhuǎn)發(fā)的服務(wù)器ip和端口
./splunk addforward-server 192.168.180.200:9997
用戶名 admin ?
密碼 changeme
注:9997端口需要在splunk服務(wù)器上先設(shè)置好監(jiān)聽端口旱幼。
4.設(shè)置開機(jī)自啟動(dòng)
/opt/splunkforwarder/bin/splunkenable boot-start
5.檢查設(shè)置splunk forwarder設(shè)置
./Splunklist forward-server