1.前言
当你读到这篇文章的时候,想必也被这个问题折磨了好久,同时我敢肯定的是,你也一定是内网开发,我甚至连镜像源都没有,只能一个一个下载,手动安装,但是再大的困难,只要遇到了执着的我们,便都能得到解决。
2.问题描述
项目测试环境是使用docker部署的,jdk采用的是openjdk,当kafka使用无密码方式连接时可以正常连接,后来,搭建kafka的人出于安全的考虑,给kafka加了密码,这时候采用SASL_PLAINTEXT安全方式连接,此时在本地和linux环境部署都是没有问题的,但是一旦使用docker部署时,由于alpine镜像少了kafka密码认证需要的运行环境,导致项目无法启动。
错误(由于内网,无法粘贴,手打了下面一部分):
org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry':nested exception is org.apache.kafka.comnon.KafkaException:Failed to construct kafka consumer at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ... Caused by: org.apache.kafka.common.kafkaException: Failed to construct kafka consumer ... Caused by: org.apache.kafka.common.KafkaException:java.lang.ExceptionInInitializerError ... Caused by: java.lang.ExceptionInInitializerError:null ... Caused by:java.security.ProviderException:Could not initialize NSS ... Caused by: java.io.FileNotFoundException:/usr/lib/libnss3.so at sun.security.pkcs11.Secmod.initialize(Secmod.java:193) at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.JAVA:218)
3.解决方案
手动下载musl-1.2.3-r0.apk,nspr-4.33-r0.apk,nss-3.78.1-r0.apk,sqlite-libs-3.38.5-r0.apk这四个包。
在dockerfile中添加
FROM openjdk8:v1 COPY nss-3.78.1-r0.apk /tmp/nss-3.78.1-r0.apk COPY musl-1.2.3-r0.apk /tmp/musl-1.2.3-r0.apk COPY nspr-4.33-r0.apk /tmp/nspr-4.33-r0.apk COPY sqlite-libs-3.38.5-r0.apk /tmp/sqlite-libs-3.38.5-r0.apk RUN apk add --allow-untrusted --no-network /tmp/sqlite-libs-3.38.5-r0.apk /tmp/musl-1.2.3-r0.apk /tmp/nspr-4.33-r0.apk /tmp/sqlite-libs-3.38.5-r0.apk ADD target/*.jar /app.jar EXPOSE 6688 ENTRYPOINT [ "java","-jar","/app.jar","--spring.profiles.active=test","&"]
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280850.html