日志收集模块用于集中展示各个微服务子系统产生的日志,后端通过ELK实现,前端系统通过iframe加载Kibana页面。 Windows系统搭建ELK环境较为麻烦,可以在Linux虚拟机中使用我提供的docker-compose.yml来一键运行ELK: ```yml version: '3' services: elasticsearch: image: elasticsearch:6.4.1 container_name: elasticsearch environment: - "cluster.name=elasticsearch" #集群名称为 elasticsearch - "discovery.type=single-node" #单节点启动 - "ES_JAVA_OPTS=-Xms512m -Xmx512m" #jvm内存分配为 512MB volumes: - /febs/elasticsearch/plugins:/usr/share/elasticsearch/plugins - /febs/elasticsearch/data:/usr/share/elasticsearch/data ports: - 9200:9200 kibana: image: kibana:6.4.1 container_name: kibana links: - elasticsearch:es #配置elasticsearch域名为 es depends_on: - elasticsearch environment: - "elasticsearch.hosts=http://es:9200" #因为上面配置了域名,所以这里可以简写为 http://es:9200 ports: - 5601:5601 logstash: image: logstash:6.4.1 container_name: logstash volumes: - /febs/logstash/logstash-febs.conf:/usr/share/logstash/pipeline/logstash.conf depends_on: - elasticsearch links: - elasticsearch:es ports: - 4560:4560 ``` 我的Linux虚拟机IP为192.168.33.10,Logstash地址为:192.168.33.10:4560。 ELK环境搭建好后,将febs-auth、febs-gateway、febs-server-system和febs-server-test模块下的日志配置文件logback-spring.xml中的注释打开: ![268.png](https://s2.ax1x.com/2019/09/07/n1yPpj.png) 逐一修改完毕后,重启febs-auth、febs-gateway、febs-server-system和febs-server-test微服务。重启后,点击日志收集菜单,如下所示: ![269.png](https://s2.ax1x.com/2019/09/07/n1yrut.png)