继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

搭建ELK日志分析系统(Docker方式)

慕标5832272
关注TA
已关注
手记 1232
粉丝 229
获赞 1001
  1. 安装Docker CE

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo$ sudo yum install docker-ce$ sudo systemctl start docker$ sudo docker run hello-world
  1. 安装Docker Compose

$ sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose$ sudo chmod +x /usr/local/bin/docker-compose$ docker-compose --version
  1. https://github.com/deviantony/docker-elk克隆源代码

$ git clone https://github.com/deviantony/docker-elk$ docker-compose up -d
  1. 默认端口配置

  • 5000: Logstash TCP input

  • 9200: Elasticsearch HTTP

  • 9300: Elasticsearch TCP transport

  • 5601: Kibana

  1. 修改logstash.conf配置

input {
  tcp {
    port => 5000
    codec => json_lines
  }
}

output {
  elasticsearch {
    hosts => "elasticsearch:9200"
  }
}
  1. 在微服务项目中,添加logback-spring.xml配置文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?><configuration debug="false">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>

    <property name="appName" value="gateway"/>
    <property name="appVersion" value="1.0.0"/>

    <springProfile name="default,dev">
        <property name="logstashDest" value="172.20.15.52:5000"/>

        <appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
            <destination>${logstashDest}</destination>
            <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                <providers>
                    <mdc/> <!-- MDC variables on the Thread will be written as JSON fields-->
                    <context/> <!--Outputs entries from logback's context -->
                    <version/> <!-- Logstash json format version, the @version field in the output-->
                    <logLevel/>
                    <loggerName/>

                    <pattern>
                        <pattern>
                            {                            <!-- we can add some custom fields to be sent with all the log entries.-->
                            <!--make filtering easier in Logstash-->
                            "appName": "${appName}",
                            "appVersion": "${appVersion}"
                            }                        </pattern>
                    </pattern>

                    <threadName/>
                    <message/>

                    <logstashMarkers/> <!-- Useful so we can add extra information for specific log lines as Markers-->
                    <arguments/> <!--or through StructuredArguments-->

                    <stackTrace/>
                </providers>
            </encoder>
        </appender>
    </springProfile>

    <root level="INFO">
        <appender-ref ref="CONSOLE"/>

        <springProfile name="default,dev">
            <appender-ref ref="logstash"/>
        </springProfile>
    </root></configuration>



作者:王睿同学
链接:https://www.jianshu.com/p/9d2b9b34dbbe


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP