• sleuth+zipkin持久化和gateway设置跨域


    目录

    1.为什么使用sleuth+zipkin持久化

    2.使用mysql实现数据持久化

    2.1.创建数据库--省略

    2.2.创建表

    2.3.在启动ZipKin Server的时候,指定数据保存的mysql的信息

    2.4.重启一下自己的项目--省略

    2.5.访问浏览器

    3.gateway设置跨域

    3.1.设置一个跨域配置类

    3.2.设置配置文件


    1.为什么使用sleuth+zipkin持久化

    Zipkin Server默认会将追踪数据信息保存到内存,但这种方式不适合生产环境。Zipkin支持将追踪数据持久化到mysql数据库或elasticsearch中。

    2.使用mysql实现数据持久化

    2.1.创建数据库--省略

    2.2.创建表

    1. CREATE TABLE IF NOT EXISTS zipkin_spans (
    2. `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
    3. `trace_id` BIGINT NOT NULL,
    4. `id` BIGINT NOT NULL,
    5. `name` VARCHAR(255) NOT NULL,
    6. `parent_id` BIGINT,
    7. `debug` BIT(1),
    8. `start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',
    9. `duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query' )
    10. ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
    11. ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate';
    12. ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations';
    13. ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds';
    14. ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames';
    15. ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';
    16. CREATE TABLE IF NOT EXISTS zipkin_annotations (
    17. `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',
    18. `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',
    19. `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',
    20. `a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',
    21. `a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',
    22. `a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',
    23. `a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',
    24. `endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',
    25. `endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',
    26. `endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',
    27. `endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null' )
    28. ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
    29. ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate';
    30. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans';
    31. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds';
    32. ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames';
    33. ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces';
    34. ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces';
    35. ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job';
    36. CREATE TABLE IF NOT EXISTS zipkin_dependencies (
    37. `day` DATE NOT NULL,
    38. `parent` VARCHAR(255) NOT NULL,
    39. `child` VARCHAR(255) NOT NULL,
    40. `call_count` BIGINT )
    41. ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
    42. ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

    2.3.在启动ZipKin Server的时候,指定数据保存的mysql的信息

    找到自己下载的位置在地址栏输入cmd

    2.4.重启一下自己的项目--省略

    2.5.访问浏览器

     可以自己在测试一下关闭 ZipKin Server,在重新启动一下看看有没有 ,持久化错了的可能数据库的版本高

    3.gateway设置跨域

    3.1.设置一个跨域配置类

    1. @Configuration
    2. public class CorsConfig {
    3. @Bean
    4. public CorsWebFilter corsFilter() {
    5. CorsConfiguration config = new CorsConfiguration();
    6. config.addAllowedMethod("*");
    7. config.addAllowedOrigin("*");
    8. config.addAllowedHeader("*");
    9. UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
    10. source.registerCorsConfiguration("/**", config);
    11. return new CorsWebFilter(source);
    12. }
    13. }

    3.2.设置配置文件

    1. spring:
    2. cloud:
    3. gateway:
    4. globalcors:
    5. cors-configurations:
    6. '[/**]':
    7. allowedOrigins: "*"
    8. allowedMethods:
    9. - GET
    10. - POST
    11. - DELETE
    12. - PUT
    13. - OPTION

  • 相关阅读:
    linux rsyslog介绍
    淘宝/天猫获得淘宝店铺详情 API
    Spring MVC请求处理流程和九大组件
    技能学习链接
    Java 新手入门:基础知识点一览
    笔试题大疆08.07
    Allegro基本规则设置指导书之Spacing规则设置
    云计算-Linux-mv,cat,less,head,tail,rm命令学习
    使用yum安装jdk,并配置环境变量
    一、了解[mysql]索引底层结构和算法
  • 原文地址:https://blog.csdn.net/ne_123456/article/details/126488877