Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现,Tomcat 5 支持最新的Servlet 2.4 和JSP 2.0 规范。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。Tomcat 很受广大程序员的喜欢,因为它运行时占用的系统资源小,扩展性好,支持负载平衡与邮件服务等开发应用系统常用的功能;而且它还在不断的改进和完善中,任何一个感兴趣的程序员都可以更改它或在其中加入新的功能。Tomcat 是一个小型的轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应对HTML 页面的访问请求。实际上Tomcat 部分是Apache 服务器的扩展,但它是独立运行的。
——以上内容摘自百度百科
下面就来介绍下Centos系统如何搭建tomcat服务!
在/usr目录下创建个java目录,并将从sun公司网站上下载下来的JDK包移动到此目录
[root@centos5 ~]# mkdir -p /usr/java
[root@centos5 ~]# mv jdk-6u13-linux-i586.bin /usr/java/
[root@centos5 ~]# cd /usr/java/
[root@centos5 java]# ll
total 78336
-rwxr--r-- 1 yang yang 80129716 May 21 2009 jdk-6u13-linux-i586.bin
安装JDK,并设置下环境变量
[root@centos5 java]#./jdk-6u13-linux-i586.bin
Please enter "yes" or "no".
Do you agree to the above license terms? [yes or no]
yes 此处输入yes
For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html
Press Enter to continue.....
Done.
[root@centos5 java]# ls
jdk1.6.0_13 jdk-6u13-linux-i586.bin
[root@centos5 java]# cd jdk1.6.0_13/
[root@centos5 jdk1.6.0_13]# ls
bin jre README_ja.html sample
COPYRIGHT lib README_zh_CN.html src.zip
db LICENSE register.html THIRDPARTYLICENSEREADME.txt
demo man register_ja.html
include README.html register_zh_CN.html
[root@centos5 jdk1.6.0_13]# ./bin/java -version 查看下java的版本信息
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)
[root@centos5 /]# tail -3 /etc/profile 设置java环境变量如下
export JAVA_HOME=/usr/java/jdk1.6.0_13
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
[root@centos5 /]# source /etc/profile 使环境变量生效
[root@centos5 /]# java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)
从apache网站上下载tomcat包,并移动到/usr/local目录下
[root@centos5 yang]# mv ./apache-tomcat-6.0.18.tar.gz /usr/local/
[root@centos5 yang]# cd /usr/local/
[root@centos5 local]# ls
apache-tomcat-6.0.18.tar.gz etc include libexec sbin share
bin games lib pgsql servmon src
[root@centos5 local]# tar -zxvf apache-tomcat-6.0.18.tar.gz 解压
[root@centos5 local]# ls
apache-tomcat-6.0.18 bin games lib pgsql servmon src
apache-tomcat-6.0.18.tar.gz etc include libexec sbin share
[root@centos5 local]# cd apache-tomcat-6.0.18
[root@centos5 apache-tomcat-6.0.18]# ls
bin lib logs RELEASE-NOTES temp work
conf LICENSE NOTICE RUNNING.txt webapps
[root@centos5 apache-tomcat-6.0.18]# cd bin/
[root@centos5 bin]# ls
bootstrap.jar digest.bat shutdown.bat tomcat-juli.jar
catalina.bat digest.sh shutdown.sh tomcat-native.tar.gz
catalina.sh jsvc.tar.gz startup.bat tool-wrapper.bat
catalina-tasks.xml service.bat startup.sh tool-wrapper.sh
commons-daemon.jar setclasspath.bat tomcat6.exe version.bat
cpappend.bat setclasspath.sh tomcat6w.exe version.sh
[root@centos5 bin]# ./startup.sh 运行下tomcat
Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.18
Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.18
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.18/temp
Using JRE_HOME: /usr/java/jdk1.6.0_13
[root@centos5 bin]# netstat -ntpl 查看下端口,tomcat使用了8080端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 3813/smbd
tcp 0 0 0.0.0.0:751 0.0.0.0:* LISTEN 1841/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1815/portmap
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2132/cupsd
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 3684/postmaster
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2156/sendmail: acce
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 3813/smbd
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 6791/java
tcp 0 0 :::8009 :::* LISTEN 6791/java
tcp 0 0 :::8080 :::* LISTEN 6791/java
tcp 0 0 :::80 :::* LISTEN 6032/httpd
tcp 0 0 :::22 :::* LISTEN 2117/sshd
tcp 0 0 :::5432 :::* LISTEN 3684/postmaster
[root@centos5 local]# mv apache-tomcat-6.0.18 tomcat
[root@centos5 local]# grep -r tomcat /etc/profile 设置下环境变量
pathmunge /usr/local/tomcat/bin
[root@centos5 local]# source /etc/profile
[root@centos5 /]# shutdown.sh 停止tomcat服务
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.6.0_13
[root@centos5 /]# netstat -ntpl |grep 8080
[root@centos5 /]# startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.6.0_13
[root@centos5 /]# netstat -ntpl |grep 8080
tcp 0 0 :::8080 :::* LISTEN 7051/java
web方式管理tomcat
[root@centos5 ~]# cd /usr/local/tomcat/
[root@centos5 tomcat]# ls
bin lib logs RELEASE-NOTES temp work
conf LICENSE NOTICE RUNNING.txt webapps
[root@centos5 tomcat]# cd conf/
[root@centos5 conf]# ls
catalina.policy context.xml server.xml web.xml
catalina.properties logging.properties tomcat-users.xml
[root@centos5 conf]# cat tomcat-users.xml 添加管理用户yang并设置密码,对应的角色是admin和manager
[root@centos5 conf]# cd / 重启下tomcat服务
[root@centos5 /]# shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.6.0_13
[root@centos5 /]# startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.6.0_13
[root@centos5 webapps]# mkdir test
[root@centos5 webapps]# cat test/index.jsp
<%
out.print("Hello yang!");
%>