Simple ELK with logback to build a log monitoring center

Today I have a free time to build an ELK example, the process is very simple.

  Elastic Search, logstash, kibana can be downloaded from this address https://www.elastic.co/cn/products . Ado.
First install ES. Unzip the download package to the top directory startup script and then elasticsearch in the bin directory. The parameters are configured in the config directory. The main configuration file is elasticsearch.yml. The main configurable port and discovery.zen.minimum_master_nodes are the minimum nodes for this election (to prevent "split brain").

Install logstash afterwards. After decompressing the compressed package, create a logstash-simple.conf under the same level of the decompressed directory.
The following is my configuration
input {  
  tcp {  
        port => 8333  
      }  
}  
  
filter {  
}  
  
output {  
  elasticsearch { hosts => "127.0.0.1" }  
  stdout {  
         codec => rubydebug  
         }  
}

How to configure this address can refer to. https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html
logstash process pipeline is executed according to input, filter, output, available plugins can refer to address below.
https://www.elastic.co/guide/en/logstash/current/input-plugins.html
https://www.elastic.co/guide/en/logstash/current/output-plugins.html

followed by kibana installation . After the decompression is complete, there is kibana.yml in the config directory. Mainly configure the http port address of ES elasticsearch.url: "http://localhost:9200/", so as to obtain the log data imported into ES through Logstash.

The following is my logback configuration file, which is directly imported into logstash through logback appender
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
	<appender name="logstash-out" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
		<!-- <destination>localhost:8333</destination> -->
		<param name="Encoding" value="UTF-8"/>
		<remoteHost>localhost</remoteHost>
		<port>8333</port>
		<encoder>
			<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
		</encoder>
	</appender>
	
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
		</encoder>
	</appender>
	
	<root level="DEBUG">
    	<appender-ref ref="logstash-out" />
    	<appender-ref ref="STDOUT" />
    </root>
</configuration>


After the configuration is complete, just write a log output code to verify it.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogPrint {

	private static final Logger LOGGER = LoggerFactory.getLogger(LogPrint.class);

	public static void main(String[] args) {

		LOGGER.info("test log info begin");
		for (int i = 0; i < 100; i++) {

			LOGGER.debug("[ResponseEntity]:{}", "i am debug" + i);
			LOGGER.info("[ResponseEntity] i am info" + i);
			LOGGER.error("[ResponseEntity]i am error" + i);
			LOGGER.warn("[ResponseEntity]i am warn" + i);
			LOGGER.debug("[ResponseEntity]:{}", "i am debug" + i);
			LOGGER.info("[ResponseEntity] i am info" + i);
			LOGGER.error("[ResponseEntity]i am error" + i);
			LOGGER.warn("[ResponseEntity]i am warn" + i);
		}
	}
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326224101&siteId=291194637