一.部署 apache
1. 在官网上下载 apache 源码包
[[email protected] src]# wget
http://labs.renren.com/apache-mirror//httpd/httpd-2.2.21.tar.gz --2011-04-25 11:32:25-- http://labs.renren.com/apache-mirror//httpd/httpd-2.2.21.tar.gz 正在解析主机 labs.renren.com... 123.129.232.121 Connecting to labs.renren.com|123.129.232.121|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:7095187 (6.8M) [application/x-gzip] Saving to: `httpd-2.2.21.tar.gz.1' 100%[=======================================================================>] 7,095,187 281K/s in 25s 2011-04-25 11:32:50 (278 KB/s) - `httpd-2.2.21.tar.gz.1' saved [7095187/7095187] [[email protected] src]#
|
[[email protected] src]# tar zxf httpd-2.2.21.tar.gz [[email protected] src]# cd httpd-2.2.21 [[email protected] src]# ./configure --prefix=/usr/local/apache2 --enable-modules=so --enable-mods-shared=most --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-rewrite && make && make install # 编译并安装 apache
|
[[email protected] httpd-2.2.21]# vi
/usr/local/apache2/conf/httpd.conf Include conf/extra/httpd-vhosts.conf # 去掉改行的注释
|
[[email protected] httpd-2.2.21]# vi
/usr/local/apache2/conf/extra/httpd-vhosts.conf NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/usr/local/tomcat/webapps/ROOT" ServerName www.wanqiu.com ServerAlias wanqiu.com ErrorLog "logs/www.wanqiu.com-error.log" CustomLog "logs/www.wanqiu.com-access_log" common ProxyRequests Off ProxyPreserveHost On ProxyPass /*.jpg ! ProxyPass /*.gif ! ProxyPass /*.png ! ProxyPass /*.js ! ProxyPass /*.html ! ProxyPass /test.html ! ProxyPass / http://172.16.123.111:8080/ ProxyPassReverse / http://172.16.123.111:8080/ <Directory "/usr/local/tomcat/webapps/ROOT"> Options -Indexes AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
|
5. Tomcat 的运行依赖于 JRE,所以我们需要安装 JDK
[[email protected] local]# chmod -R 777 jdk-6u16-linux-i586.bin [[email protected] local]# ./jdk-6u16-linux-i586.bin Sun Microsystems, Inc. Binary Code License Agreement for the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6 # 执行 JDK 之后,都是一些软件的协议,根据提示一路回车安装即可
|
6. 配置 JDK 的路径变量
[[email protected] ~]# vi /etc/profile export JAVA_HOME=/usr/local/jdk1.6.0_16 export JRE_HOME=/usr/local/jdk1.6.0_16/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
|
[[email protected] ~]# source /etc/profile
|
8. 检查 JDK 是否安装成功
[[email protected] ~]# java -version java version "1.6.0_16" # 如果出现 java的版本号,则证明 JDK 安装成功 Java(TM) SE Runtime Environment (build 1.6.0_16-b01) Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
|
[[email protected] software]# tar zxf apache-tomcat-6.0.33.tar.gz [[email protected] software]# mv apache-tomcat-6.0.33 /usr/local/tomcat [[email protected] ~]# cd /usr/local/tomcat/ [[email protected] tomcat]# ls bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work [[email protected] tomcat]# # 关于 tomcat 目录中的文件的详解,见附录
|
[[email protected] /]# cd /usr/local/tomcat/webapps/ROOT/ [[email protected] ROOT]# cat index.html Hello My name is Wanqiu [[email protected] ROOT]# cat wanqiu.jsp <html> <body> <center> Now time is: <%=new java.util.Date() %> </center> </body> </html>
|
[[email protected] ROOT]# /usr/local/apache2/bin/apachectl restart [[email protected] ROOT]# /usr/local/tomcat/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk1.6.0_16/jre Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar [[email protected] ROOT]#
|
Apache 的进程和端口 [[email protected] ROOT]# ps -ef | grep httpd root 14093 1 0 10:36 ? 00:00:00 /usr/local/apache2/bin/httpd -k start daemon 14415 14093 0 12:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start daemon 14416 14093 0 12:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start daemon 14417 14093 0 12:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start daemon 14418 14093 0 12:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start daemon 14419 14093 0 12:00 ? 00:00:00 /usr/local/apache2/bin/httpd -k start root 14473 21384 0 12:02 pts/2 00:00:00 grep httpd [[email protected] ROOT]# [[email protected] ROOT]# netstat -npl | grep httpd tcp 0 0 :::80 :::* LISTEN 14093/httpd [[email protected] ROOT]# Tomcat 的进程和端口 [[email protected] ROOT]# ps -ef | grep tomcat | grep -v grep root 14453 1 0 12:01 pts/2 00:00:01 /usr/local/jdk1.6.0_16/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start [[email protected] ROOT]# netstat -npl | grep java tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 14453/java tcp 0 0 :::8009 :::* LISTEN 14453/java tcp 0 0 :::8080 :::* LISTEN 14453/java [[email protected] ROOT]#
|
访问 html 页面
访问 jsp 页面
停掉 apache 之后访问 jsp 页面,会出现域名解析不到的问题
再次启动 apache 服务器来访问 jsp 页面,可以正常访问到
启动 apache 服务的基础上,我们停掉 tomcat 服务来测试
此时,证明我的的测试完全符合我们的要求
附录一:apache httpd-vhosts.conf 配置文件详解
NameVirtualHost *:80 # 指定服务器监听的端口 <VirtualHost *:80> # 虚拟主机的代码快 ServerAdmin [email protected] # 管理员联系方式 DocumentRoot "/usr/local/tomcat/webapps/ROOT" #指定 apache 的网页目录 ServerName www.server110.com # 指定客户端访问的域名 ServerAlias server110.com # 指定客户端访问域名的别名 ErrorLog "logs/www.server110.com-error.log" # 指定 apache 错误日志的路径 CustomLog "logs/www.server110.com-access_log" common # 指定 apache 访问日志路径 ProxyRequests Off # 代理转发请求 ProxyPreserveHost On # 启动代理转发某台计算机 ProxyPass /*.jpg ! # 静态的 jpg 图片不代理 ProxyPass /*.gif ! # 静态的 jif 图片不代理 ProxyPass /*.png ! # 静态的 png图片不代理 ProxyPass /*.js ! # 静态的 js图片不代理 ProxyPass /*.html ! # 静态页面 html 页面不代理 ProxyPass /test.html ! # 静态页面 test.html 页面不代理 ProxyPass / http://172.16.123.111:8080/ # 指定被代理的地址和端口 ProxyPassReverse / http://172.16.123.111:8080/ # 指定反向代理 <Directory "/usr/local/tomcat/webapps/ROOT"> # 授权 apache 访问的目录 Options –Indexes # 允许列出index 文件 AllowOverride None # 确定允许存在于.htaccess文件中的指令类型 Order allow,deny # 允许未明确拒绝的 Allow from all # 允许所有的访问 </Directory> </VirtualHost>
|
[[email protected] tomcat]# ls bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work bin 目录:存放 toncat 的启动脚本文件 conf 目录: tomcat 的配置文件目录 logs 目录: tomcat 的日志目录,存放 tomcat 启动等日志 webapps: tomcat 的网页目录
|
比如默认的网页文件是 /usr/local/tomcat/webapps/ROOT,我现在定义的目录是 /data/tomcat-zf/webapps/Payment 我该如何配置 server.xml
[[email protected] conf]# vi /data/tomcat-zf/conf/server.xml <Context path ="" debug="0" docBase ="/data/tomcat-zf/webapps/Payment" reloadable="true" privileged="true" acceptCount="500" > # 在配置文中加入该行
|