linux系统(CentOS7)下安装tomcat8及加载缓慢处理

一、下载tomcat

地址奉上

二、linux下安装

1.使用SecureCRT终端连接服务器

2.使用sftp Session上传tomcat压缩包到服务器上

3.使用tar -zxvf 命令解压tomcat

4.进入bin目录启动tomcat(./startup.sh)

5.打开浏览器访问服务器toncat发现不能访问,此时需要把8080端口放开

1
2
firewall-cmd --permanent --zone=public --add-port=8080/tcp  //生效永久
firewall-cmd --reload //重新读取配置

6.打开浏览器访问服务器地址:8080,安装完成

三、有的服务器会出现tomcat访问一直加载的问题,处理方式如下

原因

在一次CentOS 7系统中安装Tomcat,启动过程很慢,需要几分钟,经过查看日志,发现耗时在这里:是session引起的随机数问题导致的。Tocmat的Session ID是通过SHA1算法计算得到的,计算Session ID的时候必须有一个密钥。为了提高安全性Tomcat在启动的时候会随机生成一个密钥。

1
2
3
4
5
11-Jan-2019 12:54:56.797 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /application/apache-tomcat-8.0.27/webapps/manager
11-Jan-2019 12:54:56.848 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /application/apache-tomcat-8.0.27/webapps/manager has finished in 51 ms
11-Jan-2019 12:54:56.864 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
11-Jan-2019 12:54:56.873 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
11-Jan-2019 12:54:56.874 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 34487 m

方案1:修改jre的安全配置策略

1
2
3
4
vim $JAVA_HOME/jre/lib/security/java.security
securerandom.source=file:/dev/random
改为
securerandom.source=file:/dev/urandom

方案2:修改tomcat启动配置文件

1
2
3
4
vim $TOMCAT_HOME/bin/catalina.sh
if [[ "$JAVA_OPTS" != *-Djava.security.egd=* ]]; then
JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/urandom"
fi

方案3:安装熵服务,增大熵

1
2
yum install rng-tools # 安装rngd服务(熵服务,增大熵池)
systemctl start rngd # 启动服务

本文参考:https://blog.csdn.net/arjelarxfc/article/details/80889535