1. 程式人生 > >elasticsearch搜尋引擎資訊採集簡單使用

elasticsearch搜尋引擎資訊採集簡單使用

1.elasticsearch安裝,叢集部署

Logstash 是開源的伺服器端資料處理管道,能夠同時從多個來源採集資料,轉換資料,然後將資料傳送到您最喜歡的 “儲存庫” 中。(我們的儲存庫當然是 Elasticsearch。)

 yum install elasticsearch-2.3.3.rpm
 rpm -ivh jdk-8u121-linux-x64.rpm
 vim /etc/elasticsearch/elasticsearch.yml #編輯配置檔案
 cluster.name: my-es #叢集名稱
 node.name: server1 #節點名稱
 path.data
: /var/lib/elasticsearch/#資料儲存路徑 path.logs: /var/log/elasticsearch/ #日誌位置 network.host: 172.25.30.1#網路ip http.port: 9200 #訪問埠9200 bootstrap.mlockall: true #允許記憶體鎖定 discovery.zen.ping.unicast.hosts: ["server1", "server2", "server3"]#編輯叢集節點域名注意解析



/etc/init.d/elasticsearch start
cd /usr/share/elasticsearch/bin/
cd elk/
 /usr/share
/elasticsearch/bin/plugin install file:/root/elk/elasticsearch-head-master.zip #本地路徑安裝外掛 /usr/share/elasticsearch/bin/plugin list #列出支援外掛





新增叢集:節點都要安裝elasticsearch jdk-8u121-linux-x64.rpm
配置節點只需修改node.name,network hosts;
vim /etc/elasticsearch/elasticsearch.yml

/etc/init.d/elasticsearch reload
叢集節點服務配置
vim /etc/elasticsearch/elasticsearch.yml
node.master: true #master
node.data: false #
httpd.enabled: false #
Master配置:


/etc/init.d/elasticsearch reload
其他節點:角色一樣開啟服務配置也相同


[[email protected] elasticsearch]# curl -XDELETE ‘http://172.25.30.1:9200/index’ {“acknowledged”:true}

/opt/logstash/bin/logstash -e ‘input { stdin{ }} output {stdout {}}’
你輸入什麼我輸出什麼

/opt/logstash/bin/logstash -e ‘input { stdin{ }} output { stdout { codec => rubydebug } }’

在某個節點搜尋輸出 根據時間來定位
/opt/logstash/bin/logstash -e ‘input { stdin{ }} output { elasticsearch { hosts => [“172.25.30.1”] index => “logstash-%{+YYYY.MM.dd}”} stdout {codec => rubydebug} }’


我們發現這樣在終端輸入命令不是很方便我們可以把他的輸出格式寫在配置檔案然後在後端執行
cd /etc/logstash/conf.d/
vim es.conf #配置檔案只要以conf.d結尾然後指定就可以被讀到

input {
stdin {}
}

output {
elasticsearch {
hosts => [“172.25.30.1”]
index => “logstash-%{+YYYY.MM.dd}”
}
stdout {
codec => rubydebug
}
}

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/es.conf


vim es.conf #將資訊記錄在指定檔案裡面:
input {
stdin {}
}

output {
elasticsearch {
hosts => [“172.25.30.1”]
index => “logstash-%{+YYYY.MM.dd}”
}

stdout {
    codec => rubydebug

}
file {
    path => "/tmp/testfile"
    codec => line {format => "custom format: %{message}"}
}

}

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/es.conf

檔案記錄到日誌檔案中:

vim message.conf
input {
file {
path => “/var/log/messages”
start_position => “beginning”
}

}
output {
elasticsearch {

    hosts => ["172.25.30.1"]
    index => "message-%{+YYYY.MM.dd}"
}
stdout {
    codec => rubydebug
}

}

[[email protected] conf.d]# /opt/logstash/bin/logstash -f /etc/logstash/conf.d/message.conf
在後臺執行重新連線一個終端:
寫入輸入:
[[email protected] ~]# logger test ^10
[[email protected] ~]# cat /var/log/messages



開啟514埠同步server2的日至

當sincedb發生改變server1的後臺執行才會有資料


[[email protected] ~]# vim /etc/rsyslog.conf

. @@172.25.30.1 #通過tcp協議傳輸日誌給172.25.30.1

[[email protected] ~]# /etc/init.d/rsyslog restart
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
[[email protected] ~]# logger server2 #在server2上面寫入資訊到日誌中會被同步到server1

vim message.coinput {
        file {
                path => "/var/log/elasticsearch/my-es.log"
        start_position => "beginning"
}

}

filter { #input模組--->filter---->多行過濾向上匹配

  multiline {
#type => "type"
pattern => "^\["
negate => true
what => "previous"
}
}

output {
elasticsearch {

hosts => ["172.25.30.1"]
index => "es-%{+YYYY.MM.dd}"
}
stdout {
codec => rubydebug
}
}

opt/logstash/bin/logstash -f /etc/logstash/conf.d/message.conf #制定資料輸出以message.conf檔案格式輸出:



採集apche的日誌登陸資訊:

vim message.conf 
input {
        file {
        path => ["/var/log/httpd/access_log","/var/log/httpd/error_log"]
            start_position => "beginning"
    }

}

#filter {
#  multiline {
##  type => "type"
#   pattern => "^\["
#   negate => true
#   what => "previous"
#   }
#}

output {
    elasticsearch {

        hosts => ["172.25.30.1"]
        index => "apache-%{+YYYY.MM.dd}"
    }
    stdout {
        codec => rubydebug
    }


}


分層採集:

input {
    stdin {}
    }

filter {
  grok { #採集資訊輸出格式
    match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" }
    }
}

output {
    stdout {
        codec => rubydebug
    }
}


Apche的資料沒有改變啟動採集資訊就採集不到我們找到匹配的資訊之後需要先將sincedb刪除才可以訪問

[root@server1 conf.d]# ls -i /var/log/httpd/access_log #檢視那檔案節點
266527 /var/log/httpd/access_log
[root@server1 conf.d]# ls -i /var/log/httpd/error_log 
266525 /var/log/httpd/error_log
[root@server1 conf.d]# cd 
[root@server1 ~]# cat .sincedb_
.sincedb_452905a167cf4509fd08acb964fdb20c
.sincedb_d5a86a03368aaadc80f9eeaddba3a9f5
.sincedb_ef0edb00900aaa8dcb520b280cb2fb7d
[root@server1 ~]# cat .sincedb_ef0edb00900aaa8dcb520b280cb2fb7d
266527 0 64768 462
266525 0 64768 544
[root@server1 ~]# rm -f .sincedb_ef0edb00900aaa8dcb520b280cb2fb7d



安裝kibana:
Kibana是一個開源的分析與視覺化平臺,設計出來用於和Elasticsearch一起使用的。你可以用kibana搜尋、檢視、互動存放在Elasticsearch索引裡的資料,使用各種不同的圖表、表格、地圖等kibana能夠很輕易地展示高階資料分析與視覺化。
Kibana讓我們理解大量資料變得很容易。它簡單、基於瀏覽器的介面使你能快速建立和分享實時展現Elasticsearch查詢變化的動態儀表盤。安裝Kibana非常快,你可以在幾分鐘之內安裝和開始探索你的Elasticsearch索引資料—-—-不需要寫任何程式碼,沒有其他基礎軟體依賴。

[root@server3 ~]# rpm -ivh kibana-4.5.1-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:kibana                 ########################################### [100%]
[root@server3 ~]# vim /opt/kibana/config/kibana.yml 
[root@server3 ~]# /etc/init.d/kibana start
kibana started
[root@server3 ~]# netstat -antlp | grep :5601
tcp        0      0 0.0.0.0:5601                0.0.0.0:*                   LISTEN      2324/node        


進行訪問測試kibana上是否顯示訪問資訊:
[[email protected] ~]$ ab -c 1 -n 10 http://172.25.30.1/index.html
vim /etc/logstash/conf.d/nginx.conf
input {
file {
path => “/var/log/nginx/access.log”
start_position => “beginning”
}
}

filter {
grok {
match => { “message” => “%{COMBINEDAPACHELOG} %{QS:x_forwarded_for}” }
}
}

output {
redis {
host => [“172.25.30.2”] #訪問host其實是redis
port => 6379
data_type => “list”
key => “logstash:redis”
}
stdout {
codec => rubydebug
}
}
scp es.conf server2:/etc/logstash/conf.d/
Server2:redis—->節藕

 tar zxf redis-3.0.6.tar.gz 
 cd redis-3.0.6
 yum install gcc y
 make
 make install
 cd utils/
 ./install_server.sh 
  netstat -antlp | grep 6379
cd /etc/logstash/conf.d/
vim es.conf 
~~~~
input {
    redis{
        host => "172.25.30.2"
        port => 6379
        data_type => "list"
        key => "logstash:redis"

    }
}
output {
    elasticsearch {
        hosts => ["172.25.30.1"]
        index => "nginx-%{+YYYY.MM.dd}"

    }   
}

/etc/init.d/logstash start

Visualiza:
最終我們結合kibana將資料呈現在大螢幕上,彙總分析,該web 伺服器的訪問量,訪問排行榜以及負責人資訊。
1 .nginx客戶訪問排行榜 Vertical bar chart X-bar表示客戶端 ip,Y-bar表示client訪問次數
聯絡人 Markdown weight

3.訪問量 Data table
4.新增到 nginxDashboard

相關推薦

elasticsearch搜尋引擎資訊採集簡單使用

1.elasticsearch安裝,叢集部署 Logstash 是開源的伺服器端資料處理管道,能夠同時從多個來源採集資料,轉換資料,然後將資料傳送到您最喜歡的 “儲存庫” 中。(我們的儲存庫當然是 Elasticsearch。) yum install

Java中使用elasticsearch搜尋引擎實現簡單、修改等操作

以下的操作環境為:jdk:1.8;elasticsearch:5.2.0 maven架包下載座標為: <dependency> <groupId>org.elasticsearch.plugin</groupId> <artifactId&g

ElasticSearch搜尋引擎在JAVA中的簡單使用

Elasticsearch常用操作和核心原理見文章:https://blog.csdn.net/sdksdk0/article/details/78469190 本文參照:https://www.2cto.com/kf/201802/719374.html 一、引入ElasticSear

基於django框架編寫的簡單資訊採集系統

新學期開學,又要統計學生資訊。如果每個人都填寫一個Excel的話,最後做彙總工作的那個人一定神煩。所以基於django編了一個小網頁,用於採集學生的基本資訊。剛學會做網頁,也是第一次用django,寫的不好,望見諒。主要參考了菜鳥教程的django系列教程,很簡

Elasticsearch集群的簡單搭建

elasticsearch環境說明:服務器(系統版本 centos7)elasticsearch版本: elasticsearch-6.2.2 elasticsearch目錄: /home/soft/ 192.168.33.10 master 192.168.33.11 ma

Elasticsearch就這麽簡單

操作 last move sele id屬性 tab pad 事情 objectc 一、前言 最近有點想弄一個站內搜索的功能,之前學過了Lucene,後來又聽過Solr這個名詞。接著在了解全文搜索的時候就發現了Elasticsearch這個,他也是以Lucene為基礎的。

ES(elasticsearch)搜尋引擎使用(一)

版權宣告:本文為博主原創文章,未經博主允許不得轉載。轉載請務必加上原作者:銘毅天下,原文地址:blog.csdn.net/laoyang360 https://blog.csdn.net/wojiushiwo987/article/details/52244917   API連結:

Elasticsearch+logstash+kibana ELK簡單案例模擬

1 下載json資料包   使用kibana完成資料分析 官網資料文件地址 https://www.elastic.co/guide/en/kibana/current/tutorial-load-dataset.html 2 下載官網上的資料包(下載的是第一個也可以

Elasticsearch 與Springboot 的簡單連線

1、主要Elasticsearch 包: 2、application.properties 配置   3、 Elasticsearch  java 程式碼 package com.allen.elasticsearch; import jav

Elasticsearch搜尋引擎第十二篇-聚合分析

文章目錄 聚合分析簡介 指標聚合 max min sum avg 文件計數 佔比百分位對應的值統計 統計值小於等於指定值的文件佔比 求文件幾種的座標點範圍 求中心點座標值 桶聚合

Elasticsearch搜尋引擎第十一篇-Suggest查詢建議

文章目錄 查詢建議是什麼 ES查詢建議API Suggester介紹 term suggester phrase suggester completion suggester 自動補全 查詢建議是什麼

移動互聯時代的移動端證件識別OCR,資訊採集新幫手

隨著網際網路時代的發展,很多APP都需要個人身份證資訊的輸入認證(即實名認證),在移動端證件識別研發出來之前需要手動去輸入身份證號碼和姓名,速度非常慢,且使用者體驗非常差。為了提高在移動終端上輸入身份證資訊的速度和準確性,我們開發出離線身份證ocr識別SDK開發包,以滿足各行業將證件識別功能嵌入到APP中,通

使用haystack實現Django的全文搜尋 -- Elasticsearch搜尋引擎

全文搜尋: 在使用python進行web開發的時候,免不了需要使用到全文搜尋;全文搜尋和我們平常使用的資料庫的模糊搜尋查詢不一樣,例如在mysql資料庫中,如果進行模糊查詢,比如 name like '%wang%'這一類的,效率是非常低的;而我們需求的全文搜尋,在效率方面要求是很高

Elasticsearch搜尋引擎第十四篇-Java客戶端呼叫

文章目錄 ES支援多種程式語言客戶端 ES 提供的客戶端連線方式 Java REST Client Java Low Level REST Client Java High Level REST Client(常用) J

Elasticsearch搜尋引擎第十三篇-叢集如何規劃

文章目錄 我們需要多大規模的叢集 叢集中的節點角色如何分配 如何避免腦裂問題 索引應該設定多少個分片 分片應該設定幾個副本 我們需要多大規模的叢集 在使用ES初始階段,我們應該需要多大規模的ES叢集呢?主要從以下兩個問題入手

elasticsearch搜尋引擎安裝部署

實驗環境:redhat6.5 server1 172.25.35.1 redhat6.5 server1 172.25.35.2redhat6.5 server1 172.25.35.3準備安裝包;[[email protected] elk]# lsbigdesk-master.zip jemal

ElasticSearch搜尋引擎API筆記

                                          &nb

Python 運維自動化之伺服器資訊採集

主要是採集伺服器的CPU,記憶體,硬碟,網路等資訊。 用到的主要模組psutil還有subprocess,要注意管道問題(subprocess.popen函式的引數注意使用)。 上程式碼 1 def test2(): 2 fnull = open(os.devnull, 'w')

京東商城雙十一光棍節商品資訊採集教程

本文主要介紹“京東商品資訊採集爬蟲”(以下簡稱“京東爬蟲”)的使用教程及注意事項。 一年一度的光棍節就要到了,這個雙十一準備好趁手的採集工具沒呀?雖然市面上的採集工具種類繁多,但能夠採集京東商品的工具確實不多,而且對於像京東這類國內主流電商平臺,又該如何通過採集工具收集競品店鋪的商品價格

新浪微博資訊採集釋出教程

本文主要介紹“新浪微博採集爬蟲”(以下簡稱“微博爬蟲”)的使用教程以及注意事項。 新浪微博中有大量高價值的軟文資料,應用價值很高,接下來,給你詳細說明用“微博爬蟲”採集並匯出資料的步驟: 步驟1 設定爬蟲 進入“微博爬蟲”總覽頁,點選“應用設定”,您可以選擇“檔案託管”服務託管圖