标签:
1、软件准备
http://pan.baidu.com/s/1bW6qi6
jdk下载: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Tomcat下载: http://tomcat.apache.org/
2、安装jdk,部署Java环境
卸载默认安装的jdk
1 2 3 4 |
cd /opt/tomcat/ yum -y remove `rpm -qa | grep jdk` rpm -ivh jdk-7u40-linux-x64.rpm |
出现下面的结果表示jdk安装成功
1 2 3 4 5 |
[root@hall tomcat]# java -version java version "1.7.0_40" Java(TM) SE Runtime Environment (build 1.7.0_40-b43) Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode) [root@hall tomcat]# |
3、安装Tomcat7
3.1、单实例安装
(1)拷贝代码
1 |
[root@hall tomcat]# tar -zxf apache-tomcat-7.0.42.tar.gz [root@hall tomcat]# cp -r apache-tomcat-7.0.42 /usr/local/tomcat7 |
(2)配置环境变量
1 2 3 4 5 6 |
[root@localhost usr]# vi /etc/profile export JAVA_HOME=/usr/java/jdk1.7.0_40 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib export CATALINA_HOME=/usr/local/tomcat7 export PATH=$PATH:$JAVA_HOME/bin |
1 |
[root@localhost ~]# source /etc/profile |
(3)修改tomcat主配置文件/conf/server.xml
1 2 3 4 5 6 |
#8009端口是tomcat和apache的mod_proxy_ajp,mod_jk沟通的端口,没有用到就关了,如果需要使用,那防火墙要限制源IP,比如只允许内网使用 <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
#关闭自动部署 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false"> |
(4)启动tomcat
为安全起见,以普通用户启动tomcat
tomcat实例的安装目录和应用部署目录的属主和属组都改为普通用户,以防出现权限问题
1 2 |
启动tomcat : /usr/local/tomcat7/bin/startup.sh 关闭tomcat : /usr/local/tomcat7/bin/shutdown.sh |
1 2 3 |
[root@hall ~]# useradd javauser [root@hall ~]# cd /usr/local/ [root@hall local]# chown javauser:javauser tomcat7 -R |
1 2 3 4 5 6 7 |
[root@hall local]# su -c /usr/local/tomcat7/bin/startup.sh javauser Using CATALINA_BASE: /usr/local/tomcat7 Using CATALINA_HOME: /usr/local/tomcat7 Using CATALINA_TMPDIR: /usr/local/tomcat7/temp Using JRE_HOME: /usr/java/jdk1.7.0_40/jre Using CLASSPATH: /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar [root@hall local]# |
(5)查看启动日志,日志如下且没有报错,说明启动成功
1 2 3 4 5 6 7 8 |
[root@hall ~]# tail -f /usr/local/tomcat7/logs/catalina.out 。。。。。。。。。。。。。。。。。。。。。。。。 五月 23, 2016 4:42:05 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-8080"] 五月 23, 2016 4:42:05 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-bio-8009"] 五月 23, 2016 4:42:05 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 4674 ms |
(6)查看端口
1 2 3 4 5 |
[root@hall ~]# netstat -antp | grep java tcp 0 0 :::8080 :::* LISTEN 4926/java tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 4926/java tcp 0 0 :::8009 :::* LISTEN 4926/java [root@hall ~]# |
(7)iptables防火墙开放端口
1 2 |
[root@hall ~]# vim /etc/sysconfig/iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[root@hall ~]# service iptables restart iptables:将链设置为政策 ACCEPT:filter [确定] iptables:清除防火墙规则: [确定] iptables:正在卸载模块: [确定] iptables:应用防火墙规则: [确定] [root@hall ~]# [root@hall ~]# iptables -nL Chain INPUT (policy DROP) target prot opt source destination ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:55886 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT all -- 172.16.1.110 0.0.0.0/0 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:5666 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:10051
Chain FORWARD (policy DROP) target prot opt source destination
Chain OUTPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED [root@hall ~]# |
(8)浏览器访问测试
3.2、多实例安装
tomcat多实例,拷贝多个apache-tomcat 程序,修改配置文件,监听不同的端口,即可运行多个实例
(1)拷贝多份代码
1 2 3 |
[root@hall tomcat]# cp -r apache-tomcat-7.0.42 /usr/local/tomcat7-5050 [root@hall tomcat]# cp -r apache-tomcat-7.0.42 /usr/local/tomcat7-6060 [root@hall tomcat]# |
(2)修改tomcat主配置文件/conf/server.xml
1 2 3 4 5 6 7 8 9 10 11 |
[root@hall tomcat]# vim /usr/local/tomcat7-5050/conf/server.xml #修改shutdown端口。实例tomcat5050改为5005,实例tomcat6060改为6005 <Server port="5005" shutdown="SHUTDOWN">
#修改启动端口。实例tomcat5050改为5050,实例tomcat6060改为6060 <Connector port="5050" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
#8009端口是tomcat和apache的mod_proxy_ajp,mod_jk沟通的端口,没有用到就关了,如果需要使用,那防火墙要限制源IP,比如只允许内网使用 <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
#关闭自动部署 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false"> |
(3)修改环境变量,添加以下部分
1 2 3 4 5 |
### tomcat 1 export CATALINA_HOME_5050=/usr/local/tomcat7-5050
### tomcat 2 export CATALINA_HOME_6060=/usr/local/tomcat7-6060 |
1 |
[root@hall tomcat]# source /etc/profile |
(4)修改bin/catalina.sh
1 2 3 4 5 |
[root@hall tomcat]# vim /usr/local/tomcat7-5050/bin/catalina.sh export CATALINA_BASE=$CATALINA_HOME_5050
[root@hall tomcat]# vim /usr/local/tomcat7-6060/bin/catalina.sh export CATALINA_BASE=$CATALINA_HOME_6060 |
(5)启动tomcat实例
为安全起见,以普通用户启动tomcat
tomcat实例的安装目录和应用部署目录的属主和属组都改为普通用户,以防出现权限问题
1 2 3 |
[root@hall ~]# useradd javauser [root@hall ~]# cd /usr/local/ [root@hall local]# chown javauser:javauser tomcat7-5050 -R [root@hall local]# chown javauser:javauser tomcat7-6060 -R |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@hall local]# su -c /usr/local/tomcat7-5050/bin/startup.sh javauser Using CATALINA_BASE: /usr/local/tomcat7-5050 Using CATALINA_HOME: /usr/local/tomcat7-5050 Using CATALINA_TMPDIR: /usr/local/tomcat7-5050/temp Using JRE_HOME: /usr/java/jdk1.7.0_40/jre Using CLASSPATH: /usr/local/tomcat7-5050/bin/bootstrap.jar:/usr/local/tomcat7-5050/bin/tomcat-juli.jar [root@hall local]# [root@hall local]# su -c /usr/local/tomcat7-6060/bin/startup.sh javauser Using CATALINA_BASE: /usr/local/tomcat7-6060 Using CATALINA_HOME: /usr/local/tomcat7-6060 Using CATALINA_TMPDIR: /usr/local/tomcat7-6060/temp Using JRE_HOME: /usr/java/jdk1.7.0_40/jre Using CLASSPATH: /usr/local/tomcat7-6060/bin/bootstrap.jar:/usr/local/tomcat7-6060/bin/tomcat-juli.jar [root@hall local]# |
(6)防火墙开放端口
1 2 3 |
[root@hall tomcat]# vim /etc/sysconfig/iptables -A INPUT -p tcp -m tcp --dport 5050 -j ACCEPT -A INPUT -p tcp -m tcp --dport 6060 -j ACCEPT |
(7)浏览器访问测试
标签:
原文地址:http://www.cnblogs.com/yuguangahi/p/5545217.html