步骤一 搭建swarm集群环境
1、创建keystore宿主机,创建命令如下:
eval "$(docker-machine env elk-keystore)"
2、在elk-keystore宿主机上创建consul容器,创建命令如下:
1)eval "$(docker-machine env elk-keystore)"
2)docker run -d \-p "8500:8500" \-h "consul" \progrium/consul -server -bootstrap
3)
创建elasticsearch宿主机(同时作为swarm集群的master节点),创建命令如下:
docker-machine create \
-d virtualbox \
--swarm --swarm-master \
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-advertise=eth1:2376" \
mh-elasticsearch
4)
创建logstash宿主机,创建命令如下:
docker-machine create -d virtualbox \--swarm \--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \--engine-opt="cluster-advertise=eth1:2376" \mh-logstash
5)
创建kibana宿主机,创建命令如下:
docker-machine create -d virtualbox \--swarm \--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \--engine-opt="cluster-advertise=eth1:2376" \mh-kibana
步骤二 检验集群环境是否搭建成功,利用命令docker info监测
步骤三 利用docker-compose搭建创建ELK容器,yml文件如下所示:
version: '2'
services:elasticsearch:image: elasticsearch:latestvolumes:- /c/Users/xu/Desktop/elkcompose/elasticsearch/data/:/usr/share/elasticsearch/dataenvironment:- "constraint:node==mh-elasticsearch"#- ES_CLUSTERNAME=elasticsearchcommand: elasticsearch -Des.config=/usr/share/elasticsearch/config/elasticsearch.ymlports:- "9200:9200"- "9300:9300"networks:- mynet kibana:image: kibana:latestports:- "5601:5601"depends_on:- elasticsearch networks:- mynetlinks:- elasticsearch:elasticsearchenvironment:- "constraint:node==mh-kibana"logstash:image: logstash:latestports:- "25826:25826"- "25826:25826/udp"networks:- mynetlinks:- elasticsearch:elasticsearchdepends_on:- elasticsearchvolumes:- /c/Users/xu/Desktop/elkcompose/logstash/conf/:/conf- /c/Users/xu/Desktop/elkcompose/logstash/testdata/:/testdatacommand: logstash agent -f /conf/logstash.confenvironment:- "constraint:node==mh-logstash"
networks:mynet:
启动docker-compose,命令如下:
1)eval $(docker-machine env --swarm mh-elasticsearch)
2) docker-compose up