Rsyslog+ELK日誌分析系統搭建總結1.0(測試環境)

  由於工做需求,最近在搭建日誌分析系統,這裏主要搭建的是系統日誌分析系統,即rsyslog+elk。linux

  由於目前仍爲測試環境,這裏說一下搭建的基礎架構,後期上生產線再來更新最後的架構圖,大佬們若是有什麼看法歡迎指導。git

這裏主要總結一下搭建過程。github

一.rsyslog

  rsyslog是現在大多數linux自帶的日誌收集,這裏主要說一下rsyslog的簡單配置。npm

  client端配置它只須要更改準備發送的日誌以及在末尾加上Server端使用的協議和IP便可,例如:json

#加入如下便可
*.* @10.144.100.32:514

二.logstash配置

  logstash只須要將rsyslog收集起來並轉發至elasticsearch便可,配置以下:vim

vi /etc/logstash.conf
input{
    syslog{
        type => "system-syslog"
        port => 514
    host => "10.144.100.32"
    }
}

filter {
    date {
        match => [ "timestamp", "yyyy-MM-dd-HH:mm:ss" ]
        locale => "cn"
  }

}

output{
 elasticsearch {
        hosts => ["10.24.180.19:9200"]
    user => "elastic"
    password=> "123456"
        index => "blockchain-%{type}-%{+YYYY.MM.dd}"
    codec => "json"
    }
stdout { codec => json }
}
cd logstash-5.5.1/bin/
./logstash -f /etc/logstash.conf

三.Elasticsearch搭建

   elasticsearch搭建起來比較簡單,直接在https://www.elastic.co/downloads/elasticsearch下載elasticsearch壓縮包,解壓下來。  瀏覽器

cd elasticsearch-5.5.1/bin/
./elasticsearch &

  本地瀏覽器訪問http://localhost:9200安全

  注意:安裝elasticsearch儘可能先改一下內核參數和資源參數,我在阿里雲上搭建的,默認的內核參數和資源參數可能會致使啓動失敗。restful

vim /etc/sysctl.conf
#修改或添加如下參數
fs.file-max=65536
vm.max_map_count = 262144

vim /etc/security/limits.conf
#修改或添加如下參數
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

  elasticsearch有幾個比較推薦的插件,這裏介紹一下head插件安裝,並經過head插件介紹一下elasticsrach的一些基本概念。架構

  首先介紹一下head的安裝,ES5.0以前head插件是直接能夠經過elasticsearch-plugin install安裝,5.0以後不能夠直接插件安裝,但依然是能夠安裝使用的。

  這裏簡單介紹下安裝過程。

  首先,設置下ES同源訪問策略:

vim elasticsearch-5.5.0/conf/elasticsearch.yml
#在末尾添加以下內容:
http.cors.enabled: true
http.cors.allow-origin: "*"

  而後,經過npm進行安裝:

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start

  固然,elasticsearch若是直接暴露在外網上是很是危險的,這裏安裝一款x-pack插件,可將此端口設置帳戶密碼。

cd elasticsearch-5.5.0/bin/
./ealsticseearch-plugin intsall x-pack

  安裝完x-pack後,直接訪問9200端口會提示輸入帳號和密碼,這增長了elasticsearch的一些安全性,默認的帳號密碼是elastic:changeme,更改帳號密碼課經過調用restful

API

curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/elastic/_password' -d '{
  "password" : "elastic"
}'

四.Kibana搭建

  kibana是配合Elasticsearch一塊兒使用的可視化分析平臺,說白了就是更形象的表示Elasticsearch的結果。

vim kibana/config/kibana.yml
server.port: 5601
server.host: 0.0.0.0
elasticsearch.url: "http://localhost:9200"
elasticsearch.username: "elastic"
elasticsearch.password: "changeme"

  本地瀏覽器輸入localhost:5601便可

相關文章
相關標籤/搜索