Lilishop technology stack

Official public number & open source is not easy, if help please point Star

introduce

Liverpoolfc.tv: pickmall. Cn

Lilishop is a Java development, based on SpringBoot research and development of B2B2C multi-user mall, front-end use Vue, UNIAPP development system full end all open-source code

This system is used to teach you how to use every detail in the system, such as: payment, third-party login, log collection, distributed transactions, seconds kill scenarios and other scenarios learning scheme

Git addressGitee.com/beijing_hon…

This article studies the ELK log collection system

ELK is introduced

ELK is an acronym for three open source projects: Elasticsearch, Logstash, and Kibana. Elasticsearch is a search and analysis engine. Logstash is a server-side data processing pipeline that captures data from multiple sources at the same time, transforms it, and sends it to a “repository” such as Elasticsearch. Kibana allows users to visualize data using graphs and charts in Elasticsearch.

Responsible for the module

Elasticsearch: used to store and query log information.

Logstash: Used to collect logs. The application integrates the Logstash information and pushes logs to the Logstash.

Kibana: Elasticsearch Web interface. Index for graphical operation ES.

Using the step

  1. To start the ELK container, docker-compose is required. If you don’t know how to install the docker-compose, the environment will install the content.
#Jump item address
cd elk
#Start elK container services
docker-compose up -d
Copy the code
  1. Start the SpringBoot application.

  2. Request springboot application http://127.0.0.1:8080 response 500 error, because GET request I calculated 1/0, throw exception

  3. Request Kibana http://127.0.0.1:5601 to view the logs

Development steps

  1. The configuration log collection example is as follows (this file is a Docker container configuration file in the config directory of the elK project root directory, and the ik word divider is prepared in the same directory)

    1. Input source: Access listening local logstash
    2. Output element: Es is added. Index is the index name
    input {
      tcp {
        mode = > "server"
        host = > "127.0.0.1"
        port = > 4560
        codec = > json_lines}}output {
      elasticsearch {
        hosts = > "127.0.0.1:9200"
        index = > "application-%{+YYYY.MM.dd}"}}Copy the code
  2. The SpringBoot project adds maven dependencies

    <dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> The < version > 6.6 < / version > < / dependency >Copy the code
  3. Configure log output, project resource directory, configure configuration file logback.xml (SRC /resource/logback.xml)

    
            
    <! DOCTYPEconfiguration>
    <configuration>
        <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
        <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
        <! -- Application name -->
        <property name="APP_NAME" value="elk-study"/>
        <contextName>${APP_NAME}</contextName>
    
        <! Output to elk LOGSTASH-->
        <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
          <! -- Configure LOGSTASH address -->
            <destination>127.0.0.1:4560</destination>
            <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
                <providers>
                    <timestamp>
                        <timeZone>UTC</timeZone>
                    </timestamp>
                </providers>
                <! -- Custom field distinction items -->
                <customFields>{"appName":"${APP_NAME}"}</customFields>
            </encoder>
        </appender>
      <! -- Log level -->
        <root level="INFO">
          <! -- Output position is LOGSTASH-->
            <appender-ref ref="LOGSTASH"/>
        </root>
    </configuration>
    Copy the code
  4. Write a controller that throws an exception

    @RestController
    public class TestController {
    
        @GetMapping
        public void test(a) {
    
            // Throw an exception
            System.out.println(1 / 0); }}Copy the code