jdk和tomcat环境部署:
1、删除系统自带的openjdk
# java -versionjava 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 javatzdata-java-2013g-1.el6.noarchjava-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64java-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/latestexport PATH=$JAVA_HOME/bin:$PATH
验证是否安装成功
# java -versionjava 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/tomcatexport PATH=$CATALINA_HOME/bin:$PATH
# . /etc/profile.d/tomcat.sh
# chmod +x /usr/local/tomcat/bin/*.sh
验证是否成功
# catalina.sh versionUsing CATALINA_BASE: /usr/local/tomcatUsing CATALINA_HOME: /usr/local/tomcatUsing CATALINA_TMPDIR: /usr/local/tomcat/tempUsing JRE_HOME: /usrUsing CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarServer version: Apache Tomcat/7.0.69Server built: Apr 11 2016 07:57:09 UTCServer number: 7.0.69.0OS Name: LinuxOS Version: 2.6.32-431.el6.x86_64Architecture: amd64JVM Version: 1.7.0_79-b15JVM 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/latestCATALINA_HOME=/usr/local/tomcatexport JAVA_HOME CATALINA_HOMEcase $1 instart) 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所有处理线程均处于繁忙状态时,新发来的请求将被放置于等待队列中;
2、定义host主机
# mkdir /www/webapps/ROOT -pv
# vim /www/webapps/ROOT/index.jsp
<%@ page language="java" %><%@ page import="java.util.*" %>jsp page test1<% out.println("hello world!"); %>
# vim /usr/local/tomcat/conf/server.xml
在host主机中添加另外的应用
# mkdir /www/webapps/testapp
# cp /www/webapps/ROOT/index.jsp /www/webapps/testapp/
3、添加tomcat应用的status和应用的管理
# vim /usr/local/tomcat/conf/tomcat-users.xml
状态查看
http://192.168.8.41/manager/status