下載Elasticsearch7.6.2的docker鏡像:
docker pull elasticsearch:7.6.2
修改虛擬內(nèi)存區(qū)域大小,否則會(huì)因?yàn)檫^小而無法啟動(dòng):
sysctl -w vm.max_map_count=262144
使用如下命令啟動(dòng)Elasticsearch服務(wù):
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins\
-v/data/elasticsearch/data:/usr/share/elasticsearch/data \
-d elasticsearch:7.6.2
啟動(dòng)時(shí)會(huì)發(fā)現(xiàn)/usr/share/elasticsearch/data目錄沒有訪問權(quán)限,只需要修改/data/elasticsearch/data目錄的權(quán)限,再重新啟動(dòng)即可;
chmod 777 /data/elasticsearch/data/
安裝中文分詞器IKAnalyzer,并重新啟動(dòng):
docker exec -it elasticsearch /bin/bash
#此命令需要在容器中運(yùn)行
elasticsearch-plugin installhttps://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip
docker restart elasticsearch
下載Logstash7.6.2的docker鏡像:
docker pull logstash:7.6.2
修改Logstash的配置文件logstash.conf中output節(jié)點(diǎn)下的Elasticsearch連接地址為es:9200,配置文件地址:https://github.com/macrozheng/mall/blob/master/document/elk/logstash.conf
output {
? elasticsearch {
? ? hosts => ["http://elasticsearch:9200"]
? ? index => "omc-block-server-%{[@metadata][version]}-%{+YYYY.MM.dd}"
? ? document_id => "%{id}"
? }
? stdout {
? ? codec => json_lines
? }
}
創(chuàng)建/data/logstash目錄,并將Logstash的配置文件logstash.conf拷貝到該目錄;
mkdir /data/logstash
使用如下命令啟動(dòng)Logstash服務(wù);
docker run --name logstash -p 4560:4560 -p 4561:4561 -p 4562:4562 -p 4563:4563 \
--link elasticsearch:es \
-v /data/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf \
-d logstash:7.6.2
進(jìn)入容器內(nèi)部,安裝json_lines插件。
logstash-plugin install logstash-codec-json_lines
下載Kibana7.6.2的docker鏡像:
docker pull kibana:7.6.2
使用如下命令啟動(dòng)Kibana服務(wù):
docker run --name kibana -p 5601:5601 \
--link elasticsearch:es \
-e "elasticsearch.hosts=http://es:9200"\
-d kibana:7.6.2
訪問地址進(jìn)行測試:http://192.168.10.125:5601
kibana界面中文設(shè)置
在kibana.yml尾部添加一行配置即可
i18n.locale: "zh-CN"
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.6.2-amd64.deb
sudo dpkg -i filebeat-7.6.2-amd64.deb
2 編輯配置
修改?/etc/filebeat/filebeat.yml?以設(shè)置連接信息:
output.elasticsearch:
hosts: ["<es_url>"]
username:"elastic"
password:"<password>"
setup.kibana:
host:"<kibana_url>"
[其中,<password>?是?elastic?用戶的密碼,<es_url>?是 Elasticsearch 的 URL,<kibana_url>?是 Kibana 的 URL。
3 啟用和配置 system 模塊
sudo filebeat modules enable system
在?/etc/filebeat/modules.d/system.yml?文件中修改設(shè)置。
4 啟動(dòng)Filebeat
setup?命令加載 Kibana 儀表板。如果儀表板已設(shè)置,請(qǐng)省略此命令。
sudo filebeat setup
sudo service filebeat start
模塊狀態(tài)
確認(rèn)已從 Filebeat?system?模塊成功收到數(shù)據(jù)
檢查數(shù)據(jù)
http://www.macrozheng.com/#/deploy/mall_deploy_docker