version: '2' services: elasticsearch-central: image: elasticsearch:5.6.4 container_name: es1 volumes: - /root/mydocker/docker-es/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml - /root/mydocker/docker-es/data1:/usr/share/elasticsearch/data restart: always environment: - ES_CLUSTERNAME=elasticsearch - "ES_JAVA_OPTS=-Xmx50m -Xms50m" command: elasticsearch ports: - "9200:9200" - "9300:9300" elasticsearch-data: image: elasticsearch:5.6.4 container_name: es2 volumes: - /root/mydocker/docker-es/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml - /root/mydocker/docker-es/data2:/usr/share/elasticsearch/data restart: always environment: - ES_CLUSTERNAME=elasticsearch - "ES_JAVA_OPTS=-Xmx50m -Xms50m" command: elasticsearch ports: - "9201:9200" - "9301:9300" links: - elasticsearch-central:elasticsearch elasticsearch-head: image: mobz/elasticsearch-head:5 container_name: head restart: always volumes: - /root/mydocker/docker-es/head-conf/Gruntfile.js:/usr/src/app/Gruntfile.js - /root/mydocker/docker-es/head-conf/app.js:/usr/src/app/_site/app.js ports: - "9100:9100" links: - elasticsearch-central:elasticsearch kibana: image: kibana container_name: kibana restart: always environment: - ELASTICSEARCH_URL=http://ip:9200 links: - elasticsearch-central:elasticsearch ports: - "5601:5601" logstash: image: docker.elastic.co/logstash/logstash:5.5.1 command: logstash -f /etc/logstash/conf.d/logstash.conf volumes: - $PWD/logstash/conf.d:/etc/logstash/conf.d - $PWD/log:/tmp container_name: logstash551 hostname: logstash restart: always depends_on: - elasticsearch-central ports: - "7001-7005:7001-7005" - "4567:4567"
input { tcp { port => 4567 codec => json_lines } } output { elasticsearch { action => "index" hosts => ["172.16.147.200:9200","172.16.147.200:9201"] index => "%{[appname]}" } }
<!-- logstash --> <dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> <version>4.11</version> </dependency>
<appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <destination>127.0.0.1:4567</destination> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>INFO</level> </filter> <!-- encoder必須配置,有多種可選 --> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"> <customFields>{"appname":"carer"}</customFields> </encoder> <connectionStrategy> <roundRobin> <connectionTTL>5 minutes</connectionTTL> </roundRobin> </connectionStrategy> </appender> <!-- 開發環境 --> <springProfile name="dev"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>${PATTERN}</pattern> </encoder> </appender> <logger name="com.zhiyis" level="debug"/> <root level="info"> <appender-ref ref="CONSOLE"/> <appender-ref ref="logstash" /> </root> </springProfile>
參考
https://blog.csdn.net/guduyishuai/article/details/79228306
https://www.cnblogs.com/zhyg/p/6994314.htmlhtml