1、安装apache
1.1 下载ApacheX64.rar,并解压
1.2 修改Apache24confhttpd.conf文件
配置根目录:
配置ip和端口
1.2 安装apache服务器
以管理员身份进入到apache安装目录的bin目录下,执行httpd.exe -k install
1.3 测试配置文件是否配置正确 httpd.exe -n Apache2.4 -t
1.4 修改默认首页 Apache24htdocsindex.html
<!doctype html> <html> <head> <title> apache </title> </head> <body> it works! </body> </html>
1.5 启动apache httpd.exe -k start
1.6 测试是否apache是否启动成功
在浏览器中输入:http://localhost:80
2、tomcat集群配置(使用上面的2.4配置tomcat时总是报错,故使用apache2.2配置)
2.1 下载mod_jk-apache-2.2.2.so,并将其复制到apache2.2modules目录下
2.2 在apache2.2/conf目录下创建workers.properties文件内容如下:
worker.list=controller,tomcat1,tomcat2,tomcat3 # 配置tomcat1 # 配置tomcat和apache通信的端口 worker.tomcat1.port=11009 worker.tomcat1.host=localhost # 配置tomcat和apache通信的协议为ajp13 worker.tomcat1.type=ajp13 # 配置该tomcat获得的请求比重,数字越大获得的请求越多 worker.tomcat1.lbfactor=1 worker.tomcat2.port=12009 worker.tomcat2.host=localhost worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor=1 worker.tomcat3.port=13009 worker.tomcat3.host=localhost worker.tomcat3.type=ajp13 worker.tomcat3.lbfactor=1 # 配置负载均衡 worker.controller.type=lb #配置负载均衡的tomcat列表 worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3 worker.controller.sticky_session=false worker.controller.sticky_session_force=1
2.3 在apache2.2/conf目录下创建mod_jk.conf文件内容如下:
LoadModule jk_module modules/mod_jk-apache-2.2.2.so JkWorkersFile conf/workers.properties JkMount /*.jsp controller JkMount /*.do tomcat1 JkMount /*.action tomcat2 JkMount /*.anno tomcata3
2.4 下项目的web.xml文件中配置session共享
在web.xml文件末尾添加 <distributable/> 标签
2.5 将项目放入到2.2中的tomcat的webapp目录下,修改conf/server.xml(以tomcat1为例)
<!--修改tomcat关闭接口-->
<Server port="11006" shutdown="SHUTDOWN">
<!--修改http访问端口--> <Connector port="11081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<!--修改ajp13端口,和apache进行通信--> <Connector port="11009" protocol="AJP/1.3" redirectPort="8443" />
<!--配置虚拟主机名称--> <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<!--配置tomcat单点故障--> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
2.6 启动apache,tomcat1,tomcat2,tomcat3并进行验证
2.7 配置域名直接访问tomcat中的内容
2.7.1 修改apache2.2/conf/httpd.conf文件
取消注释
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2.7.2 修改apache2.2/conf/extra/httpd-vhosts.conf配置文件,在文件尾部添加如下内容
<VirtualHost *:80> ServerName cas.5teacher.com DocumentRoot "D:softwareapache-tomcat-1webapps omcats" DirectoryIndex index.jsp <Directory "D:softwareapache-tomcat-1webapps omcats"> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerName cas.5teacher.com DocumentRoot "D:softwareapache-tomcat-2webapps omcats" DirectoryIndex index.jsp <Directory "D:softwareapache-tomcat-2webapps omcats"> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerName cas.5teacher.com DocumentRoot "D:softwareapache-tomcat-3webapps omcats" DirectoryIndex index.jsp <Directory "D:softwareapache-tomcat-3webapps omcats"> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
2.7.3 在各个tomcat中配置(以tomcat1为例),修改apache-tomcat-1/conf/server.xml 修改
<Host name="cas.5teacher.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <alias>cas.5teacher.com</alias> <Context path="" docBase="D:softwareapache-tomcat-2webapps omcats" debug="0" reloadable="true"/> </Host>