Linux下安装两个或多个tomcat

编辑环境变量:vi /etc/profile
加入以下代码(tomcat路径要配置自己实际的tomcat安装目录)
##########first tomcat###########
CATALINA_BASE= /usr/local/tomcat7
CATALINA_HOME= /usr/local/tomcat7
TOMCAT_HOME= /usr/local/tomcat7
export CATALINA_BASE CATALINA_HOME TOMCAT_HOME
##########first tomcat############
##########second tomcat##########
CATALINA_2_BASE= /usr/local/tomcat7_2
CATALINA_2_HOME= /usr/local/tomcat7_2
TOMCAT_2_HOME= /usr/local/tomcat7_2
export CATALINA_2_BASE CATALINA_2_HOME TOMCAT_2_HOME
##########second tomcat##########
保存退出。
再输入:source /etc/profile 使之生效。
 
第一个tomcat,保持解压后的原状不用修改, 
 

复制第一个tomcat下的内容到第二个下面 cp -R tomcat7/* tomcat7_2/

来到第二个tomcat的bin目录下

打开catalina.sh ,找到下面红字,

在命令模式下 /OS specific support.  

 # OS specific support.  $var _must_ be set to either true or false.

在下面增加如下代码

export CATALINA_BASE=$CATALINA_2_BASE
export CATALINA_HOME=$CATALINA_2_HOME

 
来到第二个tomcat的conf目录下
打开server.xml更改端口:
修改server.xml配置和第一个不同的启动、关闭监听端口。
修改后示例如下:
  <Server port="8006" shutdown="SHUTDOWN">                端口:8005->8006
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector port="8081" maxHttpHeaderSize="8192"        端口:8080->8081
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="9010"                                  端口:8009->9010
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
 
 
分别进入两个tomcat的bin目录,
启动tomcat: ./startup.sh

然后访问http://localhost:8080 和 http://localhost:8081都可以看到熟悉的tomcat欢迎界面。

如果想启动多个可以依此法类推……

遇到第二个tomcat卡很久的问题 

原文地址:https://blog.csdn.net/njchenyi/article/details/46641141

第一次遇到Tomcat在Linux服务器启动卡住的情况,情况很简单,tomcat启动以后卡在INFO: Deploying web application directory ......这句话,具体会卡多久就没测试了。google、baidu都没找到解决方法。

幸亏UCloud的技术支持人员给出了解决方案。

找到jdk1.x.x_xx/jre/lib/security/java.security文件,在文件中找到securerandom.source这个设置项,将其改为:

securerandom.source=file:/dev/./urandom

这时候根据修改内容就可以查到因为此原因不仅可以造成tomcat卡住,也会造成weblogic启动缓慢,


linux或者部分unix系统提供随机数设备是/dev/random 和/dev/urandom ,两个有区别,urandom安全性没有random高,但random需要时间间隔生成随机数。jdk默认调用random。


再后来,终于在weblogic的官方文档中 Monitoring and Troubleshooting 找到了 Avoiding JVM Delays Caused By Random Number Generation 这样一个标题。摘录如下:

The library used for random number generation in Sun's JVM relies on /dev/random by default for UNIX platforms. This can potentially block the Oracle WebLogic Communication Services process because on some operating systems /dev/random waits for a certain amount of "noise" to be generated on the host machine before returning a result. Although /dev/random is more secure, Oracle recommends using /dev/urandom if the default JVM configuration delays Oracle WebLogic Communication Services startup.

To determine if your operating system exhibits this behavior, try displaying a portion of the file from a shell prompt:

head -n 1 /dev/random
Open the $JAVA_HOME/jre/lib/security/java.security file in a text editor.

Change the line:

securerandom.source=file:/dev/random
to read:

securerandom.source=file:/dev/urandom
Save your change and exit the text editor.
其中说到:可通过 head -n 1 /devrandom 查看是否你的系统会出现伪随机数提供等待。OK就这个,试了一下,果然,在服务器第一次启动后,这个可以快速提供一个值,但当再次调用时发生等待。


解决办法:


永久:oracle 说修改 $JAVA_HOME/jre/lib/security/java.security 文件,替换securerandom.source=file:/dev/random 为 securerandom.source=file:/dev/urandom。对所有使用JVM的应用生效。(这个永久的方法,这里面有个问题,就是设置时候实际应该设置为securerandom.source=file:/dev/./urandom,否则不生效)


DOMAIN临时:修改startWeblogic.sh文件,JAVA_OPTIONS="${SAVE_JAVA_OPTIONS} -Djava.security.egd=file:/dev/./urandom"


后继的SecureRandom 测试学习


编写JAVA类如下,运行测试,第一次正常,第二次等待,重启服务器后第一次又正常。启动加入参数 -Djava.security.egd=file:/dev/./urandom 正常





猜你喜欢

转载自blog.csdn.net/liwb94/article/details/79986648