使用spring boot2和spring cloud finchley 升级zipkin踩到的坑

最近希望将现有系统升级到springboot2和spring cloud Finchley ,在升级过程中踩到zipkin的几个坑,记录一下和大家分享。

在使用 Spring Boot 2.x 版本后,官方就不推荐自行定制编译了,让我们直接使用编译好的 jar 包

也就是说原来通过@EnableZipkinServer或@EnableZipkinStreamServer的路子,启动SpringBootApplication自建Zipkin Server是不行了。Spring Cloud Finchley官方文档中直接让我们去参考旧版本的Dalson的文档。

61. Zipkin Stream Span Consumer
[Important] Important
We recommend using Zipkin’s native support for message-based span sending. Starting from the Edgware release, the Zipkin Stream server is deprecated. In the Finchley release, it got removed.

If for some reason you need to create the deprecated Stream Zipkin server, see the Dalston Documentation.

so,只能写shell直接独立启动zipkin-server了。

编写bat脚本,启动zipkin,存储我使用的是elasticsearch

@ECHO OFF
set RABBIT_ADDRESSES=120.26.57.73:5672
set RABBIT_USER=wmzx
set RABBIT_PASSWORD=wmzx@804
set STORAGE_TYPE=elasticsearch
set ES_HOSTS=http://118.178.241.128:9400
set ES_USERNAME=elastic
set ES_PASSWORD=wmzx@804
set ES_INDEX=zipkin
::windows 10 64bit版本,默认参数启动zipkin server 会报错,Native memory allocation (malloc) failed to allocate 360816 bytes for Chunk::new
::需要增加ReservedCodeCacheSize大小
::linux shell暂未尝试
set JAVA_OPTS="-XX:ReservedCodeCacheSize=64m" 
java -jar zipkin-server-2.9.4-exec.jar

开始一直无法启动,一直OOM,然后jvm崩溃。根据hs_err日志文件,尝试修改-Xss -Xms -XX:Metaspace=128m -XX:MaxMetaspaceSize=256m 均无效。

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 360816 bytes for Chunk::new
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=

最后-XX:ReservedCodeCacheSize=32m,将默认值32m修改为64m,启动完成。

zipkin的环境变量

通过命令行启动,需要手动设置zipkin的收集器和存储的环境变量。查了一下github,这里也搬运记录一下吧。

RabbitMQ Collector环境变量配置

PropertyEnvironment VariableDescription
zipkin.collector.rabbitmq.concurrencyRABBIT_CONCURRENCYNumber of concurrent consumers. Defaults to 1
zipkin.collector.rabbitmq.connection-timeoutRABBIT_CONNECTION_TIMEOUTMilliseconds to wait establishing a connection. Defaults to 60000 (1 minute)
zipkin.collector.rabbitmq.queueRABBIT_QUEUEQueue from which to collect span messages. Defaults to zipkin
zipkin.collector.rabbitmq.uriRABBIT_URIRabbitMQ URI spec-compliant URI, ex. amqp://user:pass@host:10000/vhost

如果通过URI设置,可以使用下面的环境变量。

PropertyEnvironment VariableDescription
zipkin.collector.rabbitmq.addressesRABBIT_ADDRESSESComma-separated list of RabbitMQ addresses, ex. localhost:5672,localhost:5673
zipkin.collector.rabbitmq.passwordRABBIT_PASSWORDPassword to use when connecting to RabbitMQ. Defaults to guest
zipkin.collector.rabbitmq.usernameRABBIT_USERUsername to use when connecting to RabbitMQ. Defaults to guest
zipkin.collector.rabbitmq.virtual-hostRABBIT_VIRTUAL_HOSTRabbitMQ virtual host to use. Defaults to /
zipkin.collector.rabbitmq.use-sslRABBIT_USE_SSLSet to true to use SSL when connecting to RabbitMQ

Elasticsearch 存储的环境变量设置

生产环境用Elasticsearch 做存储还是很方便的。

* `ES_HOSTS`: A comma separated list of elasticsearch base urls to connect to ex. http://host:9200.
              Defaults to "http://localhost:9200".
* `ES_PIPELINE`: Only valid when the destination is Elasticsearch 5+. Indicates the ingest
                 pipeline used before spans are indexed. No default.
* `ES_TIMEOUT`: Controls the connect, read and write socket timeouts (in milliseconds) for
                Elasticsearch Api. Defaults to 10000 (10 seconds)
* `ES_MAX_REQUESTS`: Only valid when the transport is http. Sets maximum in-flight requests from
                     this process to any Elasticsearch host. Defaults to 64.
* `ES_INDEX`: The index prefix to use when generating daily index names. Defaults to zipkin.
* `ES_DATE_SEPARATOR`: The date separator to use when generating daily index names. Defaults to '-'.
* `ES_INDEX_SHARDS`: The number of shards to split the index into. Each shard and its replicas
                     are assigned to a machine in the cluster. Increasing the number of shards
                     and machines in the cluster will improve read and write performance. Number
                     of shards cannot be changed for existing indices, but new daily indices
                     will pick up changes to the setting. Defaults to 5.
* `ES_INDEX_REPLICAS`: The number of replica copies of each shard in the index. Each shard and
                       its replicas are assigned to a machine in the cluster. Increasing the
                       number of replicas and machines in the cluster will improve read
                       performance, but not write performance. Number of replicas can be changed
                       for existing indices. Defaults to 1. It is highly discouraged to set this
                       to 0 as it would mean a machine failure results in data loss.
* `ES_USERNAME` and `ES_PASSWORD`: Elasticsearch basic authentication, which defaults to empty string.
                                   Use when X-Pack security (formerly Shield) is in place.
* `ES_HTTP_LOGGING`: When set, controls the volume of HTTP logging of the Elasticsearch Api.
                     Options are BASIC, HEADERS, BODY

Example usage:

$ STORAGE_TYPE=elasticsearch ES_HOSTS=http://myhost:9200 java -jar zipkin.jar

MySQL存储环境变量

很多大佬的教程都是用mysql存储zipkin收集的链路信息,mysql的配置如下:

* `MYSQL_DB`: The database to use. Defaults to "zipkin".
* `MYSQL_USER` and `MYSQL_PASS`: MySQL authentication, which defaults to empty string.
* `MYSQL_HOST`: Defaults to localhost
* `MYSQL_TCP_PORT`: Defaults to 3306
* `MYSQL_MAX_CONNECTIONS`: Maximum concurrent connections, defaults to 10
* `MYSQL_USE_SSL`: Requires `javax.net.ssl.trustStore` and `javax.net.ssl.trustStorePassword`, defaults to false.

Example usage:

$ STORAGE_TYPE=mysql MYSQL_USER=root java -jar zipkin.jar

结语

好了,目前升级到运行阶段就踩了这些坑。后面使用中发现问题,再继续写吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值