1. 程式人生 > >filebeat+redis+elk日誌平臺搭建

filebeat+redis+elk日誌平臺搭建

filebeat elk redis

filebeat+redis+elk
系統:centos7.1 x86_64
filebeat: 6.2.3
logstash: 6.2.3
elasticsearch: 6.2.3
kibana: 6.2.3
架構如下:
技術分享圖片
配置yum源:
導入驗證文件
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
創建yum repo文件:
cat /etc/yum.repos.d/elasticsearch-6x.repo

[elasticsearch-6.x]

name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
安裝軟件:
yum install filebeat logstash elasticsearch kibana -y
系統架構:
filebeat +redis+ logstash+ elasticsearch + kibana
使用beat的原因為logstash需要依賴java環境,對cpu和內存消耗都比較大,所以filebeat應運而生,對cpu和內存基本沒有消耗。
使用redis 的原因是當多個clinet同事寫入到logstash或者elasticsearch 時候,有io瓶頸,所以選擇了redis ,當然可以使用kafka,rabbitmq等消息中間件。

配置filebeat(註意為yaml語法,什麽是yaml自己google):

filebeat.prospectors:

  • type: log
    enabled: true
    paths:
    • /var/log/*.log ###監控的文件

輸出到redis:
##-------------------------- redis output ------------------------------------

output.redis:
hosts: ["192.168.147.190"]
password: "6lapp"
key: "log_file"
db: 0
timeout: 5

logstash配置,只是寫了最簡單的input和output,需要filter的可以去github上面找正則去匹配,有點繁瑣就沒有寫:

cat /etc/logstash/conf.d/redis_logstash.conf
input {
redis {
port => "6379"
host => "192.168.147.190"
password => "6lapp"
data_type => "list"
type => "log"
key => "log_file"
}
}

output {
elasticsearch {
hosts => "192.168.147.190:9200"
index => "logstash-%{+YYYY.MM.dd}"
}
}

elasticsearch配置,這裏沒有建立集群,elaticsearch 有自動發現功能,所以只是需要配置ip和端口即可:

---------------------------------- Network -----------------------------------

#

Set the bind address to a specific IP (IPv4 or IPv6):

#
network.host: 192.168.147.190
#

Set a custom port for HTTP:

#
http.port: 9200
#

For more information, consult the network module documentation.

#

kibana配置需要修改端口ip和 elasticsearch的地址即可:
server.port: 5601
server.host: 192.168.147.190
elasticsearch.url: "http://192.168.147.190:9200"

啟動:
systemctl start redis
systemctl start filebeat
logstash -f /etc/logstash/conf.d/redis_logstash & 或者使用nohup啟動 或者使用screen啟動
systemctl start elasticsearch
systemctl start kibana

啟動之後查看進程和端口:
訪問一下http://192.168.147.190:5601 可以操作kibana了,整個日誌系統初步搭建完成,需要使用完善一下logstash的配置文件即可
創建測試文件:
touch /var/log/test.log
for ((i=0 ;i<=10000 ;i++ ));do echo "test.log 0000000" >> test.log ;done

kibana截圖:
技術分享圖片

註意:
kibana的時間和系統的時間是否一致,否則可能導致看不到圖像,這個是我猜的一個坑。

參考文件:
https://www.elastic.co
https://blog.csdn.net/Ghost_leader/article/details/79121297

filebeat+redis+elk日誌平臺搭建