FreeBSD 最小化安装 +diablo-jdk +Apache 与 Tomcat 整合 !


这篇文章算是补交很久之前的一篇作业,也顺便平息坛子里面很多同学的疑问!

我先说明一下配置环境的大概情况:
OS FreeBSD 6.2-RELEASE
JDK diablo-jdk-1.5.0.07.01
Apache apache-2.2.3
Tomcat tomcat-5.5.23

具体的版本信息显示如下:

[
root@FreeBSD ~] $ pkg_info
apache-2.2.3 Version 2.2 of Apache web server with prefork MPM.
bash-3.1.17 The GNU Project's Bourne Again SHell
cvsup-without-gui-16.1h_2 General network file distribution system optimized for CVS
diablo-jdk-1.5.0.07.01 Java Development Kit 1.5.0_07.01
expat-2.0.0_1 XML 1.0 parser written in C
fontconfig-2.3.2_6,1 An XML-based font configuration API for X Windows
freetype2-2.2.1_1 A free and portable TrueType font rendering engine
gettext-0.14.5_2 GNU gettext package
gmake-3.81_1 GNU version of 'make' utility
javavmwrapper-2.3 Wrapper script for various Java Virtual Machines
libdrm-2.0.2 Userspace interface to kernel Direct Rendering Module servi
libiconv-1.9.2_2 A character set conversion library
mod_jk-ap2-1.2.21,1 Apache JK module for connecting to Tomcat using AJP1X
perl-5.8.8 Practical Extraction and Report Language
pkg-config-0.21 A utility to retrieve information about installed libraries
tomcat-5.5.23 Open-source Java web server by Apache, 5.5.x branch
xorg-libraries-6.9.0 X11 libraries and headers from X.Org

好,来看看具体的做法吧!

第一步:安装FreeBSD,采取最小化安装的步骤。

这里没有什么特别的地方,只是提醒一下,安装完成后注意要更新到最新的ports tree !

由于是最小化安装,所以需要通过 sysinstall 去把下面几个package安装上(via CD-ROM) :
  • cvsup-without-gui # 更新ports tree 需要
  • perl # Perl当然是很多地方需要的... ^^!
  • gmake # 安装mod_jk时需要
  • bash # 我不熟C Shell,所以我另外安装了这个
完成安装后,更新ports tree,我使用了cvsup.FreeBSDChina.org 作为镜像!

第二步:安装 JDK -FreeBSD 发布的 JDK 1.5 软件包


罗嗦一句,从源代码编译JDK的时代已经过去了,我是懒人,所以喜欢用pkg_add !

如果你想从ports来编译JDK,可以看看这里:FreeBSD中编译JDK

2.1 下载diablo-jdk的软件包:diablo-jdk-freebsd6.i386.1.5.0.07.01.tbz

2.2 查找diablo-jdk的依赖项:

[root@FreeBSD /usr/ports] $ make search name=diablo-jdk-1.5.0.07.01
Port: diablo-jdk-1.5.0.07.01
Path: /usr/ports/java/diablo-jdk15
Info: Java Development Kit 1.5.0_07.01
Maint: [email protected]
B-deps: expat-2.0.0_1 fontconfig-2.3.2_6,1 freetype2-2.2.1_1 libdrm-2.0.2 pkg-config-0.21 xorg-libraries-6.9.0
R-deps: expat-2.0.0_1 fontconfig-2.3.2_6,1 freetype2-2.2.1_1 javavmwrapper-2.3 libdrm-2.0.2 pkg-config-0.21 xorg-libraries-6.9.0
WWW: http://www.FreeBSDFoundation.org/downloads/java.shtml

可以看到有如下几个packages需要安装:
  • expat-2.0.0_1
  • fontconfig-2.3.2_6,1
  • freetype2-2.2.1_1
  • libdrm-2.0.2
  • pkg-config-0.21
  • xorg-libraries-6.9.0
  • javavmwrapper-2.3
2.3 从网络安装diablo-jdk所需要的软件包 (并非ports的编译安装方式)

[
root@FreeBSD ~] $ setenv PACKAGESITE ftp://ftp.freebsdchina.org/pub/FreeBSD/ports/i386/packages-6.2-release/Latest/
[root@FreeBSD ~] $ pkg_add -r expat
[root@FreeBSD ~] $ pkg_add -r freetype
[root@FreeBSD ~] $ pkg_add -r fontconfig
[root@FreeBSD ~] $ pkg_add -r ... 省略 ...
[root@FreeBSD ~] $ pkg_add -r xorg-libraries
[root@FreeBSD ~] $ pkg_add -r javavmwrapper

注意:这里用pkg_add的时候,不带软件包的版本号!

* 有没有Debian/Ubuntu中的apt-get的感觉呀? ^^!

2.4 安装diablo-jdk,直接找到我们下载的jdk软件包文件,用pkg_add添加:

[
root@FreeBSD ~] $ pkg_add diablo-jdk-freebsd6.i386.1.5.0.07.01.tbz
[root@FreeBSD ~] $ /usr/local/diablo-jdk1.5.0/bin/java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build diablo-1.5.0-b01)
Java HotSpot(TM) Client VM (build diablo-1.5.0_07-b01, mixed mode)


提醒:
  • 安装的时候,会出来SUN的许可协议,同意即可.
  • 安装时会说javawmwrapper版本有点高,可以不用理会.

第三步:安装Tomcat

3.1 抓tomcat的档案下来:

[
root@FreeBSD ~] $ cd /usr/ports/www/tomcat55
[root@FreeBSD tomcat55] $ make
===> Vulnerability check disabled, database not found
=> apache-tomcat-5.5.23.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch from http://www.apache.org/dist/tomcat/tomcat-5/v5.5.23/bin/.
apache-tomcat-5.5.23.tar.gz 100% of 5837 kB 16 kBps 00m00s
===> Extracting for tomcat-5.5.23
=> MD5 Checksum OK for apache-tomcat-5.5.23.tar.gz.
=> SHA256 Checksum OK for apache-tomcat-5.5.23.tar.gz.
===> Patching for tomcat-5.5.23
Installation settings:
Destination directory: /usr/local/tomcat5.5
Location of JDK: /usr/local/diablo-jdk1.5.0
Location of Java port: java/diablo-jdk15
Running as (user/group): www/www
HTTP port: 8180
Shutdown listener port: 8005
AJP 1.3 connector port: 8009
Logfile stdout: /usr/local/tomcat5.5/logs/stdout.log
Logfile stderr: /usr/local/tomcat5.5/logs/stderr.log
===> Applying FreeBSD patches for tomcat-5.5.23
>> Removing unneeded files... [ DONE ]
>> Customizing server.xml... [ DONE ]
===> Configuring for tomcat-5.5.23

3.2 安装tomcat

[root@FreeBSD tomcat55] $ make install
===> Installing for tomcat-5.5.23
===> tomcat-5.5.23 depends on file: /usr/local/diablo-jdk1.5.0/bin/java - found
===> Generating temporary packing list
===> Checking if www/tomcat55 already installed
>> Creating destination directory... [ DONE ]
>> Copying files to destination directory...
Installing local configuration file: /usr/local/tomcat5.5/conf/Catalina/localhost/host-manager.xml
Installing local configuration file: /usr/local/tomcat5.5/conf/Catalina/localhost/manager.xml
Installing local configuration file: /usr/local/tomcat5.5/conf/catalina.policy
Installing local configuration file: /usr/local/tomcat5.5/conf/catalina.properties
Installing local configuration file: /usr/local/tomcat5.5/conf/context.xml
Installing local configuration file: /usr/local/tomcat5.5/conf/logging.properties
Installing local configuration file: /usr/local/tomcat5.5/conf/server-minimal.xml
Installing local configuration file: /usr/local/tomcat5.5/conf/server.xml
Installing local configuration file: /usr/local/tomcat5.5/conf/tomcat-users.xml
Installing local configuration file: /usr/local/tomcat5.5/conf/web.xml
[ DONE ]
>> Creating log files... [ DONE ]
>> Creating symlink to tools.jar... [ DONE ]

第四步:安装Apache Web Server


[root@FreeBSD ~] $ pkg_add -r apache22
Fetching ftp://ftp.freebsdchina.org/pub/FreeBSD/ports/i386/packages-6.2-release/Latest/apache22.tbz...

第五步:Apache Web Server 与 Tomcat 的整合

5.1 必备的组件mod_jk的安装

[root@FreeBSD /usr/ports/www/mod_jk] $ make
===> Vulnerability check disabled, database not found
=> tomcat-connectors-1.2.21-src.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch from http://www.apache.org/dist/tomcat/tomcat-connectors/jk/source/jk-1.2.21/.
=> Attempting to fetch from http://www.apache.org/dist/tomcat/tomcat-connectors/jk/source/jk-1.2.21/.
tomcat-connectors-1.2.21-src.tar.gz 100% of 1303 kB 27 kBps 00m00s
===> Extracting for mod_jk-ap2-1.2.21,1
=> MD5 Checksum OK for tomcat-connectors-1.2.21-src.tar.gz.
=> SHA256 Checksum OK for tomcat-connectors-1.2.21-src.tar.gz.
===> Patching for mod_jk-ap2-1.2.21,1
===> Applying FreeBSD patches for mod_jk-ap2-1.2.21,1
===> mod_jk-ap2-1.2.21,1 depends on file: /usr/local/sbin/apxs - found
===> mod_jk-ap2-1.2.21,1 depends on executable in : gmake - found
===> mod_jk-ap2-1.2.21,1 depends on file: /usr/local/sbin/apxs - found
===> Configuring for mod_jk-ap2-1.2.21,1
...省略 ...
...省略 ...
...省略 ...
Making all in common
gmake[1]: Entering directory `/usr/ports/www/mod_jk/work/tomcat-connectors-1.2.21-src/native/common'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/usr/ports/www/mod_jk/work/tomcat-connectors-1.2.21-src/native/common'
Making all in apache-2.0
gmake[1]: Entering directory `/usr/ports/www/mod_jk/work/tomcat-connectors-1.2.21-src/native/apache-2.0'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/usr/ports/www/mod_jk/work/tomcat-connectors-1.2.21-src/native/apache-2.0'

[root@FreeBSD /usr/ports/www/mod_jk] $ make install

5.2 编辑 /usr/local/etc/apache22/httpd.conf 文件,添加如下内容:

LoadModule jk_module libexec/apache/mod_jk.so

5.3 建立文件 /usr/local/etc/apache22/Includes/tomcat-apache.conf ,内容如下:

[root@FreeBSD Includes] $ cat tomcat-apache.conf
JkWorkersFile /usr/local/tomcat5.5/conf/workers.properties

JkLogFile /var/log/mod_jk.log
JkLogLevel info

JkMount /*.jsp ajp13
JkMount /jsp-examples/* ajp13
JkMount /servlets-examples/* ajp13
JkMount /servlet/* ajp13

* JkMount 是把tomcat中的URI与Apache的URI做一个映射,也就是说:

Apache 中的:http://localhost/jsp-examples/some-jsp-file.jsp
<---- 对应 --->
Tomcat 中的:http://localhost:<port>/jsp-examples/some-jsp-file.jsp

5.4 创建 mod_jk 的日志文件,并设定其归属的用户和组:

[root@FreeBSD ~] $ touch /var/log/mod_jk.log
[root@FreeBSD ~] $ chown www:www /var/log/mod_jk.log

5.5 建立 /usr/local/tomcat5.5/conf/workers.properties 文件:

[root@FreeBSD ~] $ cat /usr/local/tomcat5.5/conf/workers.properties
workers.tomcat_home=/usr/local/tomcat5.5
workers.java_home=/usr/local/diablo-jdk1.5.0
ps=/
worker.list=ajp12, ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

5.5 更改 workers.properties 文件归属的用户和组:

[root@FreeBSD ~] $ chown www:www /usr/local/tomcat5.5/conf/workers.properties

5.6 确定 tomcat 配置文件 server.xml 中有开启AJP功能:

<!-- Define an AJP 1.3 Connector --->
<Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>

* 这段不能被注视掉!

第六步:进行测试

6.1 启动服务

[root@FreeBSD ~] $ /usr/local/etc/rc.d/tomcat55 onestart
Starting tomcat55.

[root@FreeBSD ~] $ /usr/local/etc/rc.d/apache22 onestart
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.

6.2 测试

http://localhost/ ---> 出现Apache的信息:It works!
http://localhost/index.jsp ---> 出现Tomcat欢迎页面

这样就说明Apache将JSP的处理交给了Tomcat进行了!


你可能感兴趣的:(apache,jdk,tomcat,jsp,FreeBSD)