为什么使用Jboss?
1、Jboss支持热部署,将归档后的JAR、WAR文件到部署目录下自动加载部署,自动更新。
2、在高并发访问时,性能比Tomcat更加优秀、高效。
3、Jboss在设计方面与Tomcat相比,进行了线程池和连接池的优化。
4、Jboss已经成为Java中间件的一个企业级的Web应用,Tomcat是轻量级应用,作为Java开发调试环境使用广泛。
5、配置简单,占用系统资源少。
Jboss AS 7.1两种运行模式?
Dmain Mode(域模式):多台Jboss AS服务器的配置进行集中管理,统一配置、统一部署,会启动5个进程,3个Jboss AS Server实例,1个Domain Controller进程和一个Process Controller。
Standalone Mode(单机模式):作为独立一台Jboss AS服务器,会启动一个进程。
JBoss下载:http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz
JDK下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Mod_JK下载:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.39-src.tar.gz
一、安装Apache、PHP与JK
1.YUM安装
[[email protected]~]# yum install -y gcc gcc-c++ httpd httpd-devel php php-devel php-mysql php-gd php-xml php-mbstring php-mcrypt freetype freetype-devel libpng libpng-devel zlib-devel libjpeg*
2.生成并加载mod_jk模块
|
1
2
3
4
5
6
|
[[email protected]~]# tar zxvf tomcat-connectors-1.2.39-src.tar.gz
[[email protected]~]# cd tomcat-connectors-1.2.39-src
[[email protected]]# cd native/
[[email protected]]# ./configure --with-apxs=/usr/sbin/apxs --with-java-home=/usr/local/jdk1.7/
[[email protected]]# make
[[email protected]]# cp apache-2.0/mod_jk.so /etc/httpd/modules/
|
|
1
2
3
4
5
|
[[email protected]~]# vi /etc/httpd/conf/httpd.conf
LoadModulejk_module modules/mod_jk.so #加载jk模块
Include/etc/httpd/conf/mod_jk.conf #先加载jk配置文件
DirectoryIndex index.phpindex.jsp index.html index.html.var #添加索引页
[[email protected]~]# service httpd restart
|
二、安装JDK1.7
|
1
2
3
4
5
6
7
8
9
10
|
[[email protected]~]# tar zxvf jdk-7u17-linux-x64.tar.gz
[[email protected]~]# mv jdk1.7.0_17/ /usr/local/jdk1.7
[[email protected]~]# vi /etc/profile
JAVA_HOME=/usr/local/jdk1.7
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HMOE/lib:$JAVA_HOME/jre/lib
export JAVA_HOMEPATH CLASSPATH
[[email protected]~]# source /etc/profile
[[email protected]~]# java -version
java version"1.7.0_17"
|
三、安装Jboss7.1
|
1
2
3
4
|
[[email protected]~]# tar zxvf jboss-as-7.1.1.Final.tar.gz
[[email protected]~]# mv jboss-as-7.1.1.Final /usr/local/jboss7.1
[[email protected]~]# cd /usr/local/jboss7.1/
[[email protected]]# nohup bin/standalone.sh & #后台运行
|
现在还不能通过访问,默认jboss只监听本地,修改如下段:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[[email protected]]# vi standalone/configuration/standalone.xml
<interfaces>
<interfacename="management">
<inet-addressvalue="${jboss.bind.address.management:192.168.1.153}"/>
#web后台管理IP,默认端口是9990 </interface>
<interfacename="public">
<inet-addressvalue="${jboss.bind.address:0.0.0.0}"/>
#jboss监听ip地址,0.0.0.0为所有 </interface>
<!-- TODO - only show this if thejacorb subsystem is added -->
<interfacename="unsecure">
<!--
~ Used for IIOP sockets in the standard configuration.
~ To secure JacORB you need tosetup SSL
-->
<inet-addressvalue="${jboss.bind.address.unsecure:127.0.0.1}"/>
</interface>
</interfaces>
|
重启JBoss
|
1
2
|
[[email protected]]# killall java
[[email protected]]# nohup bin/standalone.sh &
|
首次登陆管理控制后台,提示让你先创建后台的登陆用户和密码
创建用户和密码,将密码生成字符串报错到文件中
现在就可以正常登陆控制后台了
四、Jboss与Apache整合
1.创建mod_jk配置信息
|
1
2
3
4
5
6
7
|
[[email protected] ~]# vi /etc/httpd/conf/mod_jk.conf
JkWorkersFileconf/workers.properties
JkLogFile/var/log/httpd/mod_jk.log
JkShmFile/var/log/httpd/mod_jk.shm
JkLogLevel infoJkMount/servilet/* jboss
JkMount /*.jspjboss #所有jsp文件由jboss处理
|
|
1
2
3
4
5
|
[[email protected] ~]# vi /etc/httpd/conf/workers.properties
worker.list=jbossworker.jboss.type=ajp13 #使用ajp协议1.3版本
worker.jboss.host=127.0.0.1worker.jboss.port=8009 #连接jboss 8009端口
|
2. 添加AJP/1.3协议支持
|
1
2
3
4
5
6
7
8
9
10
|
[[email protected]]# vi standalone/configuration/standalone.xml
</subsystem>
<subsystemxmlns="urn:jboss:domain:web:1.1"default-virtual-server="default-host" native="false">
<connector name="http"protocol="HTTP/1.1" scheme="http"socket-binding="http"/>
<connector name="ajp"protocol="AJP/1.3" scheme="http" socket-binding="ajp"/> #添加ajp支持
<virtual-servername="default-host" enable-welcome-root="true">
<aliasname="localhost"/>
<aliasname="example.com"/>
</virtual-server>
</subsystem>
|
3.创建虚拟主机测试
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[[email protected] ~]# vi /etc/httpd/conf/httpd.conf
Listen192.168.1.153:81Listen192.168.1.153:82<VirtualHost*:81> DocumentRoot/usr/local/jboss7.1/standalone/deployments
ServerName 192.168.1.153
JkMount /* jboss #这个目录下的所有程序都由定义的jboss处理
# ErrorLoglogs/dummy-host.example.com-error_log# CustomLoglogs/dummy-host.example.com-access_log common</VirtualHost>
<VirtualHost*:82> DocumentRoot /opt
ServerName 192.168.1.153
# ErrorLoglogs/dummy-host.example.com-error_log# CustomLoglogs/dummy-host.example.com-access_log common</VirtualHost>
|
#创建jsp测试
|
1
2
3
4
5
6
7
8
|
[[email protected]]# cd standalone/deployments/
[[email protected]]# ls
index.jsp README.txt[[email protected] deployments]#jar cvf test.war index.jsp #将index.jsp用jar工具归档后才可以自动部署
added manifestadding:index.jsp(in = 10) (out= 12)(deflated -20%)
[[email protected]]# ls
index.jsp README.txt test.war test.war.deployed #部署成功后,会生成一个以deployed结果的文件
|
4.分别访问php与jsp程序
五、创建jboss虚拟主机
1.在配置文件添加
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[[email protected] jboss7.1]# vi standalone/configuration/standalone.xml
</subsystem>
<subsystemxmlns="urn:jboss:domain:web:1.1"default-virtual-server="default-host" native="false">
<connector name="http"protocol="HTTP/1.1" scheme="http"socket-binding="http"/>
<connector name="ajp"protocol="AJP/1.3" scheme="http"socket-binding="ajp"/>
<virtual-servername="default-host" enable-welcome-root="false">
<aliasname="localhost"/>
<aliasname="example.com"/>
</virtual-server>
下面添加,name是域名,我以ip代替: <virtual-servername="192.168.1.153" enable-welcome-root="false">
<aliasname="192.168.1.153"/>
</virtual-server>
</subsystem>
|
2.在网站程序里面创建WEB-INF,并创建jboss-web.xml文件
|
1
2
3
4
5
6
7
8
|
[[email protected]]# ls
index.jsp WEB-INF[[email protected]]# vi WEB-INF/jboss-web.xml
<jboss-web> <context-root>/</context-root> #从部署根目录访问
<virtual-host>192.168.1.153</virtual-host> #虚拟主机ip或域名
</jboss-web>
[[email protected]]# jar cvf root.war index.jsp WEB-INF/
|
当使用IP或域名访问时就能根据jboss-web.xml配置文件来读取哪一个应用了。