jdk和tomcat环境部署:
1、删除系统自带的openjdk
# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
# rpm -qa | grep java
tzdata-java-2013g-1.el6.noarch
java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
# rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
2、安装jdk-7u79
# rpm -ivh jdk-7u79-linux-x64.rpm
# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH
验证是否安装成功
# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
3、部署tomcat
# unzip apache-tomcat-7.0.69.zip
# cp -r apache-tomcat-7.0.69 /usr/local/
# cd /usr/local
# ln -sv apache-tomcat-7.0.69 tomcat
# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH
# . /etc/profile.d/tomcat.sh
# chmod +x /usr/local/tomcat/bin/*.sh
验证是否成功
# catalina.sh version
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.69
Server built: Apr 11 2016 07:57:09 UTC
Server number: 7.0.69.0
OS Name: Linux
OS Version: 2.6.32-431.el6.x86_64
Architecture: amd64
JVM Version: 1.7.0_79-b15
JVM Vendor: Oracle Corporation
将tomcat加入服务脚本
# vim /etc/init.d/tomcat
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
# JAVA_OPTS='-Xms64m -Xmx128m'
JAVA_HOME=/usr/java/latest
CATALINA_HOME=/usr/local/tomcat
export JAVA_HOME CATALINA_HOME case $1 in
start)
exec $CATALINA_HOME/bin/catalina.sh start ;;
stop)
exec $CATALINA_HOME/bin/catalina.sh stop;;
restart)
$CATALINA_HOME/bin/catalina.sh stop
sleep 2
exec $CATALINA_HOME/bin/catalina.sh start ;;
configtest)
exec $CATALINA_HOME/bin/catalina.sh configtest ;;
*)
echo "Usage: `basename $0` {start|stop|restart}"
exit 1
;;
esac
# chmod +x /etc/init.d/tomcat
# chkconfig add tomcat
# service tomcat start
tomcat配置常用案例:
1、定义同时监听两个端口80和8080:
以下为connector常用属性的说明:
1) address:指定连接器监听的地址,默认为所有地址,即0.0.0.0;
2) maxThreads:支持的最大并发连接数,默认为200;
3) port:监听的端口,默认为0;
4) protocol:连接器使用的协议,默认为HTTP/1.1,定义AJP协议时通常为AJP/1.3;
5) redirectPort:如果某连接器支持的协议是HTTP,当接收客户端发来的HTTPS请求时,则转发至此属性定义的端口;
6) connectionTimeout:等待客户端发送请求的超时时间,单位为毫秒,默认为60000,即1分钟;
7) enableLookups:是否通过request.getRemoteHost()进行DNS查询以获取客户端的主机名;默认为true;
8) acceptCount:设置等待队列的最大长度;通常在tomcat所有处理线程均处于繁忙状态时,新发来的请求将被放置于等待队列中;
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
<Connector port="8080" address="127.0.0.1" maxThreads="1024" enableLookups="false" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
2、定义host主机
# mkdir /www/webapps/ROOT -pv
# vim /www/webapps/ROOT/index.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>jsp page test1</title>
</head>
<body>
<% out.println("hello world!"); %>
</body>
</html>
# vim /usr/local/tomcat/conf/server.xml
<Host name="www.a.com" appBase="/www/webapps" unpackWARS="true" autoDeploy="true">
<Context path="" docBase="ROOT" reloadable="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="a.com_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
在host主机中添加另外的应用
# mkdir /www/webapps/testapp
# cp /www/webapps/ROOT/index.jsp /www/webapps/testapp/
<Host name="www.a.com" appBase="/www/webapps" unpackWARS="true" autoDeploy="true">
<Context path="" docBase="ROOT" reloadable="true" />
<Context path="/test" docBase="testapp" reloadable="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="a.com_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
3、添加tomcat应用的status和应用的管理
# vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="manage-gui" />
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui,admin-gui" />
状态查看
http://192.168.8.41/manager/status