系统环境:centos 6.3 64bit IP:192.168.1.108
tomcat版本:apache-tomcat-6.0.28.tar.gz
jdk版本: jdk-6u18-linux-x64-rpm.bin(需要注册下载)
tomcat源码包下载地址:wget -c http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.28/bin/apache-tomcat-6.0.28.tar.gz
JDK 二进制代码包下载地址:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html
一、安装JDK
将jdk包放到
#cd /usr/local/src/ 下
# chmod 755 jdk-6u18-linux-x64-rpm.bin
# ./jdk-6u18-linux-x64-rpm.bin
中间输入一次yes
点击一次enter
配置环境变量:cp /etc/profile /etc/profile.bak //备份
vim /etc/profile
在最后添加:
export JAVA_HOME=/usr/java/jdk1.6.0_18 export JAVA_BIN=/usr/java/jdk1.6.0_18/bin export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME JAVA_BIN PATH CLASSPAT
使之生效:source /etc/profile
测试JDK 是否正常工作:
[root@centos7 src]# java -version java version "1.6.0_24" OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64) OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
2、安装 tomcat
# cd /usr/local/src/
# tar zxvf apache-tomcat-6.0.28.tar.gz -C /usr/local/
# cd /usr/local/
# mv apache-tomcat-6.0.28 tomcat
启动 tomcat :
1、/usr/local/tomcat/bin/startup.sh >/dev/null 2<&1 &
停止 tomcat :
2、/usr/local/tomcat/bin/shutdown.sh
测试:启动完成,查看下tomcat 进程,确保其正常启动:
# ps aux|grep java root 13231 15.0 16.5 2150360 82116 pts/0 Sl 07:01 0:04 /usr/local/jdk1.8.0_11/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start root 13262 0.0 0.1 112656 988 pts/0 R+ 07:02 0:00 grep --color=auto java
3、开启防火墙的8080端口:
# iptables -I INPUT -p tcp -m multiport --dport 80,8080 -j ACCEPT
浏览器输入:http://192.168.1.141:8080/如下tomcat 的测试页面
测试:
Linux 下:
# curl -I localhost:8080 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Date: Mon, 28 Jul 2014 23:16:27 GMT
4、客户端测试:
1、vim /usr/local/tomcat/webapps/ROOT/test.jsp
2、The time is <%= new java.util.Date() %>
浏览器中测试出现下图说明成功。
至此!tomcat 环境搭建完成。下面我们来简单的了解下tomcat 根目录下的个目录的作用:
详解:
bin:该目录下存放的是一些可执行脚本文件,tomcat 的启动关闭都在这个文件里面
conf:该目录存放的是tomcat 的配置文件,比如server.xml tomcat-user.xml
lib:该买目录存放的是tomcat 的一些库文件
log:日志目录
temp:临时文件目录
webapps:应用文件存放目录,比如war jsp 等(如果部署完tomcat,不想默认访问tomcat,只需要把该目录下的root目录重命名或者删除,重新部署新的应用在这里即可)
work:
关于tomcat 测试主页上的一些栏目对应的 webapps 目录如下:
注:在conf 目录下有两个配置文件需要重点提一下:
server.xml:该文件是tomcat 的主配置文件,它包含了端口、域名、IP及虚拟主机的配置等;
tomcat-users.xml:该文件主要是针对tomcat 管理方面的配置,比如登陆manager、查看服务器运行状况,前提是需要在该文件中定义用户和组等
首先我们来看tomcat-users.xml 文件,该文件几乎全部被注释,如下:
[root@centos7 webapps]# cat ../conf/tomcat-users.xml <?xml version=‘1.0‘ encoding=‘utf-8‘?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <tomcat-users> #定义用户信息标签 <!-- NOTE: By default, no user is included in the "manager-gui" role required to operate the "/manager/html" web application. If you wish to use this app, you must define such a user - the username and password are arbitrary. --> <!-- NOTE: The sample user and role entries below are wrapped in a comment and thus are ignored when reading this file. Do not forget to remove <!.. ..> that surrounds them. --> <!-- <role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/> --> <role rolename="manager-gui"/> <user username="silence" password="tomcat" roles="manager-gui"/> </tomcat-users>
在不修改该文件的前提下,我们先从tomcat 主页登陆manager,就会弹出一个登陆框,要求输入登陆账号密码。
3.jpg (664.62 KB, 下载次数: 0)
由于默认 tomcat-users.xm文件没有被配置,所以我们无法登入。点击取消,或者关闭登陆框,会弹出一个提示页面,示例如何配置验证信息:
为了顺利登陆,我们来修改tomcat-users.xml 文件,在<tomcat-users>..</tomcat-users>中间加入:
<role rolename="manager"/> #定义manager 组 <user username="admin" password="admin" roles="manager"/> #定义用户名及密码,并将admin 加入manager
为了顺利登陆,我们来修改tomcat-users.xml 文件,在<tomcat-users>..</tomcat-users>中间加入:
<role rolename="manager"/> <role rolename="admin"/> <user username="admin" password="admin" roles="manager,admin"/>
重启tomcat:
[root@centos7 webapps]# /usr/local/tomcat/bin/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/local/jdk1.8.0_11/jre Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@centos7 webapps]# /usr/local/tomcat/bin/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/local/jdk1.8.0_11/jre Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
本文出自 “david0512” 博客,请务必保留此出处http://gjr0512.blog.51cto.com/6518687/1573049
原文地址:http://gjr0512.blog.51cto.com/6518687/1573049