Spring Boot ELK two-step integrated log collection and Distributed System CAT

ELK distributed log collection and monitoring system CAT


Spring Boot project integration method

A. Pom.xml introduced starter dependent
<dependency>
    <groupId>com.louis</groupId>
    <artifactId>ylog-spring-boot-starter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
Two. Bootstrap.yml profile open log
ylog:
  enable-y-log: ${YLog_Enable:true}
  app-name: ${spring.application.name}
  env: ${spring.profiles.active}
  cat:
    enable-cat: ${YLog_Enable_Cat:true}
    http-port: ${YLog_Cat_HttpPort:8081}
    port: ${YLog_Cat_Port:2280}
    cat-servers: ${YLog_Cat_Servers:192.168.102.212}
    enable-spring-bean-aop: true
  elk:
    enable-elk: ${YLog_Enable_Elk:true}
    logstash-host: ${YLog_Enable_elk:192.168.102.130:30309}

Appendix: Installation Services


A. ELK installation

1. ElasticSearch installation
  • Download the archive and extract the required version

  • Modify /config/elasticsearch.yml

    network.host=127.0.0.1
    network.port=9200
  • Start /bin/elasticsearch.bat

  • Browser to access http: // localhost: 9200 /, a normal return json format ES server information, namely the installation was successful

2. Logstash installation
  • Download the archive and extract the required version

  • Modify /config/logstash.yml

    xpack.monitoring.elasticsearch.hosts: ["http://localhost:9200"]
  • New /config/log4j_to_es.conf file, as follows:

    input {
        tcp {
            port => 4560
            codec => json_lines
        }
    } 
    output {
            elasticsearch {
                    hosts => "127.0.0.1:9200"
                    index => "applog"
            }
            stdout { codec => rubydebug}
    }
    • New /bin/run_default.bat file, as follows:

      D:\ELK\logstash-7.4.0\bin\logstash.bat -f D:\ELK\logstash-7.4.0\bin\log4j_to_es.conf
      pause
    • Start /bin/run_default.bat

    • View the console output, no ERROR. Browser to access http: // localhost: 9600 /, the server normally returns json format information, that is, the installation was successful

3. Kibana AnSo
  • Download the archive and extract the required version

  • Modify /config/kibana.yml

    elasticsearch.hosts: ["http://localhost:9200"]
    elasticsearch.requestTimeout: 90000
  • Run /bin/kibana.bat

  • Visit http: // localhost: 5601 kibana normal display page, is the successful installation

The official document: gitbook

Two. CAT installation

  • Download the official Open Source Source: https://github.com/dianping/cat.git

  • Switch to the 2.0.0 version (removing part of the plug-cat version 3.0.0, you need to install to the local maven repository in the 2.0.0 version):

    git checkout v2.0.0
  • Execute mvn command to install the plug-in

    mvn clean install -Dmaven.test.skip=true
  • Switch to version 3.0.0

    git checkout v3.0.0
  • Create mysql database cat, script execution /script/CatApplication.sql 3.0.0 branch to complete the initialization

  • New configuration file client.xml to tomcat installation disk, such as file directory: C: \ data \ appdatas \ cat \ client.xml, configuration elements:

    <?xml version="1.0" encoding="utf-8"?>
    <config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd">
      <servers>
          <!-- Local mode for development -->
          <server ip="10.0.75.1" port="2280" http-port="8080" />
          <!-- If under production environment, put actual server address as list. -->
          <!-- <server ip="192.168.7.71" port="2280" /> -->
      </servers>
    </config>

    Local debugging within the native network ip address, write 127.0.0.1 could lead to service failed to start

    • New server.xml configuration file to the tomcat installation disk, such as file directory C: \ data \ appdatas \ cat \ server.xml, configuration elements:

      <?xml version="1.0" encoding="utf-8"?>
      
      <!-- Configuration for development environment-->
      <config local-mode="false" hdfs-machine="false" job-machine="true" alert-machine="false">
      
          <storage  local-base-dir="/data/appdatas/cat/bucket/" max-hdfs-storage-time="15" local-report-storage-time="7" local-logivew-storage-time="7">
      
          </storage>
      
          <console default-domain="Cat" show-cat-domain="true">
              <remote-servers>10.0.75.1:8080</remote-servers>     
          </console>
      
      </config>

      Local debugging within the native network ip address, write 127.0.0.1 could lead to service failed to start

    • New configuration file datasources.xml to tomcat installation disk, such as file directory C: \ data \ appdatas \ cat \ datasources.xml, configuration elements:

      <?xml version="1.0" encoding="utf-8"?>
      
      <data-sources>
          <data-source id="cat">
              <maximum-pool-size>3</maximum-pool-size>
              <connection-timeout>1s</connection-timeout>
              <idle-timeout>10m</idle-timeout>
              <statement-cache-size>1000</statement-cache-size>
              <properties>
                  <driver>com.mysql.jdbc.Driver</driver>
                  <url><![CDATA[jdbc:mysql://127.0.0.1:3306/cat]]></url>
                  <user>root</user>
                  <password>123456</password>
                  <connectionProperties><![CDATA[useUnicode=true&autoReconnect=true]]></connectionProperties>
              </properties>
          </data-source>
          <data-source id="app">
              <maximum-pool-size>3</maximum-pool-size>
              <connection-timeout>1s</connection-timeout>
              <idle-timeout>10m</idle-timeout>
              <statement-cache-size>1000</statement-cache-size>
              <properties>
                  <driver>com.mysql.jdbc.Driver</driver>
                  <url><![CDATA[jdbc:mysql://127.0.0.1:3306/cat]]></url>
                  <user>root</user>
                  <password>123456</password>
                  <connectionProperties><![CDATA[useUnicode=true&autoReconnect=true]]></connectionProperties>
              </properties>
          </data-source>
      </data-sources>
  • Execute the command mvn package Source

    mvn clean install -Dmaven.test.skip=true
  • Copy /cat-home/target/cat-home-3.0.0.jar to the installation directory of tomcat, and renamed car.jar: /webapps/cat.jar

  • Start tomcat

  • Visit http: // localhost: 8080 / cat, cat show normal home page, is the successful installation

ylog-spring-boot-starter Source: GitHub

Guess you like

Origin www.cnblogs.com/LouisGuo/p/12170608.html