需求:
近期要用java开发的用户中心替换旧的用户中心,程序开发和测试使用的环境是tomcat6,计划部署到线上环境的时候使用jboss,主要考虑jboss支持热部署的原因要求是当用户使用ip访问的时候提示403权限拒绝(这变态的要求主要是机房管理的因素,主要针对的是80端口),使用域名访问的时候显示正常的应用
环境介绍:
操作系统:redhat enterprise linux 5.4 64位
系统ip:192.168.50.7/24
apache + mod_jk + jboss
apache版本:2.2.16
mod_jk版本:1.2.31
jboss版本:jboss5.1 GA
备注:之前考虑过在jboss上直接使用虚拟主机的方式实现,但使用ip和域名访问的时候都会出现404,且没有日志信息;考虑到jboss容器上只有部署一个用户中心的应用,
因而就放弃了使用jboss虚拟主机方式实现,将来如果有其他的java应用需要部署,可以考虑在一台服务器上部署多个jboss,监听不同的端口即可
- 1:编译安装apache2.2.16
- wget http://archive.apache.org/dist/httpd/httpd-2.2.16.tar.gz -P /usr/local/src/tarbag
- tar -zxvf /usr/local/src/tarbag/httpd-2.2.16.tar.gz -C /usr/local/src/software
- cd /usr/local/src/software/httpd-2.2.16 &
- ./configure --prefix=/usr/local/apache2.2.16 --enable-so --enable-rewrite --enable-headers --with-mpm=worker --enable-expires --enable-mods-shared=all
- make && make install
- 2:下载安装jboss,boss需要java支持
- java的下载地址可以在java.com上找到
- chmod u+x jdk-6u17-linux-i586.bin
- ./jdk-6u17-linux-i586.bin
- mv jdk1.6.0_17 /usr/local/java
- vi /etc/profile 添加如下内容到文件末尾
- export JAVA_HOME=/usr/local/java
- CLASSPATH=/usr/local/java/lib/dt.jar:/usr/local/java/lib/tools.jar
- PATH=/usr/local/java/bin:$PATH
- export PATH JAVA_HOME CLASSPATH
- source /etc/profile
- wget http://nchc.dl.sourceforge.net/project/jboss/JBoss/JBoss-5.1.0.GA/jboss-5.1.0.GA.zip
- unzip jboss-5.1.0.GA.zip -d /usr/local/
- mv /usr/local/jboss-5.1.0.GA /usr/local/jboss5
- 删除jmx-console和admin-console等默认的jboss应用(若需要此类应用,也可以留着)
- cd /usr/local/jboss5/server/default/deploy
- mkdir /bak/laji
- mv admin-console.war jbossws.sar jmx-console.war jmx-remoting.sar management messaging /bak/laji
- cp -rvp ROOT.war /bak/laji
- rm -rf ROOT.war/*
- 修改jboss主配置文件相关内容如下
- <Service name="jboss.web">
- <!-- A HTTP/1.1 Connector on port 8080 -->
- <Connector port="8080" address="0.0.0.0"
- maxThreads="2500" strategy="ms" maxHttpHeaderSize="8192"
- emptySessionPath="true"
- enableLookups="true" redirectPort="8443" acceptCount="100"
- connectionTimeout="20000" disableUploadTimeout="true" compression="on"
- compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
- useIPVHosts="true"
- />
- 启动jboss:/usr/local/jboss5/bin/run.sh -c default &
- (也可以使用nohup方式来启动,或者等jboss在后台启动完毕后输入exit退出终端,然后重新登录服务器)
- 关闭jboss: /usr/local/jboss5/bin/shutdown.sh -S
- 3:配置mod_jk和apache
- cd /usr/local/src/tarbag/
- wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/x86_64/mod_jk-1.2.31-httpd-2.2.x.so
- cp mod_jk-1.2.31-httpd-2.2.x.so /usr/local/apache2.2.16/modules/mod_jk.so
- 在apache主配置文件中添加如下内容
- grep 'jk' /usr/local/apache2.2.16/conf/httpd.conf
- Include conf/extra/mod_jk.conf
- 新增mod_jk.conf配置文件内容如下:
- cat /usr/local/apache2.2.16/conf/extra/mod_jk.conf
- LoadModule jk_module modules/mod_jk.so //加载mod_jk模块
- JkWorkersFile conf/extra/workers.properties //该文件用于控制请求转发jboss的端口
- JkLogFile logs/mod_jk.log //mod_jk的日志
- JkLogLevel info //日志级别为info
- JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" //日志时间戳格式
- JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
- JkRequestLogFormat "%w %V %T" //日志请求格式
- JkMount /* cas
- #JkMountFile conf/extra/uriworkermap.properties
- JkShmFile logs/jk.shm
- # Add jkstatus for managing runtime data
- <Location /jkstatus/>
- JkMount status
- Order deny,allow
- Deny from all
- Allow from 192.168.50.8
- Allow from 127.0.0.1
- </Location>
- cat /usr/local/apache2.2.16/conf/extra/workers.properties
- worker.list=cas
- # Define cas
- worker.cas.port=8009
- worker.cas.host=127.0.0.1
- worker.cas.type=ajp13
- worker.cas.cachesize=10
- worker.XXX.port 对应的是jboss应用的ajp端口,
- worker.XXX.host主机IP地址
- 这里注意一点 worker.list的列表项中出现的内容,一定要在mod_jk.conf里对应增加 JkMount /* XXX,否则apache是无法启动
- 配置apache虚拟主机如下
- grep -v '^#' /usr/local/apache2.2.16/conf/extra/httpd-vhosts.conf |grep -v '^$'
- NameVirtualHost 192.168.50.7:80
- <VirtualHost 192.168.50.7:80>
- ServerName 192.168.50.7
- <Location />
- Order deny,allow
- Deny from all
- </Location>
- </VirtualHost>
- <VirtualHost 192.168.50.7:80>
- ServerName jboss.766.com
- CustomLog "|/usr/local/apache2.2.16/bin/rotatelogs /usr/local/apache2.2.16/logs/jboss_log_%Y%m%d 86400 480" combined
- Errorlog "logs/jboss-error.log"
- RewriteEngine on
- JkMount /* cas
- </VirtualHost>
- /usr/local/apache2.2.16/bin/apachectl -k restart
- 测试:
- tail -f /usr/local/apache2.2.16/logs/access_log
- 192.168.50.8 - - [06/May/2011:13:45:28 +0800] "GET / HTTP/1.1" 403 202
- tail -f /usr/local/jboss5/server/default/log/localhost_access_log.2011-05-06.log
- 192.168.50.8 - - [06/May/2011:15:17:28 +0800] "GET / HTTP/1.1" 200 37
本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/560598如需转载请自行联系原作者
ylw6006