blog.zhuohua.store's Archiver

admin 发表于 2019-9-6 21:20

CentOS6安装两个Tomcat

笺注:实验是在 [url=http://blog.zhuohua.store/viewthread.php?tid=55&extra=page%3D1]Tomcat+JDK+MySQL[/url] 的基础上做的


第一个Tomcat使用TCP 80端口
第二个Tomcat使用TCP 8082端口

第一个Tomcat的目录为/usr/local/tomcat
第二个Tomcat的目录为/usr/local/tomcat2





[root@localhost ~]# vi /etc/profile
在最后追加:

##########first tomcat###########
CATALINA_BASE=/usr/local/tomcat
CATALINA_HOME=/usr/local/tomcat
TOMCAT_HOME=/usr/local/tomcat
export CATALINA_BASE CATALINA_HOME TOMCAT_HOME
##########first tomcat############
笺注:/usr/local/tomcat 为第一个Tomcat的目录


##########second tomcat##########
CATALINA_2_BASE=/usr/local/tomcat2
CATALINA_2_HOME=/usr/local/tomcat2
TOMCAT_2_HOME=/usr/local/tomcat2
export CATALINA_2_BASE CATALINA_2_HOME TOMCAT_2_HOME
##########second tomcat##########
笺注:/usr/local/tomcat2 为第二个Tomcat的目录


效果:
[attach]9955[/attach]


使环境变量生效:
[root@localhost ~]# source /etc/profile


复制第一个Tomcat的目录为第二个Tomcat的目录:
[root@localhost ~]# cp -rfp /usr/local/tomcat/ /usr/local/tomcat2




### 修改第一个Tomcat的默认端口:( 8080 改为80 )
[root@localhost ~]# vi /usr/local/tomcat/conf/server.xml
[attach]9956[/attach]
修改为:
[attach]9957[/attach]









#########
修改第二个Tomcat的catalina.sh
[root@localhost ~]# vi /usr/local/tomcat2/bin/catalina.sh
增加:(注意命令的位置,效果如下图)
export CATALINA_BASE=$CATALINA_2_BASE
export CATALINA_HOME=$CATALINA_2_HOME
[attach]9958[/attach]



修改第二个Tomcat的server.xml
[root@localhost ~]# vi /usr/local/tomcat2/conf/server.xml

-->
<Server port="[color=DarkRed]9005[/color]" shutdown="SHUTDOWN"> [color=DarkRed]#8005改为9005[/color]
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

###########

-->
    <Connector port="[color=DarkRed]8082[/color]" protocol="HTTP/1.1" [color=DarkRed]#8080改为8082[/color]
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="utf-8" />

###########

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="[color=DarkRed]9009[/color]" protocol="AJP/1.3" redirectPort="8443" /> [color=DarkRed]#8009改为9009[/color]


笺注:上面修改的三个端口号不是固定的,只要不重复即可






插入防火墙规则:
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 8082 -j ACCEPT

保存防火墙规则:
iptables-save > /etc/sysconfig/iptables





重启第一个Tomcat:
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh

重启第二个Tomcat:
/usr/local/tomcat2/bin/shutdown.sh
/usr/local/tomcat2/bin/startup.sh


在系统开启的时候自动开启两个Tomcat:
[root@localhost ~]# cat /etc/rc.local |grep -v '^#'
touch /var/lock/subsys/local
[color=Purple]export JAVA_HOME=/usr/local/jdk[/color]
[color=Blue]/usr/local/tomcat/bin/startup.sh
/usr/local/tomcat2/bin/startup.sh[/color]






查看java进程:(有两个Tomcat,所以有两个进程)
[root@localhost ~]# ps -ef |grep java
root       [color=Purple]1969[/color]      1  2 05:21 pts/1    00:00:07 /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root       [color=Purple]2050[/color]      1  2 05:21 pts/1    00:00:07 /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/tomcat2/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/local/tomcat2/bin/bootstrap.jar:/usr/local/tomcat2/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat2 -Dcatalina.home=/usr/local/tomcat2 -Djava.io.tmpdir=/usr/local/tomcat2/temp org.apache.catalina.startup.Bootstrap start
root       2103   1716  0 05:27 pts/1    00:00:00 grep java






在第一个Tomcat的默认网站根目录下创建测试页:
[root@localhost ~]# vi /usr/local/tomcat/webapps/ROOT/1.jsp

<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>第一个Tomcat</title>
</head>
<body>
    <center>第一个Tomcat,现在时间: <%=new java.util.Date()%></center>
</body>
</html>





在第二个Tomcat的默认网站根目录下创建测试页:
[root@localhost ~]# vi /usr/local/tomcat2/webapps/ROOT/2.jsp

<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>第二个Tomcat</title>
</head>
<body>
    <center>第二个Tomcat,现在时间: <%=new java.util.Date()%></center>
</body>
</html>







服务器本地测试:

[root@localhost ~]# yum -y install elinks

[root@localhost ~]# elinks 127.0.0.1:80/1.jsp
[attach]9959[/attach]


[root@localhost ~]# elinks 127.0.0.1:8082/2.jsp
[attach]9960[/attach]





客户端远程测试:

http://192.168.168.131/1.jsp
[attach]9961[/attach]


http://192.168.168.131:8082/2.jsp
[attach]9962[/attach]












######################

以防关闭系统时卡死,最好先杀死java进程,再关闭、重启服务器

[root@localhost ~]# killall -9 java
[root@localhost ~]#
[root@localhost ~]# ps -ef |grep java
root       2124   1716  0 05:32 pts/1    00:00:00 grep java
[root@localhost ~]#


重启服务器:
[root@localhost ~]# reboot




相关文章:
[url=http://blog.zhuohua.store/viewthread.php?tid=303&extra=page%3D1]Nginx基于域名的虚拟主机+两个Tomcat[/url]





#################################
#################################
[url=https://weidian.com/?userid=823531601&wfr=wx&sfr=app&source=shop]亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^[/url]

[url=https://weidian.com/item.html?itemID=905482571143072712221&wfr=wx&sfr=app&source=goods_home]FaSoLa户外便携吊床秋千室内单双人大学生宿舍家用成人儿童睡觉椅[/url]
[url=https://weidian.com/item.html?itemID=905482571143072712221&wfr=wx&sfr=app&source=goods_home][attach]4064[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571143388419032&wfr=wx&sfr=app&source=goods_home]FaSoLa 旅行晾衣架 旅游便携式折叠衣架出差多功能衣挂小撑子晾晒[/url]
[url=https://weidian.com/item.html?itemID=905482571143388419032&wfr=wx&sfr=app&source=goods_home][attach]4065[/attach][/url]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.