版本說明:
Elasticsearch 5.0
Logstash 5.0(暫時未用)
Filebeat 5.0
Kibana 5.0
ELK是一套採集日誌並進行清洗分析的系統,由於目前的分析的需求較弱,所以僅僅採用filebeat做日誌採集,沒有使用logstash
一、環境準備&&軟件安裝:
1、首先,需要安裝Java環境
下載安裝包:jre-8u111-linux-x64.rpm
安裝:yum install jre-8u111-linux-x64.rpm
2、 新建一個用戶,elsearch,用來啓動elasticsearch,因爲該軟件必須用普通用戶啓動。
useradd elsearch
3、修改變量參數:否則啓動elasticsearch會報bootstrap錯誤。
1、ulimit -u 10240 #
2、vim /etc/sysctl.conf
vm.max_map_count = 655360 sysctl -p
3、vim /etc/security/limits.conf
* soft noproc 65536 * hard noproc 65536 * soft nofile 65536 * hard nofile 65536
4、軟件安裝
安裝包下載地址:https://www.elastic.co/downloads
使用的是綠色安裝包,解壓即用。
1、filebeat安裝
tar -xvf filebeat-5.0.0-linux-x86_64.tar.gz cp filebeat-5.0.0-linux-x86_64 /usr/local/filebeat -r
2、kibana安裝
tar -xvf kibana-5.0.0-linux-x86_64.tar.gz cp kibana-5.0.0-linux-x86_64 /usr/local/kibana -r
3、logstash安裝(暫時未用)
tar -xvf logstash-5.0.0.tar.gz cp logstash-5.0.0 /usr/local/logstash -r
4、elasticsearch安裝
unzip elasticsearch-5.0.0.zip cp elasticsearch-5.0.0 /usr/local/elasticsearch -r
二、配置&&啓動
1、啓動elasticsearch
cd /usr/local/ chown -R elsearch:elsearch elasticsearch 將權限給elsearch用戶 su elsearch cd /usr/local/elasticsearch
修改配置文件如下:
cat config/elasticsearch.yml |grep -v "#"
path.data: /usr/local/elasticsearch/data path.logs: /usr/local/elasticsearch/logs network.host: 192.168.221.30 http.port: 9200
啓動:
cd /usr/local/elasticsearch/bin ./elasticsearch #使用-d參數,放到後臺執行
查看啓動情況:
[root@localhost elasticsearch]# lsof -i:9200
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 29987 elsearch 237u IPv6 470519 0t0 TCP 192.168.221.30:wap-wsp
在瀏覽器中查看:
輸入:192.168.221.30:9200
能看到類似信息則啓動成功:
{ "name" : "FrmZoqD", "cluster_name" : "elasticsearch", "cluster_uuid" : "IcATEXFBQkGsZdh4P_TiTw", "version" : { "number" : "5.0.0", "build_hash" : "253032b", "build_date" : "2016-10-26T04:37:51.531Z", "build_snapshot" : false, "lucene_version" : "6.2.0" }, "tagline" : "You Know, for Search" }
注意本機防火牆要關掉。
2、配置&&啓動filebeat
修改配置文件:
cd /usr/local/filebeat
cp filebeat.yml filebeat.yml.default
vim filebeat.yml filebeat.prospectors: - input_type: log paths: - /var/log/messages document_type: "messages" output.elasticsearch: hosts: ["192.168.221.30:9200"] #filebeat傳到Elasticsearch index: filebeat-%{+yyyy.MM.dd} #這裏的索引index會跟kibana的索引有關係
touch /var/log/test.log #測試日誌文件
啓動:
./filebeat -e -c filebeat.yml -d "publish"
測試
輸入一條語句進行測試
echo "hello,test" >test.log
能看到beat已經將輸入的log採集到了。
將filebeat放入後臺執行:
nohup ./filebeat -e -c filebeat.yml >>/dev/null 2>&1 &
3、配置&&啓動kibana
修改配置:
cd /usr/local/kibana
vim config/kibana.yml
server.port: 5601 server.host: "27.131.221.30" elasticsearch.url: "http://27.131.221.30:9200"
修改以上三項。
啓動動服務:
cd /usr/local/kibana/bin/ ./kibana
如果都配置正確的話,會進入到kibana的頁面,剛開始會讓你配置一個index索引
這條索引跟我們上面filebeat裏面配置的索引有關。
filebeat-*
*就是時間格式,我們是按照時間來進行索引的。
如果是用logstash進行採集數據的話,那麼索引就是logstash-*
當然,我們也可以配置多條索引,例如我們同時用filebeat和logstash進行採集不同的業務日誌。
最終的形式應該是這樣的: