說明:本次使用的windows系統,利用vm進行安裝虛擬機,安裝的只是單測試單機版elk。
一、下載vm
自行官網下載
二、安裝centos7系統
自己有現成的鏡像跳過,沒有自行查找資料完成
三、進行centos系統后進行docker安裝
1)yum install docker(后面一路回車)
2)進行docker鏡像加速
參考地址:https://www.cnblogs.com/runnerjack/articles/7519070.html
四、修改host文件
vi /etc/hosts
添加以下內容
==================
Ip elasticsearch
五、關閉防火牆與selinux
1)
systemctl stop firewalld.service
systemctl disable firewalld.service
2)
setenforce 0 vim /etc/sysconfig/selinux
將其中的:
SELINUX=enforcing
改成:
SELINUX=disabled
六、安裝ElasticSearch
1)安裝
docker pull docker.io/elasticsearch:7.5.2 docker run -d --name es --restart=always --net=host -e "discovery.type=single-node" docker.io/elasticsearch:7.5.2
2)配置跨域
docker exec -it es /bin/bash
修改 elasticsearch.yml(cd / 后用find -name elasticsearch.yml進行查找)
#
顯示文件
ls
結果如下:
LICENSE.txt README.textile config lib modules
NOTICE.txt bin data logs plugins
#
進入配置文件夾
cd config
#
顯示文件
ls
結果如下:
elasticsearch.keystore ingest-geoip log4j2.properties roles.yml users_roles
elasticsearch.yml jvm.options role_mapping.yml users
#
修改配置文件
vi elasticsearch.yml
#==========================================
重點在這==================================
#
加入跨域配置
http.cors.enabled: true http.cors.allow-origin: "*"
3)重啟容器
docker restart es
4)驗證訪問
http://localhost:9200/
顯示效果如下就成功了
{
"name"
:
"a12CcOw",
"cluster_name"
:
"docker-cluster",
"cluster_uuid"
:
"Zi4eufCQQ6y88rO0lt9YVw",
"version"
:
{
"number"
:
"6.3.2",
"build_flavor"
:
"default",
"build_type"
:
"tar",
"build_hash"
:
"053779d",
"build_date"
:
"2018-07-20T05:20:23.451332Z",
"build_snapshot"
:
false,
"lucene_version"
:
"7.3.1",
"minimum_wire_compatibility_version"
:
"5.6.0",
"minimum_index_compatibility_version"
:
"5.0.0"
},
"tagline"
:
"You Know, for Search"}
七、安裝ElasticSearch-Head
為什么要安裝ElasticSearch-Head呢,原因是需要有一個管理界面進行查看ElasticSearch相關信息
第一步:拉取
docker pull mobz/elasticsearch-head:5
第二步:安裝
docker run -d --name es_admin -p 9100:9100 --restart=always mobz/elasticsearch-head:5
第三步:訪問地址
見如下效果就成功了
八、安裝logstash
1)
docker run -d --net=host \ -v /home/lj/logstash/config/logstash.conf:/usr/share/logstash/pipeline/logstash.conf \ -v /home/lj/logstash/test/:/home/lj/logstash/test/ \
--restart=always \
--name es_logstash docker.io/logstash:7.5.2
其中外掛的logstash.conf文件為(文件內容嚴格遵守縮進,不然不報錯而且容器退出):
input { beats { port => "5044" } } filter { } output { stdout {} elasticsearch { hosts => ["192.168.253.140:9200"] index => "logstash-test-%{+YYYY.MM.dd}" } }
2)進入目錄cd config ,打開並修改配置文件
docker exec -it es_logstash /bin/bash
cd /usr/share/logstash/config
vi logstash.yml
修改IP
xpack.monitoring.elasticsearch.hosts: [ "http://elasticsearch:9200" ]
為
xpack.monitoring.elasticsearch.hosts: [ "http://192.168.253.140:9200" ]
添加以下信息
xpack.monitoring.elasticsearch.username: elastic
xpack.monitoring.elasticsearch.password: changme
重啟容器
docker restart es_logstash
九、安裝kibana
注意版本一定要比ES低
1)生成容器
docker run --name es_kibana -p 5601:5601 -d --net=host --restart=always -e ELASTICSEARCH_URL=http://localhost:9200 docker.io/kibana:7.5.2
3) 訪問:http://localhost:5601/
十、安裝filebeat
1) 拉鏡像
docker pull docker.io/elastic/filebeat:7.5.2
2)配置文件
mkdir -p /home/lj/filebeat/config
vi /home/lj/filebeat/config/filebeat.yml
filebeat.inputs: - type: log paths: - /var/log/system.log - /var/log/wifi.log output.logstash: hosts: ["127.0.0.1:5044"]
2) 生成容器
docker run -d --name filebeat \ -v /home/lj/filebeat/config/filebeat.yml:/usr/share/filebeat/filebeat.yml \ -v /test/log/:/var/log/ \
--restart=always \ docker.io/elastic/filebeat:7.5.2
十一、驗證
在宿主機的/test/log/目錄下創建一個wifi.log或system.log文件,隨便丟點東西,然后訪問http://192.168.253.140:9200/logstash-test-2020.04.15/_search就能查看到數據了,黃色為現在的日期。
可能碰到的問題:
1. docker啟動報錯iptables failed?
解決方案:https://www.cnblogs.com/amoyzhu/p/9329368.html
2. 本次elk安裝參考的網址?
https://www.jianshu.com/p/a0bd70301eec
但是文檔中的安裝與參考的內容有些出入,版本號也不一樣。以文檔為主,碰到問題可以參考elk安裝參考網址。