1、在管理机上运行 docker swarm init --advertise-addr 192.168.204.135 2、在节点机上运行(加入集群) docker swarm join
--token SWMTKN-1-48w6yubnwxpbboqo296es90r7snmru0q2dnwmthq1i7a6qlom9-8xuklnbfys5vdcx3pkyf4u3ha
192.168.204.135:2377 3、在管理机上运行(Nginx 集群) docker service create --name nginx-web
--mount type=bind,source=/root/nginx/www,destination=/usr/share/nginx/html
--mount type=bind,source=/root/nginx/logs,destination=/var/log/nginx
--mount type=bind,source=/etc/localtime,destination=/etc/localtime
--replicas 2 --publish 10080:80 nginx:latest 备注:宿主机与容器有目录对应关系 4、在浏览器上打开网页,查看效果 5、下载elk 镜像 Docker pull sebp/elk 6、运行elk docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -v /root/nginx/logs:/data -it -d --name elk-guodong sebp/elk 7、配制logstash input { file { path => "/data/access.log" start_position => "beginning" } }i nput { file { path => "/data/access-201900000002.log " start_position => "beginning" } }f ilter{ grok { match => { "message" => "%{IPORHOST:clientip} - - [%{HTTPDATE:timestamp}] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}) %{QS:referrer} %{QS:agent}" } } } output { elasticsearch { hosts => ["192.168.204.135:9200"] } stdout {codec => rubydebug} } 8、启动logstash(进入容器运行) /opt/logstash/bin/logstash --path.data /root/ -f /data/config/logstash.conf 9、查看并配制 http://192.168.204.135:5601/app/kibana#/management/kibana/index?_g=() 10、可以在discover 界面创建索引 11、在visualize 界面进行可视化(如图标等的绘制) 12、效果