Docker部署SpringCloud ELK+RabbitMQ
一、效果图
image.png二、ELK是什么?
能找到这篇文章肯定知道什么是elk,如果不知道,请参考:https://www.elastic.co/webinars/introduction-elk-stack
三、ELK安装
docker安装步骤,CentOS7以上请参考:https://docs.docker.com/engine/installation/linux/docker-ce/centos/
3.1安装rabbitmq
docker run -d -it --name rabbit --hostname rabbit -p 5672:5672 -p 15672:15672 rabbitmq:management,默认密码和用户名为guest
3.2安装elasticsearch
docker run -d -it --name es -p 9200:9200 -p 9300:9300 elasticsearch
3.3安装kibana
docker run -d -it --name kibana --link es:elasticsearch -p 5601:5601 kibana
3.4安装logstash
docker run -d -it logstash -e 'input { rabbitmq {
host => "192.168.0.34(不要写localhost)" port => 端口 exchange=>'ex_logstash' queue =>'q_logstash' durable => true } }
output { elasticsearch { hosts => ["192.168.0.34"] } }'
3.5查看它们日志方式
docker logs CONTAINER ID(容器id)
四、springcloud项目中logback.xml配置方法
<appender name="AMQP"
class="org.springframework.amqp.rabbit.logback.AmqpAppender">
<layout>
<pattern>
{
"time": "%date{ISO8601}",
"thread": "%thread",
"level":
"%level",
"class": "%logger{60}",
"message": "%msg"
}
</pattern>
</layout>
<host>192.168.0.34</host>
<port>5672</port>
<username>guest</username>
<password>guest</password>
<applicationId>ms</applicationId>
<routingKeyPattern>lgstash</routingKeyPattern>
<declareExchange>true</declareExchange>
<exchangeType>direct</exchangeType>
<exchangeName>ex_logstash</exchangeName>
<generateId>true</generateId>
<charset>UTF-8</charset>
<durable>true</durable>
<deliveryMode>PERSISTENT</deliveryMode>
</appender>
<root level="INFO">
<appender-ref ref="AMQP" />
</root>
五、rabbitmq配置
先创建一个q_logstash队列,再绑定,见下图:
image.png六、访问Kibanna
打开192.168.0.34:5601,会出现要你配置index pattern的界面,如果无法使用默认的logstash-*模式,证明你部署的还是有问题,请参考日志纠错。