现象
生产环境(centos7,jdk8)中tomcat启动非常缓慢,几分钟才能启动
解决
- 方式1:修改%JRE_HOME%/lib/security/java.security文件:
修改前:securerandom.source=file:/dev/random 修改后:securerandom.source=file:/dev/./urandom - 方式二:追加java启动参数
$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom
原因分析
关键字
- tomcat启动优化
- tomcat的
sessionId及其它随机数的生成, 通过java.security.SecureRandom生成随机数来实现,随机数算法使用的是SHA1PRNG /dev/random, 阻塞的随机数发生器/dev/urandom, 非阻塞的随机数发生器- 伪随机数发生器:
- 熵池
- 密码安全学
参考
- 参考1:https://wiki.apache.org/tomcat/HowTo/FasterStartUp

- 参考2:http://hongjiang.info/jvm-random-and-entropy-source/
扩展:linux生成随机数
cat /dev/urandom | head -n 10 | md5sum | head -c 10 #c61adce3e4
cat /dev/urandom | strings -n 8 | head -n 1 #生成全字符的随机字符串,fLqF!lSB)
cat /dev/urandom | sed -e 's/[^a-zA-Z0-9]//g' | strings -n 8 | head -n 1 #生成数字加字母的随机字符串,HRZuXFMb 其中 strings -n设置字符串的字符数,head -n设置输出的行数