电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> 服务器技术>>[整合] APACHE2.2.0+tomcat5.5.12+jk1.2.15整和:

[整合] APACHE2.2.0+tomcat5.5.12+jk1.2.15整和

来源:www.cncfan.com | 2006-3-18 | (有3675人读过)


APACHE2.2.0+tomcat5.5.12+jk1.2.15


软件环境:
apache httpd-2.2.0.tar.gz
apr-1.2.2.tar.tar
apr-util-1.2.2.tar.tar
jdk-1_5_0_05-linux-i586.bin
jakarta-tomcat-connectors-1.2.15-src.tar.gz
apache-tomcat-5.5.12.tar.gz

软件说明:apache2.2.0是目前较新的版本。和apache2.0版本比较,它首先需要安装 apr-1.2.2.tar.tar和 apr-util-1.2.2.tar.tar
才能正常的运行。安装之前解压软件包。进入源代码包,先阅读,readme.txt,里面有安装说明。
安装:apr-1.2.2和apr-util-1.2.2
# Build and install apr 1.2
cd srclib/apr
./configure --prefix=/usr/local/apr-httpd/
make
make install

# Build and install apr-util 1.2
cd ../apr-util
./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/
make
make install

# Configure httpd
cd ../../
./configure --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/


二.apache安装
1../configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-so
#make
#make install

2.查看编译进apache的模块:
[root@localhost root]#cd /usr/local/httpd2/bin

[root@localhost bin]# httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c

(说明:看到mod_so.c这个模块,就说明能支持DSO。)





3.在配置文件中加入要监听的ip和端口。
#cd /usr/local/apache2/conf
#vi httpd.conf
32 # Listen: Allows you to bind Apache to specific IP addresses and/or
33 # ports, instead of the default. See also the <VirtualHost>
34 # directive.
35 #
36 # Change this to Listen on specific IP addresses as shown below to
37 # prevent Apache from glomming onto all bound IP addresses.
38 #
39 #Listen 12.34.56.78:80
40 Listen 192.168.10.2:80(这就是我们要加入的内容)
41

4.测试apache
#cd /usr/local/apache2/bin
#./apachectl start

现在在ie里输入ip就可以显示apache默认的主页了。



三.
1.装jdk
[root@localhost home]# ./jdk-1_5_0_05-linux-i586.bin
生成目录:jdk1.5.0_05
在/usr/创建目录,java
将该文件移动到/usr/local/java 目录下
测试java环境是否建立:
[root@host1 jdk1.5.0_05]# ls
bin COPYRIGHT demo include jre lib LICENSE man README.html sample src.zip
[root@localhost bin]# ./java –version
[root@host1 bin]# ./java -version
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)

显示版本,说明java环境建立成功!
(注意:tomcat5.5的必须有jdk1.5这个版本支持)

四.安装tomcat
1.[root@localhost root]#tar zxvf jakarta-tomcat-5.1.12.tar.gz /home (指定安装到/home目录下)
[root@localhost root]#mv jakarta-tomcat-5.1.12 tomcat (换个文件名)
启动关闭服务文件放在 /home/tomcat/bin
配置文件 /home/tomcat/conf
web文件 /home/tomcat/webapps
默认访问目录 /home/tomcat/webapps/ROOT


2.设置环境变量,
在/etc/profile中末尾加入:
export JAVA_HOME=/home/jdk1.5.0_05
export TOMCAT_HOME=/home/tomcat
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

3.启动与关闭服务:
#cd /home/tomcat/bin
#./startup.sh (关闭服务:#./shutdown.sh)


5.测试:http://192.168.10.2:8080/

(注:ROOT目录下面必须有WEB-INF这个目录,否则将无法访问该页面。
该目录下有两个文件:lib web.xml
这是web.xml的内容:
[root@host1 WEB-INF]# vi web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>Web Application</display-name>
<description>Uniprint</description>

</web-app>
~
Lib下的文件:
[root@host1 WEB-INF]# cd lib
[root@host1 lib]# ls
activation.jar commons-digester.jar commons-pool.jar jdbc2_0-stdext.jar mail.jar
commons-beanutils.jar commons-fileupload.jar commons-services.jar jdbc7.1-1.3.jar servlet.jar
commons-collections.jar commons-lang.jar commons-validator.jar jdom.jar taglibs-i18n.jar
commons-dbcp.jar commons-logging.jar jcommon-0.9.5.jar jfreechart-0.9.20.jar




五.安装jakarta-tomcat-connectors-1.2.15-src,生成mod_jk.so文件。

1.安装jakarta-tomcat-connectors-1.2.15-src.tar.gz
参考文档:http://www.redflag-linux.com/phorumredflag/phorumredflag/read.php?15,100143
进行安装,具体过程如下:
root@localhost native]#tar zxvf jakarta-tomcat-connectors-1.2.15-src.tar.gz
生成原文件: jakarta-tomcat-connectors-1.2.15-src
[root@localhost home]# cd jakarta-tomcat-connectors-1.2.15-src
[root@localhost jakarta-tomcat-connectors-1.2.15-src]#
[root@localhost jakarta-tomcat-connectors-1.2.15-src]# cd jk
[root@localhost jk]# cd native

root@localhost native]#./configure --with-apxs=/usr/local/apache2/bin/apxs
[root@localhost native]#make
[root@localhost native]#make install
[root@localhost native]#cd apache-2.0/
[root@localhost apache-2.0]#ls
mod_jk.so

(mod_jk.so会自动被复制到 /usr/local/apache2/modules目录下)




六.整和apache与tomcat(具体参考apache的官方网站)

编辑apache的配置文件/etc/httpd/conf/httpd.conf,在文件末尾添加如下内容:

#ad mod_jk module
LoadModule jk_module modules/mod_jk.so
# Update this path to match your modules location
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /usr/local/apache2/workers.properties
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /usr/local/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /*.jsp worker1

新建此文件/etc/httpd/conf/workers.properties 添加如下内容:
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.reclycle_timeout=300

七.建立基于name的虚拟主机:
对httpd.conf进行一些设置:
1.注释以下三行:
#ServerAdmin
#ServerName
#DocumentRoot
2.指定要访问站点的主目录(主目录下面放的是我们建立虚拟站点的子目录,我们的站点目录都放在/var/www下,这一步很重要)
具体设置:
179 <Directory "/var/www">
180 #
181 # Possible values for the Options directive are "None", "All",
182 # or any combination of:
183 # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
184 #
185 # Note that "MultiViews" must be named *explicitly* --- "Options All"
186 # doesn't give it to you.
187 #
188 # The Options directive is both complicated and important. Please see
189 # http://httpd.apache.org/docs/2.2/mod/core.html#options
190 # for more information.
191 #
192 # Options Indexes FollowSymLinks
193
194 #
195 # AllowOverride controls what directives may be placed in .htaccess files.
196 # It can be "All", "None", or any combination of the keywords:
197 # Options FileInfo AuthConfig Limit
198 #
199 AllowOverride None
200
201 #
202 # Controls who can get stuff from this server.
203 #
204 Order allow,deny
205 Allow from all
206
207 </Directory>
208
3.指定虚拟主机配置文件
440 #Virtual hosts
441 #Include conf/extra/httpd-vhosts.conf
将441行的注释去掉,就可以拉。
4.进入/conf/extra
[root@host1 extra]#vi httpd-vhosts.conf
(释掉原来的example(我是这么做的)
参照example我们就可以添加vhosts了。)



以下是我添加:


NameVirtualHost 192.168.10.2:80
<VirtualHost 192.168.10.2:80>
<Directory "/var/www/lazy1">
DirectoryIndex index.htm index.html index.jsp
</Directory>
ServerAdmin [email]lazy_bug@126.com[/email]
DocumentRoot /var/www/lazy1
ServerName lazy1.bug.com
ServerAlias html
ErrorLog logs/ lazy1.bug.com-error_log
CustomLog logs/lazy1.bug.com--access_log common
</VirtualHost>

<VirtualHost 192.168.10.2:80>
<Directory "/var/www/lazy2" >
DirectoryIndex index.htm index.html index.jsp
</Directory>

ServerAdmin [email]lazy_bug@126.com[/email]
DocumentRoot /var/www/lazy2
ServerName lazy2.bug.com
ServerAlias unisis
ErrorLog logs/lazy2.bug.com-error_log
CustomLog logs/lazy2.bug.com-access_log common
</VirtualHost>



测试虚拟主机配置是否生效:
#cd /usr/local/apache2/bin
[root@host1 bin]# ./httpd -S
VirtualHost configuration:
Syntax OK
(说明配置没有问题)

将我们的站点的web文件,放到上面所设置的目录下,启动apache和tomcat,
在ie里输入我们要访问的域名,也就是我们上面设置的Servername。




说明:测试机器没有做dns,域名解析是通过在测试机和客户机的hosts文件内加入域名和ip对应内容来实现的。
服务器技术热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号