Tomcat学习总结(18)—— Tomcat启动时org.apache.catalina.util.SessionIdGenerator产生安全随机类SecureRandom的实例慢问题解决

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://zhanghaiyang.blog.csdn.net/article/details/80818627

Tomcat7/8使用org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom类产生安全随机类SecureRandom的实例作为会话ID。


SHA1PRNG算法是基于SHA-1算法实现且保密性较强的伪随机数生成器。
在SHA1PRNG中,有一个种子产生器,它根据配置执行各种操作。
1)如果Java.security.egd 属性或securerandom.source属性指定的是”file:/dev/random”或”file:/dev/urandom”,那么JVM 会使用本地种子产生器NativeSeedGenerator,它会调用super()方法,即调用 SeedGenerator.URLSeedGenerator(/dev/random)方法进行初始化。
2)如果java.security.egd属性或securerandom.source属性指定的是其它已存在的URL,那么会调用SeedGenerator.URLSeedGenerator(url)方法进行初始化。
这就是为什么我们设置值为”file:///dev/urandom”或者值为”file:/./dev/random”都会起作用的原因。
在这个实现中,产生器会评估熵池(entropy pool)中的噪声数量。随机数是从熵池中进行创建的。当读操作时,/dev/random设备会只返回熵池中噪声的随机字节。/dev/random非常适合那些需要非常高质量随机性的场景,比如一次性的支付或生成密钥的场景。
当熵池为空时,来自/dev/random的读操作将被阻塞,直到熵池收集到足够的环境噪声数据。这么做的目的是成为一个密码安全的伪随机数发生器,熵池要有尽可能大的输出。对于生成高质量的加密密钥或者是需要长期保护的场景,一定要这么做。
那么什么是环境噪声?
随机数产生器会收集来自设备驱动器和其它源的环境噪声数据,并放入熵池中。产生器会评估熵池中的噪声数据的数量。当熵池为空时,这个噪声数据的收集是比较花时间的。这就意味着,Tomcat在生产环境中使用熵池时,会被阻塞较长的时间。
解决
1)在Tomcat环境中解决
可以通过配置JRE使用非阻塞的Entropy Source。
在catalina.sh中加入这么一行:-Djava.security.egd=file:/dev/./urandom 即可。
加入后再启动Tomcat,整个启动耗时下降到Server startup in 2912 ms。

2)在JVM环境中解决
打开$JAVA_PATH/jre/lib/security/java.security这个文件,找到下面的内容:
securerandom.source=file:/dev/urandom
替换成
securerandom.source=file:/dev/./urandom
展开阅读全文

tomcat 启动时,过滤器类报错

02-21

2008-2-21 4:05:44 org.apache.catalina.core.AprLifecycleListener lifecycleEventrn信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_06\bin;D:\apache-tomcat-5.5.25\bin;C:\Documents and Settings\Administrator\桌面\publicrn2008-2-21 4:05:45 org.apache.coyote.http11.Http11BaseProtocol initrn信息: Initializing Coyote HTTP/1.1 on http-8080rn2008-2-21 4:05:45 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 3484 msrn2008-2-21 4:05:45 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2008-2-21 4:05:45 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/5.5.25rn2008-2-21 4:05:45 org.apache.catalina.core.StandardHost startrn信息: XML validation disabledrn2008-2-21 4:05:51 org.apache.catalina.core.ApplicationContext logrn信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]rn2008-2-21 4:05:52 org.apache.catalina.core.ApplicationContext logrn信息: ContextListener: contextInitialized()rn2008-2-21 4:05:52 org.apache.catalina.core.ApplicationContext logrn信息: SessionListener: contextInitialized()rn2008-2-21 4:05:52 org.apache.catalina.core.ApplicationContext logrn信息: ContextListener: contextInitialized()rn2008-2-21 4:05:52 org.apache.catalina.core.ApplicationContext logrn信息: SessionListener: contextInitialized()rn2008-2-21 4:06:04 org.apache.catalina.core.StandardContext filterStartrn严重: Exception starting filter filter1rnjava.lang.ClassNotFoundException: com.sjz.common.filter.EncodingFilterrn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1362)rn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1208)rn at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:207)rn at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:302)rn at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:78)rn at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3635)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4222)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:448)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:552)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)rn2008-2-21 4:06:04 org.apache.catalina.core.StandardContext startrn严重: Error filterStartrn2008-2-21 4:06:04 org.apache.catalina.core.StandardContext startrn严重: Context [/xinzhucheng] startup failed due to previous errorsrn2008-2-21 4:06:05 org.apache.coyote.http11.Http11BaseProtocol startrn信息: Starting Coyote HTTP/1.1 on http-8080rn2008-2-21 4:06:07 org.apache.jk.common.ChannelSocket initrn信息: JK: ajp13 listening on /0.0.0.0:8009rn2008-2-21 4:06:07 org.apache.jk.server.JkMain startrn信息: Jk running ID=0 time=0/313 config=nullrn2008-2-21 4:06:07 org.apache.catalina.storeconfig.StoreLoader loadrn信息: Find registry server-registry.xml at classpath resourcern2008-2-21 4:06:08 org.apache.catalina.startup.Catalina startrn信息: Server startup in 23500 msrn 论坛

没有更多推荐了,返回首页