基于docker安裝ELK

文章目錄結(jié)構(gòu)如下:


image.png

巨坑提醒:ES和kibana的版本盡可能的保證一致,否則要去修改很多配置信息,而且不一定能安裝成功,現(xiàn)象:ES安裝成功了但是kibana無(wú)法鏈接到ES,報(bào)紅(red)。

1、安裝完后的ELK訪(fǎng)問(wèn)路徑

ES訪(fǎng)問(wèn) :http://localhost:9200/

Es-head訪(fǎng)問(wèn): http://localhost:9100/

kibana訪(fǎng)問(wèn):http://localhost:5601

2、ElasticSearch

可以事先搜索一下:

docker search elasticsearch

第一步:拉取鏡像

docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2

注意可以是其他版本,本次安裝拉取"6.3.2"版本,

下載需要一段時(shí)間,完畢后可以查看鏡像,注意:如果下載不成功,可以查找其他版本。

docker images

第二步:安裝

docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2

ElasticSearch的默認(rèn)端口是9200,我們把宿主環(huán)境9200端口映射到Docker容器中的9200端口,就可以訪(fǎng)問(wèn)到Docker容器中的ElasticSearch服務(wù)了,同時(shí)我們把這個(gè)容器命名為es。

第三步:配置跨域

1)進(jìn)入容器

docker exec -it es /bin/bash

其中"es"是容器名稱(chēng)

2)修改 elasticsearch.yml

# 顯示文件
ls
結(jié)果如下:
LICENSE.txt  README.textile  config  lib   modules
NOTICE.txt   bin             data    logs  plugins
# 進(jìn)入配置文件夾
cd config
# 顯示文件
ls
結(jié)果如下:
elasticsearch.keystore  ingest-geoip  log4j2.properties  roles.yml  users_roles
elasticsearch.yml       jvm.options   role_mapping.yml   users
# 修改配置文件
vi elasticsearch.yml
#==========================================重點(diǎn)在這==================================
# 加入跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"
使用三個(gè)命令:

1) 修改命令 shift + i;

2)退出修改模式esc;

3)保存退出shift + :  wq

第四步:重啟容器

docker restart es 

第五步:訪(fǎng)問(wèn)地址

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"
}

3、ElasticSearch-Head

為什么要安裝ElasticSearch-Head呢,原因是需要有一個(gè)管理界面進(jìn)行查看ElasticSearch相關(guān)信息

第一步:拉取

docker pull mobz/elasticsearch-head:5

第二步:安裝

docker run -d --name es_admin -p 9100:9100 mobz/elasticsearch-head:5

第三步:訪(fǎng)問(wèn)地址

http://localhost:9100/

見(jiàn)如下效果就成功了


image.png

4、安裝logstash

第一步:安裝

選擇使用官網(wǎng)中的鏡像地址:

docker run --name es_logstash docker.elastic.co/logstash/logstash:6.2.4

docker run --name es_logstash logstash:6.2.4

容器名稱(chēng)"es_logstash“ ,版本”6.2.4“

第二步:修改logstash.yml文件

進(jìn)入容器:

docker exec -it es_logstash /bin/bash

進(jìn)入目錄cd config ,打開(kāi)并修改配置文件

vi logstash.yml

使用三個(gè)命令:

1) 修改命令 shift + i;

2)退出修改模式esc;

3)保存退出shift + :  wq
http.host: "0.0.0.0"
xpack.monitoring.elasticsearch.url: http://192.168.2.153:9200
xpack.monitoring.elasticsearch.username: elastic
xpack.monitoring.elasticsearch.password: changme

注意,一定是本機(jī)器IP地址。xpack.monitoring.elasticsearch.url: http://192.168.2.153:9200

5、安裝kibana

第一步:拉取

docker pull kibana:5.6.14 

注意版本一定要比ES低。

第二步:安裝

docker run --name es_kibana -p 5601:5601 -d -e ELASTICSEARCH_URL=http://192.168.2.153:9200 kibana:5.6.14

注意:我下載的版本是5.6.14

訪(fǎng)問(wèn)地址:http://127.0.0.1:5601。如果你的kibana版本高于ES的版本,訪(fǎng)問(wèn)后會(huì)報(bào)錯(cuò) "Kibana server is not ready yet"。因此在安裝前務(wù)必下載版本比ES低。

第三步:修改

1)修改pipeline下的logstash.conf文件

docker exec -it es_logstash /bin/bash
ls
bin  config  CONTRIBUTORS  data  Gemfile  Gemfile.lock  lib  LICENSE  logstash-core  logstash-core-plugin-api  modules  NOTICE.TXT  pipeline  tools  vendor
cd pipeline
ls
logstash.conf
vi logstash.conf
#原來(lái)的
#========================================
#input {
#  beats {
#    port => 5044
#  }
#}

#output {
#  stdout {
#    codec => rubydebug
#  }
#}
#========================================
#添加的部分
input {
        file {
            codec=> json
                path => "/usr/local/*.json"
        }
}
filter {
  #定義數(shù)據(jù)的格式
  grok {
    match => { "message" => "%{DATA:timestamp}\|%{IP:serverIp}\|%{IP:clientIp}\|%{DATA:logSource}\|%{DATA:userId}\|%{DATA:reqUrl}\|%{DATA:reqUri}\|%{DATA:refer}\|%{DATA:device}\|%{DATA:textDuring}\|%{DATA:duringTime:int}\|\|"}
  }
}
output {
   elasticsearch{
     hosts=> "http://192.168.2.153:9200"
   }
}

注意,一定是本機(jī)器IP地址, hosts=> "http://192.168.2.153:9200"

容器全部重啟

xx-Air::~ ming$ docker restart 122bddb80fb9
122bddb80fb9
xx-Air:~ ming$ docker restart es_admin
es_admin
xx-Air::~ ming$ docker restart 8a4cba6ae3aa
8a4cba6ae3aa
xx-Air::~ ming$ docker restart 415d5e4b3383

第四步:訪(fǎng)問(wèn)地址
http://localhost:5601/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容