JDK+Apache+Tomcat整合安装

工作中要在RHEL5上搭建JDK+Apache+Tomcat的环境,总结如下,方便自己参照。

JDK+Apache+Tomcat整合安装 

1 安装 jdk(安装在/usr/local/jdk目录下,版本1.6.0_04)

--首先将jdk-6u4-linux-x64.bin放在/usr/local下

#chmod a+x jdk-6u4-linux-x64.bin
#.
/jdk-6u4-linux-x64.bin
#mv jdk1.
6.0_04 /usr/local/jdk

 #mv jdk1.6.0_04 /usr/local/jdk(实现将jdk1.6.0_04重新命名为jdk)

--设置环境变量
#vi /etc/profile加入下面的内容

export JAVA_HOME=/usr/local/jdk
export CATALINA_BASE
=/usr/local/tomcat
export CATALINA_HOME
=/usr/local/tomcat
export PATH
=$CATALINA_HOME/bin:$JAVA_HOME/bin:$PATH
export CLASSPATH
=$JAVA_HOME/lib


--检测安装

# java -version
java version 
"1.6.0_04"
Java(TM) SE Runtime Environment (build 
1.6.0_04-b12)
Java HotSpot(TM) 
64-Bit Server VM (build 10.0-b19, mixed mode)

出现如上信息,说明安装成功。

2 安装 tomcat(安装在/usr/local/apache-tomcat-6.0.14.zip目录下,版本6.0.14)

# cp  apache - tomcat - 6.0 . 14 .zip  / usr / local /
# cd 
/ usr / local
# unzip apache
- tomcat - 6.0 . 14 .zip   
# ln 
- s apache - tomcat - 6.0 . 14  tomcat
# rm 
- rf apache - tomcat - 6.0 . 14 .zip

3 安装 apache(安装在/usr/local/apache2目录下,版本2.2.6)

 

# tar xzvf httpd - 2.2 . 6 .tar.gz
# cd httpd
- 2.2 . 6
#.
/ configure  -- prefix =/ usr / local / apache2  -- enable - so  -- enable - mods - shared = all -- enbale - lib64 
# make
# make install

#注意提示信息,如果出现/usr/lib/libexpat.so: could not read symbols: File in wrong format错误,参照[注1]
[注1]
--1. Delete file 'srclib/apr-util/configure' under 'httpd-2.0.61'
--2. Delete 'configure' file  under 'httpd-2.0.61'
--3. rebuild the configure scripts, run
     ./buildconf

4 启动tomcat

# cd $CATALINA_HOME / bin
# chmod a
+ * .sh
#.
/ startup.sh

5 停止tomcat

# cd $CATALINA_HOME / bin
#.
/ shutdown.sh

6 启动apache

# cd  / usr / local / apache2 / bin
# .
/ apachectl  - k start

7 停止apache

# cd  / usr / local / apache2 / bin
# .
/ apachectl  - k stop

8 将apache设为LINUX启动就运行的服务


1)#cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

2)#chkconfig 添加httpd的方法

#vi /etc/rc.d/init.d/httpd
在开始处#!/bin/bash之后的行后
插入
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server. It is used to serve HTML files and CGI.
#符号不能去掉

运行ntsysv 选中 httpd,就可以了

9 将tomcat设为LINUX启动就运行的服务 

  • 第一种方法 
1 )#  vi  / etc / init.d / tomcatsh
  #
!/ bin / sh
  # description: tomcat auto start
- stop script.
  # chkconfig: 
-   20   80
  #
  # Set CATALINA_HOME to be equivalent to the $CATALINA_HOME
  # from which you wish to execute startup.sh and shutdown.sh;
  #
  # Set ORA_OWNER to the user id of the owner of the
  # Oracle database 
in  $CATALINA_HOME.

  export JAVA_HOME
=/ usr / local / jdk
  CATALINA_HOME
=/ usr / local / tomcat
  
if  [  !   - f $CATALINA_HOME / bin / startup.sh ]
  then
      echo 
" tomcat startup: cannot start "
      exit
  fi
  
case   " $1 "   in
      
' start ' )
          # Start the tomcat:
          # The following command assumes that the root login
          # will not prompt the user 
for  any values
          $CATALINA_HOME
/ bin / startup.sh
          ;;
      
' stop ' )
          # Stop the tomcat:
          # The following command assumes that the root login

          # will not prompt the user 
for  any values
          $CATALINA_HOME
/ bin / shutdown.sh
          ;;
      
' restart ' )
          $
0  stop
          $
0  start
          ;;
  esac

 chkconfig --level 345 tomcat on

  • 第二种方法

用jsvc自动启动tomcat

--1、创建用户:

#groupadd tomcat
#useradd -s /sbin/nologin -g tomcat tomcat 

--2.修改目录所有者:
#chown -R tomcat:tomcat /usr/local/tomcat5.5

--3、安装jsvc
#cd /usr/local/tomcat/bin
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#sh support/buildconf.sh
#chmod 755 configure
#./configure --with-java=/usr/local/jdk      (改成你的JDK的位置)
#make

--4、修改启动文件
#vi ./native/Tomcat5.sh
改成如下内容: 

#
# chkconfig: 
345   87   13
# description: Tomcat Daemon
# processname: tomcat 
# pidfile: 
/ var / run / jsvc.pid
# config:
#
# Source function library.
# . 
/ etc / rc.d / init.d / functions
#
# prog
= tomcat
#
# Small shell script to show how to start
/ stop Tomcat  using  jsvc
# If you want to have Tomcat running on port 
80  please modify the server.xml
# file:
#


# port
= " 80 "  minProcessors = " 5 "  maxProcessors = " 75 "
# enableLookups
= " true "  redirectPort = " 8443 "
# acceptCount
= " 10 "  debug = " 0 "  connectionTimeout = " 60000 " />
#
# You need a developement version of Tomcat (Apache Tomcat
/ 4.1 - dev)
#
# Adapt the following lines to your configuration
 
 
#
!/ bin / sh
##############################################################################
#
#   Copyright 
2004  The Apache Software Foundation.
#
#   Licensed 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.
##############################################################################
#
# Small shell script to show how to start
/ stop Tomcat  using  jsvc
# If you want to have Tomcat running on port 
80  please modify the server.xml
# file:
#
#    
<!--  Define a non - SSL HTTP / 1.1  Connector on port  80   -->
#    
< Connector className = " org.apache.catalina.connector.http.HttpConnector "
#               port
= " 80 "  minProcessors = " 5 "  maxProcessors = " 75 "
#               enableLookups
= " true "  redirectPort = " 8443 "
#               acceptCount
= " 10 "  debug = " 0 "  connectionTimeout = " 60000 " />
#
# That 
is   for  Tomcat - 5.0 .x (Apache Tomcat / 5.0 )
#
# Adapt the following lines to your configuration
JAVA_HOME
=/ usr / local / jdk
CATALINA_HOME
=/ usr / local / tomcat
DAEMON_HOME
=/ usr / local / tomcat / bin
TOMCAT_USER
= root
 
for  multi instances adapt those lines.
TMP_DIR
=/ var / tmp
PID_FILE
=/ var / run / jsvc.pid
CATALINA_BASE
=/ usr / local / tomcat
 
CATALINA_OPTS
=
CLASSPATH
=
$JAVA_HOME
/ lib / tools.jar:
$CATALINA_HOME
/ bin / commons - daemon.jar:
$CATALINA_HOME
/ bin / bootstrap.jar
 
case   " $1 "   in
  start)
    #
    # Start Tomcat
    #
    $DAEMON_HOME
/ jsvc 
    
- user $TOMCAT_USER 
    
- home $JAVA_HOME 
    
- Dcatalina.home = $CATALINA_HOME 
    
- Dcatalina. base = $CATALINA_BASE 
    
- Djava.io.tmpdir = $TMP_DIR 
    
- wait  10  
    
- pidfile $PID_FILE 
    
- outfile $CATALINA_HOME / logs / catalina. out  
    
- errfile  ' &1 '  
    $CATALINA_OPTS 
    
- cp $CLASSPATH 
    org.apache.catalina.startup.Bootstrap
    #
    # To 
get  a verbose JVM
    #
- verbose 
    # To 
get  a debug of jsvc.
    #
- debug 
    exit $
?
    ;;
 
  stop)
    #
    # Stop Tomcat
    #
    $DAEMON_HOME
/ jsvc 
    
- stop 
    
- pidfile $PID_FILE 
    org.apache.catalina.startup.Bootstrap
    exit $
?
    ;;
 
  
* )
    echo 
" Usage tomcat.sh start/stop "
    exit 
1 ;;
esac

10.mod_jk.so的安装配置

# tar xzvf jakarta-tomcat-connectors-current-src.tar.gz
# cd jakarta-tomcat-connectors-1.2.14.1-src/jk/native
# ./configure --with-apxs=/usr/local/apache2/bin/apxs
# make
# make install
# cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/

11.修改Tomcat下的/conf/server.xml

  找到文件中的这一行:
<Engine name="Catalina" defaultHost="localhost">
  修改为:
<Engine name="Standalone" defaultHost="localhost" debug="0" jvmRoute="tomcat123">
  其中jvmRoute是apache通过mod_jk连接tomcat的名字。

12. 在Apache下创建mod_jk.conf文件

  在apache根目录下创建conf.d目录,在此目录下创建mod_jk.conf文件
  内容如下:
JkMount /* tomcat123
  其中“tomcat123”为tomcat中server.xml中“jvmRoute”的名字。
/* 为Context为“/”下的所有访问权限。加入context为“/cas”,则可配置为JkMount /cas/* tomcat123

13.在Apache下创建workers.properties文件

  在apache根目录下创建conf.d目录,在此目录下创建workers.properties文件。
  内容如下:

worker.list =  tomcat
#tomcat 
==========================================================
worker.tomcat123.port
= 8009
worker.tomcat123.host
= 127.0 . 0.1
worker.tomcat123.type
= ajp13
  #负载平衡因数
worker.tomcat123.lbfactor
= 1

 14.修改Apache下的/conf/httpd.conf

  在/conf/httpd.conf找到如下语句:
# Example:
# LoadModule foo_module modules/mod_foo.so
  在此语句下面添加如下配置:

LoadModule jk_module modules / mod_jk.so
JkWorkersFile conf.d
/ workers.properties
Include conf.d
/ mod_jk.conf

  在/conf/httpd.conf中配置虚拟主机,配置tomcat下的web应用。在此文件的末尾添加如下语  句:

< VirtualHost  * : 80 >
#(本服务器ip)
ServerName 
192.168 . 0.123
#(资源地址)
DocumentRoot 
/ webapp / web  
DirectoryIndex index.jsp
</ VirtualHost >

15.修改 /usr/local/apache2/conf/httpd.conf中的ServerName 为127.0.0.1

  通过以上配置,apache和tomcat的配置完成,重启apache,即可通过apache访问tomcat应用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值