开始操作前,首先下载需要的安装包。
apache2:http://httpd.apache.org/download.cgi
apr和apr-util:http://apr.apache.org/
tomcat7:http://tomcat.apache.org/download-70.cgi
jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
东西准备好了之后开始编译、安装。
一、编译apr
tar -zxvf apr-1.5.0.tar.gz
cd apr-1.5.0
./configure –prefix=/usr/local/apr-httpd/
make
make install
二、编译apr_util
tar -zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3
./configure –prefix=/usr/local/apr-util-httpd/–with-apr=/usr/local/apr-httpd/
make
make install
三、编译apache2
tar -zxvf httpd-2.2.26.tar.gz
cd httpd-2.2.26
./configure –prefix=/usr/local/apache2/–with-apr=/usr/local/apr-httpd/ –with-apr-util=/usr/local/apr-util-httpd/–enable-so –enable-mods-shared=most –enable-rewrite=shared –enable-proxy=shared –enable-proxy-ajp=shared –enable-proxy-balancer=shared –enable-speling=shared
make
make install
启动apache2服务器
/usr/local/apache2/bin/apachectl start
如果没有报错,而且浏览器打开http://yourip/显示It works!页面,那么说明apache安装成功。
设置apache2开机自动启动,添加服务。
cp -a /usr/local/apache2/bin/apachectl /etc/init.d/
mv /etc/init.d/apachectl /etc/init.d/apache2
编辑/etc/init.d/apache2,在#!/bin/bash下添加如下两行。
# chkconfig: 35 70 30
# description: Apache2
update-rc.d apache2 defaults
四、安装tomcat7
1、安装jdk
tar zxvf jdk-7u55-linux-x64.gz
mkdir -p /usr/lib/jvm/
mv jdk1.7.0_55/ /usr/lib/jvm
设置jdk环境变量
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_55
export JRE_HOME=/usr/lib/jvm/jdk1.7.0_55/jre
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
最后出现如下页面说明jdk设置完成。
root@ubuntu:/usr/lib/jvm# java -version
java version “1.7.0_55″
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
2、安装tomcat
tar zxvf apache-tomcat-7.0.52.tar.gz -C /usr/local/
mv /usr/local/apache-tomcat-7.0.52 /usr/local/tomcat7
在/usr/local/tomcat7/bin/catalina.sh中找到“# OS specific support. $var _must_ be set to either true or false.”,在他的下面添加如下两条信息,保存退出。
CATALINA_HOME=/usr/local/tomcat7
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_55
3、启动tomcat
/usr/local/tomcat7/bin/startup.sh
如果没有报错,而且浏览器打开http://yourip:8080/显示tomcat的默认页面,那么说明tomcat安装成功。
4、设置tomcat7开机启动
新建文件/etc/init.d/tomcat7,添加如下内容。
#!/bin/bash
#
# /etc/rc.d/init.d/tomcat7
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
RETVAL=$?
CATALINA_HOME="/usr/local/tomcat7"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
保存后授予tomcat7可以执行权限,然后再运行update-rc.d tomcat7 defaults即可。
五、整合tomcat和apache
修改apache的配置文件httpd.conf,添加模块proxy_module 和proxy_ajp_module ,去掉Include conf/extra/httpd-vhosts.conf一行的注释。
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
……
Include conf/extra/httpd-vhosts.conf
编辑httpd-vhosts.conf文件,我的设置如下,打开http://yourip/images由apache处理,其他都由tomcat处理。
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/home/www/"
ServerName www.domain.com
<Directory "/home/www/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPass /images !
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
ErrorLog "/home/wwwlogs/www.domain.com-error_log"
CustomLog "/home/wwwlogs/www.domain.com-access_log" common
</VirtualHost>
到这里,apache整合tomcat基本上就已经部署完成了。