How to setup a basic Linux J2EE server (Tomcat & Apache)

本文详细介绍了如何在Linux环境下安装配置Apache HTTP服务器及Tomcat应用服务器,并实现两者间的整合,同时还涉及了Java运行环境的搭建及MySQL数据库的安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 You must have the following files:
1. httpd-2.0.52.tar.gz (apache web server)
2. jakarta-tomcat-5.0.28.tar.gz (tomcat jsp/servlet container)
3. jakarta-tomcat-connectors-jk2-src-current.tar.gz (jk2 connector for apache)
4. jdk-1_5_0_01-linux-i586.bin (Java JDK)
5. jtds-0.9.1-dist.zip (FreeTDS Linux -> MSSQL connector)
6. mysql-standard-4.1.9-pc-linux-gnu-i686.tar.gz

NOTE: The following steps assume you are logged as root

1. Install J2SDK binary distribution:

./jdk-1_5_0_01-linux-i586.bin

2. Move installation directory (i.e. /usr/local/jdk)

 

mv jdk1.5.0_01  /usr/local/jdk

 

 

 

 

3. Configure environment variables:
Edit /etc/profile.d/alljava.sh, at the end add the following lines:

 
if [ -x /usr/local/jdk ]; then
    export  PATH=$PATH:/usr/local/jdk/bin
    export  JAVA_HOME=/usr/local/jdk
fi

4. Install Tomcat binary distribution:

tar -xzvf  jakarta-tomcat-5.0.28.tar.gz

5. Move installation directory (i.e. /usr/local/tomcat)

mv jakarta-tomcat-5.0.28  /usr/local/tomcat

6. Edit <tomcat_path>/conf/tomcat-users.xml
example:

 
<?xml version=‘1.0′ encoding=‘utf-8′?>
    <tomcat-users>
        <role rolename="manager"/>
        <role rolename="admin"/>
        <role rolename="myAppAdmin"/>
        <user username="root" password="admin" roles="admin,manager"/>
        <user username="administrador" password="admin" roles="myAppAdmin"/>
    </tomcat-users> 

 

7. Install Apache HTTP server:

 
tar -xzvf httpd-2.0.52.tar.gz
cd  httpd-2.0.52
./configure –enable-mods-shared=most  –enable-ssl=shared
make
make install
 

8. Configure apache/tomcat to start at boot time:
Create a file /etc/init.d/apache

 
#!/bin/bash
case "$1"  in 
    start)
        echo "Starting Apache HTTP server…"
        if [ -x  /usr/local/apache2 ]; then
            /usr/local/apache2/bin/httpd -k  start
        fi
        ;;
    stop)
        echo "Stoping Apache HTTP  server…"
        if [ -x /usr/local/apache2 ];  then
            /usr/local/apache2/bin/httpd -k  stop
        fi
        ;;
esac

Create a file /etc/init.d/tomcat

 
#!/bin/bash
case "$1"  in
    start)
        echo "Starting tomcat…"
        export  JAVA_HOME=/usr/local/jdk
        if [ -x /usr/local/tomcat ];  then
            /usr/local/tomcat/bin/startup.sh
        fi
        ;;
    stop)
        echo  "Stoping tomcat…"
        if [ -x /usr/local/tomcat ];  then
            /usr/local/tomcat/bin/shutdown.sh
        fi
        ;;
esac

Enable apache/tomcat services at runlevel 5

 
chmod 755 apache
chmod 755  tomcat
 

– CHOOSE ONE OF THE FOLLOWING METHODS:
A. chkconfig

 
chkconfig –add apache
chkconfig apache  5
chkconfig -add tomcat
chkconfig tomcat 5
 

B. symbolic links ( look for rc5.d usually /etc/rc.d/rc5.d)

 
cd /etc/rc.d/rc5.d
ln -s Sxxapche  /etc/init.d/apache (*)
ln -s Sxxtomcat /etc/init.d/tomcat (*)
cd  rc0.d
ln -s Kxxapache /etc/init.d/apache(*)
ln -s Kxxtomcat  /etc/init.d/tomcat (*) 
  

(*) where xx is the order in which the Linux init process starts or kills the services

9. Configure jk2 module

 
tar -xzvf  jakarta-tomcat-connectors-jk2-src-current.tar.gz
cd  jakarta-tomcat-connectors-2.0.4-src/jk/native2
./configure  –with-apache2=/usr/local/apache2  –with-apxs2=/usr/local/apache2/bin/apxs
make
cp ../build/jk2/apache2/*.so  /usr/local/apache2/modules
libtool –finish /usr/local/apache2/modules
cp  ../conf/workers2.properties /usr/local/apache2/conf
 

Open Apache’s /usr/local/apache2/conf/httpd.conf configuration file and add this line to the bottom of the list of LoadModule lines:
LoadModule jk2_module modules/mod_jk2.so

Edit workers2.properties, map your application webapp to the Web server uri space:

 
[uri:/<my_web_app>/*]
group=lb

If you want to install mySQL (instead of using MSSQL server) read next section:
1. Install mySQL binary distribution

 
tar -xzvf  mysql-standard-4.1.9-pc-linux-gnu-i686.tar.gz
mv  mysql-standard-4.1.9-pc-linux-gnu-i686 /usr/local/mysql
 

2. configure mySQL

 
groupadd mysql
useradd -g mysql  mysql
cd <mysql_path>
./scripts/mysql_install_db –user  mysql
chown -R root mysql .
chown -R mysql data
chgrp -R mysql  .
  

3. Start mySQL

 
./bin/mysqld_safe  &amp;
 

4. To start mySQL at boot time

 
cp  <mysql_path>/support-files/mysql.server  /etc/init.d/mysql
 

5. Edit /etc/init.d/mysql

 
basedir = <mysql_path>
data =  <mysql_path>/data
 

6. Enable mysql system service at run level 5

 
chkconfig -a  mysql
chkconfig mysql 5
 

 

引用:http://blog.piloni.net/?p=38

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值