Tomcat集群
安装环境:CentOS 6.6(64位系统)
--查看并卸载已经安装JDK的版本
[xju@xjuCentOS 桌面]$ su root
密码:
[root@xjuCentOS 桌面]# rpm -qa|grep jdk
java-1.7.0-openjdk-1.7.0.9-2.3.4.1.el6_3.i686
java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.i686
[root@xjuCentOS 桌面]# rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.i686
[root@xjuCentOS 桌面]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.9-2.3.4.1.el6_3.i686
# chmod 777 jdk-7u79-linux-i586.rpm
# rpm -ivh jdk-7u79-linux-i586.rpm
--配置java环境变量
--修改/etc/profile文件, 全局变量,可能会给系统带来安全性问题;修改.bash_profile文件,这种方法更为安全,它可以把使用这些环境变量的权限控制到用户级别,如果你需要给某个用户权限使用这些环境变量,你只需要修改其个人用户主目录下的.bash_profile文件就可以了。
--备份配置文件
#cp /etc/profile /etc/profile.bak
--编辑配置文件(在最后追加如下内容)
# vi /etc/profile
#Set Java Environment
export JAVA_HOME=/usr/java/jdk1.7.0_79
export PATH=$PATH:$JAVA_HOME/bin
--重新加载配置文件
#source /etc/profile
或者:
# vi /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.7.0_79
export PATH=$PATH:$JAVA_HOME/bin
--查看安装的jdk版本信息
#java -version
#javac -version
-- 用文本编辑器新建一个Test.java文件,在其中输入以下代码并保存:
public class Test {
public static void main(String args[]) {
System.out.println("Hello,Java !");
}
}
--编译
#javac Test.java
--运行
#java Test
# tar -zxvf apache-tomcat-7.0.62.tar.gz
# cp -rf apache-tomcat-7.0.62 /usr/local/tomcat1
# mv apache-tomcat-7.0.62 /usr/local/tomcat2
# chown -R xju:xju /usr/local/tomcat1
# chown -R xju:xju /usr/local/tomcat2
(1)修改tomcat1端口号
$ cd /usr/local/tomcat1/conf/
$ cp server.xml server.xml.bak
$ cp web.xml web.xml.bak
$ vi server.xml
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1" >
(2)修改tomcat2端口号
$ cd /usr/local/tomcat2/conf/
$ cp server.xml server.xml.bak
$ cp web.xml web.xml.bak
$ vi server.xml
<Server port="8006" shutdown="SHUTDOWN">
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2" >
Tomcat默认端口备注:
8005:表示用于停止Tomcat的端口
8080:表示HTTP连接端口
8009:表示Apache的侦听端口
8443:表示SSL的连接端口
--启动tomcat1
# cd /usr/local/tomcat1/bin
#./startup.sh--启动
#./shutdown.sh --关闭
Using CATALINA_BASE: /usr/local/tomcat1
Using CATALINA_HOME: /usr/local/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomcat1/temp
Using JRE_HOME: /usr/java/jdk1.7.0_79/jre/
Using CLASSPATH: /usr/local/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar
Tomcat started.
(1)将tomcat1设置开机自启动
将/usr/local/tomcat1/bin/catalina.sh文件复制到/etc/init.d目录下并改名为tomcat1
# cp /usr/local/tomcat1/bin/catalina.sh /etc/init.d/tomcat1
修改/etc/init.d/tomcat1文件,在文件中添加为红色部分:
# vi /etc/init.d/tomcat1
在第一行下面输入如下内容(否则出现错误:tomcat 服务不支持 chkconfig):
#!/bin/sh
# chkconfig: 2345 10 90
# description:Tomcat1 service
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
.....................................................................
# $Id: catalina.sh 1498485 2013-07-01 14:37:43Z markt $
# -----------------------------------------------------------------------------
CATALINA_HOME=/usr/local/tomcat1
JAVA_HOME=/usr/java/jdk1.7.0_79
# OS specific support. $var _must_ be set to either true or false.
--添加tomcat服务:
# chkconfig --add tomcat1
--设置tomcat为开机自启动:
# chkconfig tomcat1 on
--关闭和启动tomcat 服务,由此生成的tomcat没有重启命令:
# service tomcat1 stop
# service tomcat1 start
(2)将tomcat1设置开机自启动
将/usr/local/tomcat2/bin/catalina.sh文件复制到/etc/init.d目录下并改名为tomcat2
# cp /usr/local/tomcat2/bin/catalina.sh /etc/init.d/tomcat2
修改/etc/init.d/tomcat2文件,在文件中添加为红色部分:
# vi /etc/init.d/tomcat2
在第一行下面输入如下内容(否则出现错误:tomcat 服务不支持 chkconfig):
#!/bin/sh
# chkconfig: 2345 10 90
# description:Tomcat2 service
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
.....................................................................
# $Id: catalina.sh 1498485 2013-07-01 14:37:43Z markt $
# -----------------------------------------------------------------------------
CATALINA_HOME=/usr/local/tomcat2
JAVA_HOME=/usr/java/jdk1.7.0_79
# OS specific support. $var _must_ be set to either true or false.
--添加tomcat服务:
# chkconfig --add tomcat2
--设置tomcat为开机自启动:
# chkconfig tomcat2 on
--关闭和启动tomcat 服务,由此生成的tomcat没有重启命令:
# service tomcat2 stop
# service tomcat2 start
# cd /usr/local/tomcat/
原文地址:http://qing0991.blog.51cto.com/1640542/1657294