欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot2.3集成ELK7.1.0的示例代碼

 更新時(shí)間:2020年08月12日 10:25:37   作者:陳湯姆  
這篇文章主要介紹了SpringBoot2.3集成ELK7.1.0的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

最近想用ELK做日志分析,所以先寫了Demo來實(shí)驗(yàn)一下!

1、安裝ELK(Elasticsearch+Logstash+Kibana),具體安裝教程百度

2、查看是否安裝成功,輸入localhost:9200,localhost:5601,如下頁面則安裝成功



3、pom包依賴

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.modules</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>elk</name>
  <description>Demo project for Spring Boot</description>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <!--集成logstash-->
    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>5.3</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>2.1.2</version>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.junit.vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>2.3.0.RELEASE</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

4、配置文件

server:
 port: 8087
spring:
 application:
  name: search-service
 elasticsearch:
  rest:
   uris: http://localhost:9200

5、在logstash的bin目錄下創(chuàng)建logstash.conf配置文件,啟動(dòng)logstash時(shí)要依賴這個(gè)配置文件
logstash.conf

input {
 tcp {
  mode => "server"
  port => 4560
  codec => json_lines
 }
}
output {
 elasticsearch {
  action => "index"
  hosts => "127.0.0.1:9200"
  index => "applog"
 }
}

6、在項(xiàng)目中創(chuàng)建logback-spring.xml

< destination>localhost:4560</ destination>
中的地址為logstash.conf設(shè)置的端口號(hào)

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

  <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
    <destination>localhost:4560</destination>
    <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />
  </appender>

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

7、創(chuàng)建controller類設(shè)定測試數(shù)據(jù)

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/elastic")
public class ElkController {

  Logger logger = LoggerFactory.getLogger(ElkController.class);

  @Autowired
  private ElkService elkService;

  @PostMapping
  public void create(){
    elkService.createIndex();
  }

  @RequestMapping("/test")
  public String test2(){
    logger.info("你好啊e");
    logger.warn("This is a warn message!");
    logger.error("This is error message!");
    return "ELK測試數(shù)據(jù)";
  }
}

8、打開localhost:5601,創(chuàng)建索引值,索引值跟logstash.conf中的outputindex一樣

9、回到首頁查看生成的日志信息

到此這篇關(guān)于SpringBoot2.3集成ELK7.1.0的示例代碼的文章就介紹到這了,更多相關(guān)SpringBoot2.3集成ELK7.1.0內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解決Tomcat修改get提交請(qǐng)求亂碼問題

    解決Tomcat修改get提交請(qǐng)求亂碼問題

    這篇文章主要介紹了Tomcat修改get提交請(qǐng)求亂碼問題的解決方案,需要的朋友參考下
    2017-04-04
  • Java使用通配符實(shí)現(xiàn)增強(qiáng)泛型詳解

    Java使用通配符實(shí)現(xiàn)增強(qiáng)泛型詳解

    泛型是JAVA重要的特性,使用泛型編程,可以使代碼復(fù)用率提高。本文將利用通配符實(shí)現(xiàn)增強(qiáng)泛型,文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2022-08-08
  • 詳解java動(dòng)態(tài)代理的2種實(shí)現(xiàn)方式

    詳解java動(dòng)態(tài)代理的2種實(shí)現(xiàn)方式

    目前Java開發(fā)包中包含了對(duì)動(dòng)態(tài)代理的支持,但是其實(shí)現(xiàn)只支持對(duì)接口的的實(shí)現(xiàn)。這篇文章主要介紹了詳解java動(dòng)態(tài)代理的2種實(shí)現(xiàn)方式 ,有興趣的可以了解一下。
    2016-11-11
  • @RequestBody時(shí)第二個(gè)字母大寫,映射不到的解決

    @RequestBody時(shí)第二個(gè)字母大寫,映射不到的解決

    這篇文章主要介紹了@RequestBody時(shí)第二個(gè)字母大寫,映射不到的解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Spring 源碼解析CommonAnnotationBeanPostProcessor

    Spring 源碼解析CommonAnnotationBeanPostProcessor

    這篇文章主要為大家介紹了Spring 源碼解析CommonAnnotationBeanPostProcessor示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • SpringBoot增強(qiáng)Controller方法@ControllerAdvice注解的使用詳解

    SpringBoot增強(qiáng)Controller方法@ControllerAdvice注解的使用詳解

    這篇文章主要介紹了SpringBoot增強(qiáng)Controller方法@ControllerAdvice注解的使用詳解,@ControllerAdvice,是Spring3.2提供的新注解,它是一個(gè)Controller增強(qiáng)器,可對(duì)controller進(jìn)行增強(qiáng)處理,需要的朋友可以參考下
    2023-10-10
  • selenium+java環(huán)境搭建過程推薦

    selenium+java環(huán)境搭建過程推薦

    這篇文章主要介紹了selenium+java環(huán)境搭建過程推薦,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • Java如何實(shí)現(xiàn)圖片的疊加與拼接操作

    Java如何實(shí)現(xiàn)圖片的疊加與拼接操作

    這篇文章主要介紹了Java如何實(shí)現(xiàn)圖片的疊加與拼接操作,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Java使用黑盒方式模擬實(shí)現(xiàn)內(nèi)網(wǎng)穿透

    Java使用黑盒方式模擬實(shí)現(xiàn)內(nèi)網(wǎng)穿透

    這篇文章主要介紹了Java使用黑盒方式模擬實(shí)現(xiàn)內(nèi)網(wǎng)穿透,內(nèi)網(wǎng)穿透,也即 NAT 穿透,進(jìn)行 NAT 穿透是為了使具有某一個(gè)特定源 IP 地址和源端口號(hào)的數(shù)據(jù)包不被 NAT 設(shè)備屏蔽而正確路由到內(nèi)網(wǎng)主機(jī),需要的朋友可以參考下
    2023-05-05
  • springboot3整合SpringSecurity實(shí)現(xiàn)登錄校驗(yàn)與權(quán)限認(rèn)證

    springboot3整合SpringSecurity實(shí)現(xiàn)登錄校驗(yàn)與權(quán)限認(rèn)證

    本文主要介紹了springboot3整合SpringSecurity實(shí)現(xiàn)登錄校驗(yàn)與權(quán)限認(rèn)證,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-04-04

最新評(píng)論