ELK官網(wǎng):?https://www.elastic.co/
**安裝要求:
1.java1.8以上版本
2.?elasticsearch ,?logstash,?kibana要安裝同一個(gè)版本號(hào)
1. 搭建ELK服務(wù)器
1.1?要先刪除1.7版的JAVA包扯旷,并安裝1.8版缓溅。參考以下網(wǎng)址完成姥饰。
http://blog.csdn.net/yony2011/article/details/50313223
1.2?客戶端需要安裝一個(gè)插件filebeat闷尿,直接解壓即可使用线椰。
1.3?cd /usr/local/filebeat/ 修改里面的yml文件岗钩。
- input_type: log ? # Paths that should be crawled and fetched. Glob based paths. ? paths: ? ? #- /var/log/*.log ?? ? - /yoururl/weixin_access.log
output.logstash: ? # The Logstash hosts ? # hosts: ["localhost:5044"] ? hosts: ["logstaship:5044"] ? index: pro_weixin_accesslog
啟動(dòng)命令
nohup /usr/local/filebeat/filebeat -e -c /usr/local/filebeat/filebeat-accesslog.yml -d "publish" > /dev/null 2>&1 &
1.4 服務(wù)器端安裝logstash直接解壓即可使用, 在?/usr/local/logstash/bin內(nèi)新建logstash-access.conf纽窟。以下filter處是用正則拆分日志內(nèi)容〖嫦牛可在http://grokdebug.herokuapp.com上面做拆分正則腳本調(diào)試臂港。
filter { ? grok { ?? ? ? match => { "message" => "%{IP:client} \| - \| \[%{HTTPDATE:logdate}\] \| \"%{WORD:method} %{URIPATHPARAM:request_url} %{WORD:method1}/%{NUMBER:nil}\" \| %{NUMBER:status} \| %{NUMBER:bytes} \|%{xsx:unknown}\| \"%{xyh:userinfo}" } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
啟動(dòng)命令
nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/bin/logstash-access.conf > /dev/null 2>&1 &
1.5 服務(wù)器端安裝elasticsearch和kibana,也是直接解壓可用视搏。啟動(dòng)命令如下:
su elasticsearch
nohup /usr/local/elasticsearch/bin/elasticsearch? > /dev/null 2>&1&
nohup /usr/local/kibana/bin/kibana > /dev/null 2>&1&
2.設(shè)置自動(dòng)備份和清理備份
2.1?配置文件必須添加如下參數(shù)
path.repo: ?/mnt/backups/es_mybak
2.2 ?創(chuàng)建備份倉(cāng)庫es_mybak审孽,授777權(quán)限,或者轉(zhuǎn)給用戶ELK
2.3 備份命令
2.3.1.創(chuàng)建備份倉(cāng)庫
curl -u elasticaccount:password -XPUT 'localhost:9200/_snapshot/EsBackup' -d '{"type":"fs","settings": {"location":"/data/backups/es_mybak"}}'
2.3.2.查詢備份倉(cāng)庫
curl -u elasticaccount:password -XGET 'localhost:9200/_snapshot?pretty'
2.3.3.備份部分索引
curl -u elasticaccount:password -XPUT 'localhost:9200/_snapshot/EsBackup/snapshot_pro_weixin_accesslog-2017.06.18' -d '{"indices":"pro_weixin_accesslog-2017.06.18"}'
2.3.4.查看備份快照
curl -u elasticaccount:password -XGET 'localhost:9200/_snapshot/EsBackup/snapshot_*?pretty'
curl -u elasticaccount:password -XGET 'localhost:9200/_snapshot/EsBackup/snapshot_pro_weixin_accesslog-2017.06.18?pretty'
2.3.5.刪除索引
curl -u elasticaccount:password -XDELETE 'localhost:9200/pro_weixin_accesslog-2017.06.18?pretty'
2.3.6.根據(jù)快照恢復(fù)索引
curl -u elasticaccount:password -XPOST 'localhost:9200/_snapshot/EsBackup/snapshot_pro_weixin_accesslog-2017.06.18/_restore'
2.3.7.刪除快照
curl -u elasticaccount:password -XDELETE 'localhost:9200/_snapshot/EsBackup/snapshot_pro_weixin_accesslog-2017.06.18'
2.4 使用上述命令做成SHELL腳本浑娜,再結(jié)合JENKINS定時(shí)構(gòu)建佑力。