ELK-「線上標準文檔」——測試

Elasticstack官網:https://www.elastic.co
本文檔僅限搭建過程參考,使用相關的文檔,不在本文檔討論範圍以內。
一切依據的核心便是Elasticstack官網。

查看支持的操做系統:
Elasticstack各版本軟件支持的系統等:https://www.elastic.co/support/matrix#show_os
必備軟件:
Elasticsearch:elasticsearch-5.3.0.tar.gz
Logstash:logstash-5.3.0.tar.gz
Kibana:kibana-5.3.0-linux-x86_64.tar.gz
Beats:filebeat-5.3.0-linux-x86_64.tar.gz
X-pack:x-pack-5.3.0.zip
jdk1.8:jdk-8u121-linux-i586.tar
搭建流程:
Elasticsearch:
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
修改時區(如必要):
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
安裝JDK1.8,先安裝yum install -y glibc.i686
root權限下
sysctl -w vm.max_map_count=262144
/etc/security/limits.conf 增長 
* soft nproc 2048 (第一列爲Linux帳戶名)
* hard nproc 4096(第一列爲Linux帳戶)
* soft nofile 65536
* hard nofile 131072
/etc/security/limits.d/90-nproc.conf 修改
* soft nproc 2048
sudo sysctl -p
生產環境須要的配置
Elasticsearch經過name判斷所屬的集羣
  ● path.data and path.logs
      ○ 不要和安裝目錄放一塊兒,防止升級的時候數據丟失
      ○ 能夠配置多個目錄
  ● cluster.name
      ○ 各節點經過cluster.name加入集羣
  ● node.name
      ○ 保證重啓機器名稱不變
      ○ 能夠設置成機器名例如node.name:${HOSTNAME}
  ● bootstrap.memory_lock
      ○ bootstrap.memory_lock: true(遇到問題,見博客園博客)
      ○ /etc/sysctl.conf 增長vm.swappiness=0
  ● network.host
      ○ 一旦配置標誌進入生產環境
  ● discovery.zen.ping.unicast.hosts
      ○ 自動入集羣
  ● discovery.zen.minimum_master_nodes
      ○ 避免腦裂
生產環境須要設置bootstrap.memory_lock: true
節點以下配置,承擔的角色爲負載均衡
node.master: false
node.data: false
node.ingest: false
配置文件elasticsearch.yml參考:
cluster.name: rokid-test
node.name: node-41
node.master: true
node.data: true 
path.data: /home/zhangzhenghai/elk/data/elasticsearch/data
path.logs: /home/zhangzhenghai/elk/data/elasticsearch/logs
bootstrap.memory_lock: true 
bootstrap.system_call_filter: false 
network.host: test41
http.port: 9200
discovery.zen.ping.unicast.hosts:
    - test41
    - test42
    - test43
discovery.zen.minimum_master_nodes: 2 
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
啓動方式:bin/elasticsearch -d -p pid 
中止方式:kill `cat pid`
重啓方式:kill `cat pid`
    bin/elasticsearch -d -p pid 
Logstash:
參考https://www.elastic.co/guide/en/logstash/current/index.html
grok正則表達式參考:https://grokdebug.herokuapp.com/
配置文件:
input {
    beats {
        port => "5043"
    }
}
filter {
    grok {
        match => {
            "message" => "%{HOSTNAME:hostabc} %{DAY:zhouji} %{WORD:month} %{MONTHDAY:jihao} %{TIME:shijian} %{TZ:biaozhun} %{YEAR:nian} %{TIMESTAMP_ISO8601:shijianquan} \[%{WORD:zhonglei}\] %{WORD:caozuo} %{NOTSPACE:info}"
        }
    }
}
output {
    file {
        codec => line {format => "%{message}"}
        path => "/home/zhangzhenghai/elk/data/logstash/%{hostabc}.log"
    }
    elasticsearch {
        hosts => ["test41:9200","test42:9200","test43:9200"]
        index => "%{hostabc}"
        document_type => "%{hostabc}"
        flush_size => 100
        idle_flush_time => 10
        user => "elastic"
        password => "baoshan"
    }
}
上面的正則表達式對應的原始日誌參考:
test-41.dev.rokid-inc.com Tue Apr 25 14:54:36 CST 2017 2017-04-16 23:37:44,282 [DEBUG] add service:com.rokid.open.nlp.facade.NLPService
啓動方式(自動加載配置文件,修改配置文件不用重啓Logstash):
bin/logstash -f config/firtst.conf --config.reload.automatic
Kibana:
配置文件參考:
server.port: 5601
server.host: "test43" 
elasticsearch.url: "http://test43:9200"
elasticsearch.preserveHost: true
kibana.index: ".kibana"
kibana.defaultAppId: "discover"
elasticsearch.username: "elastic"
elasticsearch.password: "xxx"
啓動方式:
bin/kibana
X-Pack
bin/elasticsearch-plugin install x-pack 或者線下安裝方式
bin/elasticsearch-plugin install file:///path/to/file/x-pack-5.3.1.zip
bin/kibana-plugin install file:///path/to/file/x-pack-5.3.1.zip
查看是否安裝成功:
bin/kibana-plugin list
bin/elasticsearch-plugin list
(如是elastic集羣,須要將全部節點安裝x-pack後重啓,默認用戶名密碼elastic/changeme才生效)
elasticsearch.yml配置以下信息
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
卸載x-pack
bin/elasticsearch-plugin remove x-pack
Beats(可直接寫入Elasticseatch):
filebeat-5.3.0-linux-x86_64.tar.gz
配置文件參考:
filebeat.prospectors:
- input_type: log
  paths:
    - /home/zhangzhenghai/elk/data/filebeat/testdate.log
  document_type: typetest42
output.elasticsearch:
  hosts: ["test41:9200","test42:9200","test43:9200"] 
  index: "indextest42"
  username: "elastic"
  password: "xxx"
output.logstash:
  hosts: ["test39:5043"]
啓動方式:
./filebeat -e -c filebeat.yml -d "publish"

可能短時間內將會部署到線上,隨着部署的進行,逐步更新完善本文檔。
(發現每當須要文檔的時候,常常嫌棄寫得少;當須要本身寫文檔的時候,總感受沒得寫?OMG)

 如更新忘記更新此文檔,請參考連接:html

http://note.youdao.com/noteshare?id=d9b4d5c0f5991c63c5b8ae965722f619node

相關文章
相關標籤/搜索