配置java环境jdk下载
[root@NFS-WEB1 local]# rpm -ivh jdk-7u9-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
[root@NFS-WEB1 latest]# /usr/java/latest/bin/java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
脚本
[root@NFS-WEB1 latest]# vim /etc/profile.d/java
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin/:$PATH
[root@NFS-WEB1 latest]# java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
[root@NFS-WEB1 latest]#
apache-tomcat安装
wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.67/bin/apache-tomcat-7.0.67.tar.gz
[root@NFS-WEB1 ~]# tar xf apache-tomcat-7.0.67.tar.gz -C /usr/local/
[root@NFS-WEB1 ~]# cd /usr/local/
[root@NFS-WEB1 local]# ln -sv apache-tomcat-7.0.67 tomcat
`tomcat' -> `apache-tomcat-7.0.67'
[root@NFS-WEB1 local]#
查看帮助:
[root@NFS-WEB1 tomcat]# bin/catalina.sh --help
启动:
[root@NFS-WEB1 tomcat]# bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@NFS-WEB1 tomcat]# ss -lnp|grep java
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* users:(("java",2679,46))
LISTEN 0 100 :::8009 :::* users:(("java",2679,43))
LISTEN 0 100 :::8080 :::* users:(("java",2679,42))
[root@NFS-WEB1 tomcat]# jps
2679 Bootstrap
2704 Jps
[root@NFS-WEB1 tomcat]#
tomcat配置层次顶级组件:位于整个配置的顶层容器类:可以包含其他组件的组件连接器类组件:连接用户请求至tomcat被嵌套类组件:位于一个容器中,不能半酣其他组件
engine
:核心容器,catalina引擎,负责通过connector接收用户请求处理请求
host
:类似于httpd中的虚拟主机,支持基于FQDN的虚拟主机
context
:最内层的容器类组件,一个context代表一个web应用程序:配置context的主要目的,指定对应的webapp的根目录,还能为webapp指定额外的属性,如部署方式等
service
:将连接器管理至engine,因此一个service内部可以有多个connector,但是只能有一个engine
嵌套类组件:valve
:拦截请求并在将其转至对应的webapp之前进行某种处理操作如:remote address filter value :基于ip做访问控制
logger
:日志记录器,用于记录组件内部的状态信息:可用于除context之外的任何容器中
realm
:可以用于任何容器类的组件中,关联用户认证库,实现认证和授权:UserDatabaseRealm:使用JNDI自定义的用户认证库;MemoryRealm:tomcat-users.xml;JDBCRealm:基于JDBC连接至数据中查找用户;
端口的修改:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
AJP(apache jserv pritical)协议端口:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
二进制协议,使用httpd反向代理用户请求至tomcat时,在httpd和tomcat之间使用;
tomcat启动脚本
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
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;;
*)
echo "Usage: `basename $0` {start|stop|restart}"
exit 1
;;
esac