一、安装JDK1.6.
[[email protected] ~]# chmod +x jdk-6u30-linux-x64-rpm.bin [[email protected] ~]# ./jdk-6u30-linux-x64-rpm.bin [[email protected] ~]# echo "export JAVA_HOME=/usr/java/default" > /etc/profile.d/java.sh [[email protected] ~]# . /etc/profile.d/java.sh
二、安装Tomcat。
[[email protected] ~]# tar xf apache-tomcat-7.0.40.tar.gz -C /usr/local [[email protected] local]# ln -sv apache-tomcat-7.0.40 tomcat [[email protected] ~]# vim /etc/profile.d/tomcat.sh export CATALINA_HOME=/usr/local/tomcat export PATH=$PATH:$CATALINA_HOME/bin [[email protected] ~]# . /etc/profile.d/tomcat.sh [[email protected] ~]# catalina.sh version #查看版本信息 [[email protected] ~]# vim /usr/local/tomcat/conf/server.xml #添加测试路径 <Engine name="Catalina" defaultHost="www.liangshaoqin.com" jvmRoute="TomcatA"> <Host name="www.liangshaoqin.com" appBase="/web" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="webapps" reLoadable="true" /> </Host> [[email protected] ~]# catalina.sh configtest #检查配置文件语法错误 [[email protected] ~]# mkdir /web/webapps -pv [[email protected] ~]# vim /web/webapps/index.jsp #编写测试页面 <%@ page language="java" %> <html> <head><title>TomcatA</title></head> <body> <h1><font color="red">TomcatA </font></h1> <table align="centre" border="1"> <tr> <td>Session ID</td> <% session.setAttribute("abc","abc"); %> <td><%= session.getId() %></td> </tr> <tr> <td>Created on</td> <td><%= session.getCreationTime() %></td> </tr> </table> </body> </html> [[email protected] ~]# catalina.sh start #启动tomcat服务,客户端通过8080访问测试
三、安装apache,先安装apr和apr-util,此处略过。
[[email protected] ~]# yum -y install pcre-devel [[email protected] ~]# yum -y install openssl-devel [[email protected] ~]# tar -zxvf httpd-2.4.10.tar.gz [[email protected] ~]# cd httpd-2.4.10 [[email protected] httpd-2.4.10]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-lbmethod-heartbeat --enable-heartbeat --enable-slotmem-shm --enable-slotmem-plain --enable-watchdog [[email protected] httpd-2.4.10]# make && make install [[email protected] ~]# vim /etc/init.d/httpd #为apache提供init脚本,略…… 1、配置apache通过mod_proxy模块与Tomcat连接 要使用mod_proxy与Tomcat实例连接,需要apache已经装载mod_proxy、mod_proxy_http、mod_proxy_ajp 和proxy_balancer_module(实现Tomcat集群时用到)等模块: # /usr/local/apache/bin/httpd -D DUMP_MODULES | grep proxy proxy_module (shared) proxy_connect_module (shared) proxy_ftp_module (shared) proxy_http_module (shared) proxy_fcgi_module (shared) proxy_scgi_module (shared) proxy_ajp_module (shared) proxy_balancer_module (shared) proxy_express_module (shared) 2、在httpd.conf的全局配置段或虚拟主机中添加如下内容: ProxyVia Off ProxyRequests Off ProxyPreserveHost Off <Proxy *> Require all granted </Proxy> ProxyPass / ajp://172.16.100.1:8009/ ProxyPassReverse / ajp://172.16.100.1:8009/ <Location / > Require all granted </Location> 或让apache跟Tomcat的http连接器进行整合: ProxyVia Off ProxyRequests Off ProxyPass / http://172.16.100.1:8080/ ProxyPassReverse / http://172.16.100.1:8080/ <Proxy *> Require all granted </Proxy> <Location / > Require all granted </Location> [[email protected] ~]# vim /etc/httpd/httpd.conf PidFile "/var/run/httpd.pid" #DocumentRoot "/usr/local/apache/htdocs" #注释此行 Include /etc/httpd/extra/httpd-proxy.conf LoadModule slotmem_shm_module modules/mod_slotmem_shm.so #取消这两行注释 LoadModule slotmem_plain_module modules/mod_slotmem_plain.so [[email protected] ~]# vim /etc/httpd/extra/httpd-proxy.conf <VirtualHost *:80> ProxyVia Off ProxyRequests Off ProxyPreserveHost Off <Proxy *> Require all granted </Proxy> ProxyPass / ajp://192.168.1.31:8009/ ProxyPassReverse / ajp://192.168.1.31:8009/ <Location / > Require all granted </Location> </VirtualHost> [[email protected] ~]# service httpd restart 3、配置apache通过mod_jk模块与Tomcat连接 [[email protected] ~]# tar xf tomcat-connectors-1.2.40-src.tar.gz [[email protected] ~]# cd tomcat-connectors-1.2.40-src/native/ [[email protected] native]# ./configure --with-apxs=/usr/local/apache/bin/apxs [[email protected] native]# make && make install [[email protected] ~]# ls /usr/local/apache/modules/ #检查模块是否已安装成功 [[email protected] ~]# vim /etc/httpd/httpd.conf Include /etc/httpd/extra/httpd-jk.conf [[email protected] ~]# vim /etc/httpd/extra/httpd-jk.conf LoadModule jk_module modules/mod_jk.so JkWorkersFile /etc/httpd/extra/workers.properties JkLogFile logs/mod_jk.log JkLogLevel debug JkMount /* TomcatA JkMount /status/ stat1 [[email protected] ~]# vim /etc/httpd/extra/workers.properties worker.list=TomcatA,stat1 worker.TomcatA.port=8009 worker.TomcatA.host=192.168.1.31 worker.TomcatA.type=ajp13 worker.TomcatA.lbfactor=1 worker.stat1.type = status
时间: 2024-10-06 00:10:51