在之前的文章中,日月已經教大家如何在windows環境搭建elk和進階版的filebeat + redis + elk,今天,日月在這裡教大家如何在linux環境搭建進階版的filebeat + redis +elk。
windows環境搭建的請看:ELK進階為filebeat+reids+ELK(windows版)
環境:centos 7.4
工具:xshell 5
一、安裝包下載下傳
https://www.elastic.co/downloads
elasticsearch-6.6.1.tar.gz
logstash-6.6.1.tar.gz
filebeat-6.6.1-linux-x86_64.tar.gz
kibana-6.6.1-linux-x86_64.tar.gz
此外還需要reids,這裡不做叙述,請翻閱之前的文章。
二、将安裝包上傳至伺服器
使用 rz 指令 或者 Xftp
三、解壓安裝包
tar -zxvf elasticsearch-6.6.1.tar.gz
tar -zxvf logstash-6.6.1.tar.gz
tar -zxvf filebeat-6.6.1-linux-x86_64.tar.gz
tar -zxvf kibana-6.6.1-linux-x86_64.tar.gz
解壓後:
四、防火牆開放端口
elasticsearch 的 9200 端口 和 kibana 的 5601 端口
修改/etc/sysconfig/目錄下的iptables檔案,這個比較簡單,大家自行百度即可。
添加好之後重新開機防火牆
service iptables restart
五、修改es配置檔案
config/elasticsearch.yml 添加下面一行
network.host: 伺服器ip或者域名
六、添加使用者 并賦權
useradd chenqi
root使用者下
chown chenqi:chenqi -R /opt/elasticsearch-6.6.1
七、切換使用者,啟動es
su - chenqi
#es目錄下
./bin/elasticsearch &
常見問題:es啟動報錯
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解決:切換到root使用者修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并執行指令:
sysctl -p
然後,重新啟動elasticsearch,即可啟動成功。
浏覽器通路:ip + 端口9200
八、修改filebeat.yml配置檔案
filebeat安裝目錄下
Outputs配置子產品注釋掉Elasticsearch output配置
添加redis配置
#-------------------------- reids output ------------------------------
output.redis:
hosts: ["192.168.50.252:6379"]
password: "whpipa123"
key: filebeat
timeout: 5s
max_retries: 3
修改 Filebeat inputs子產品配置
enabled: true
添加掃描的日志檔案
paths:
- /var/log/*.log
- /testlog.log
添加
encoding: utf-8
scan_frequency: 10s
harvester_buffer_size: 16384
max_bytes: 10485760
tail_files: true
九、啟動filebeat
./filebeat -e -c filebeat.yml &
十、編輯logstash配置檔案
logstash安裝目錄中的conf目錄下logstash-sample.conf
配置替換為:
input {
redis {
host => "192.168.50.252"
port => "6379"
password => "whpipa123"
data_type => "list"
key => "filebeat"
type => "redis-input"
}
}
filter {
}
output {
# For detail config for elasticsearch as output,
# See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html
elasticsearch {
action => "index" #The operation on ES
hosts => "192.168.50.252:9200" #ElasticSearch host, can be array.
index => "chenqilog" #The index to write data to.
}
}
11、啟動logstash
./bin/logstash -f config/logstash-sample.conf &
12、修改kibana配置檔案
kibana安裝目錄中的config目錄下kibana.yml
添加:
server.port: 5601
server.host: 192.168.50.252
elasticsearch.url: http://192.168.50.252:9200
13、啟動kibana
./bin/kibana &
浏覽器通路:ip:5601
建立索引:
由于這裡是示範,是以建立索引前需要去伺服器testlog.log檔案中添加一些日志資料,不然索引無法建立。記得實際情況中,filebeat配置檔案中的日志讀取目錄是你項目的日志輸出目錄。
OK,至此,linux搭建filebeat + redis + elk完成。
如果該文章有幫助到您,就留言點個贊吧!您的支援與肯定是我持續更新最大的動力。