netty_transport_native_epoll cannot be loaded from java.library.path, now trying export to -Dio.netty.native.workdir:


背景

按照尚硅谷周陽老師的springcloud系列課程敲代碼,然后部署到linux,日志級別改成debug看到以下錯誤

.NativeLibraryLoader - netty_transport_native_epoll cannot be loaded from java.library.path, now trying export to -Dio.netty.native.workdir: /tmp
java.lang.UnsatisfiedLinkError: no netty_transport_native_epoll in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
        at java.lang.Runtime.loadLibrary0(Runtime.java:871)
        at java.lang.System.loadLibrary(System.java:1124)
        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:351)
        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:136)
        at io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:253)
        at io.netty.channel.epoll.Native.<clinit>(Native.java:69)
        at io.netty.channel.epoll.Epoll.<clinit>(Epoll.java:39)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at reactor.netty.resources.DefaultLoopEpoll.<clinit>(DefaultLoopEpoll.java:96)
        at reactor.netty.resources.DefaultLoopNativeDetector.<clinit>(DefaultLoopNativeDetector.java:35)
        at reactor.netty.resources.LoopResources.hasNativeSupport(LoopResources.java:332)
        at reactor.netty.resources.LoopResources.preferNative(LoopResources.java:273)
        at reactor.netty.resources.DefaultLoopResources.onServerSelect(DefaultLoopResources.java:149)
        at reactor.netty.tcp.TcpResources.onServerSelect(TcpResources.java:256)
        at reactor.netty.tcp.TcpServerRunOn.configure(TcpServerRunOn.java:53)
        at reactor.netty.tcp.TcpServerRunOn.configure(TcpServerRunOn.java:43)
        at reactor.netty.tcp.TcpServerBootstrap.configure(TcpServerBootstrap.java:39)
        at reactor.netty.tcp.TcpServerBootstrap.configure(TcpServerBootstrap.java:39)
        at reactor.netty.tcp.TcpServerBootstrap.configure(TcpServerBootstrap.java:39)
        at reactor.netty.tcp.TcpServerBootstrap.configure(TcpServerBootstrap.java:39)
        at reactor.netty.tcp.TcpServerChannelGroup.configure(TcpServerChannelGroup.java:44)
        at reactor.netty.tcp.TcpServerBootstrap.configure(TcpServerBootstrap.java:39)
        at reactor.netty.tcp.TcpServerBootstrap.configure(TcpServerBootstrap.java:39)
        at reactor.netty.tcp.TcpServer.bind(TcpServer.java:165)

作為強迫症患者,看到這個想動手改改,於是找到以下文字

Since 1.2.2 netty engine is trying to initialize native transport is available with fallback to NIO implementation.

This is not an error. The problem is that you have wrong logger configuration so you see netty debug log.

解決方法

筆者使用的Springcloud版本比較高,2.3.4.RELASE,mvn package打包后看到netty版本是4.1.52.Final,在項目添加依賴

netty目前支持macOS/BSD、Linux內核的調優,大家需要根據自己部署的服務器CPU架構類型選擇相應的包。

執行以下命令

uname -m

 

 

 筆者部署在華為雲鯤鵬雲arm架構,所有要使用linux-aarch64,如果是普通X86架構cpu使用linux-x86_64(默認打包用linux-x86-64)

<dependency>
     <groupId>io.netty</groupId>
     <artifactId>netty-transport-native-epoll</artifactId>
     <version>4.1.52.Final</version>
     <classifier>linux-aarch64</classifier>
</dependency>

打開jar包確認,如果有以下包說明打包成功

 

查看日志

grep -in native

 

 以上說明加載成功

 

 

 參考

https://github.com/ktorio/ktor/issues/1203

https://netty.io/wiki/native-transports.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM