您的位置:首页 > 其它

JBOSS5.0 Beta4 配置详解(转)

2008-10-29 14:20 381 查看
一. 下载与安装JBoss
在本文中,我下载的JBoss版本为:JBOSS5.0 Beta4。
下载地址: http://www.jboss.org/jbossas/downloads/
在如上的下载页中下载JBOSS5.0 Beta4.zip文件。
下载完成后,将其解压缩后即可完成安装,解压缩后将其放置到一个不带空格的目录(若目录带有空格,例如:C:"Program Files,日后可能会产生一些莫名的错误),eg:E:"JBossJBOSS5.0 Beta4。同时在“环境变量设置”中设置名为JBOSS_HOME的环境变量,值为JBoss的安装路径,如下图所示:



在此,JBoss的安装工作已经结束,可通过如下方式测试安装是否成功:
运行JBoss安装目录"bin"run.bat,如果窗口中没有出现异常,且出现:10:16:19,765 INFO [Server] JBoss (MX MicroKernel) [5.0.Beta4 (build: SVNTag=5.0.Beta4 date=20080831605)] Started in 30s:828ms字样,则表示安装成功。
我们可以通过访问: http://localhost:8080/ 进入JBoss的欢迎界面,点击JBoss Management下的JMX Console可进入JBoss的控制台。
若启动失败,可能由以下原因引起:
1) JBoss所用的端口(8080,1099,1098,8083等)被占用。一般情况下为8080端口被占用(例如,Oracle占用了8080端口),此时需要修改JBoss的端口,方法为进入JBoss安装目录"server"default"deploy"jboss-web.deployer目录,修改其下的server.xml目录,在此文件中搜索8080,将其改成你想要的端口即可(例如8088);
2) JDK安装不正确;
3) JBoss下载不完全。
二. JBoss 的目录结构说明
目录
描述
bin
启动和关闭 JBoss 的脚本( run.bat 为 windows 系统下的启动脚本, shutdown.bat 为 windows 系统下的关闭脚本)。
client
客户端与 JBoss 通信所需的 Java 库( JARs )。
docs
配置的样本文件(数据库配置等)。
docs/dtd
在 JBoss 中使用的各种 XML 文件的 DTD 。
lib
一些 JAR , JBoss 启动时加载,且被所有 JBoss 配置共享。(不要把你的库放在这里)
server
各种 JBoss 配置。每个配置必须放在不同的子目录。子目录的名字表示配置的名字。 JBoss 包含 3 个默认的配置: minimial , default 和 all ,在你安装时可以进行选择。
server/all
JBoss 的完全配置,启动所有服务,包括集群和 IIOP 。
server/default
JBoss 的默认配置。在没有在 JBoss 命令行中指定配置名称时使用。 ( 我们下载的 JBOSS5.0 Beta4 版本默认采用此配置 ) 。
server/default/conf
JBoss 的配置文件。
server/default/data
JBoss 的数据库文件。比如,嵌入的数据库,或者 JBossMQ
server/default /deploy
JBoss 的热部署目录。放到这里的任何文件或目录会被 JBoss 自动部署。 EJB 、 WAR 、 EAR ,甚至服务。
server/default /lib
一些 JAR , JBoss 在启动特定配置时加载他们。 (default 和 minimial 配置也包含这个和下面两个目录。 )
server/default/log
JBoss 的日志文件。
server/default/tmp
JBoss 的临时文件。
三. JBoss 的配置
1. 日志文件设置
若需要修改JBoss默认的log4j设置,可修改JBoss安装目录"server"default"conf下的jboss-log4j.xml文件,在该文件中可以看到,log4j的日志输出在JBoss安装目录"server"default"log下的server.log文件中。对于log4j的设置,读者可以在网上搜索更加详细的信息。
2. web 服务的端口号的修改
这点在前文中有所提及,即修改JBoss安装目录"server"default"deploy"jboss-web.deployer下的server.xml文件,内容如下:
<Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
将上面的8080端口修改为你想要的端口即可。重新启动JBoss后访问:http://localhost/:新设置的端口,可看到JBoss的欢迎界面。
3. JBoss 的安全设置
1) jmx-console 登录的用户名和密码设置
默认情况访问 http://localhost:8080/jmx-console 就可以浏览jboss的部署管理的一些信息,不需要输入用户名和密码,使用起来有点安全隐患。下面我们针对此问题对jboss进行配置,使得访问jmx-console也必须要知道用户名和密码才可进去访问。步骤如下:
i) 找到JBoss安装目录/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml文件,去掉<security-domain>java:/jaas/jmx-console</security-domain>的注释。修改后的该文件内容为:


<jboss-web>




<!-- Uncomment the security-domain to enable security. You will




need to edit the htmladaptor login configuration to setup the




login modules used to authentication users.-->




<security-domain>java:/jaas/jmx-console</security-domain>




</jboss-web>



ii)修改与i)中的jboss-web.xml同级目录下的web.xml文件,查找到<security-constraint/>节点,去掉它的注释,修改后该部分内容为:


<!-- A security constraint that restricts access to the HTML JMX console




to users with the role JBossAdmin. Edit the roles to what you want and




uncomment the WEB-INF/jboss-web.xml/security-domain element to enable




secured access to the HTML JMX console.-->




<security-constraint>




<web-resource-collection>




<web-resource-name>HtmlAdaptor</web-resource-name>




<description>An example security config that only allows users with the




role JBossAdmin to access the HTML JMX console web application




</description>




<url-pattern>/*</url-pattern>




<http-method>GET</http-method>




<http-method>POST</http-method>




</web-resource-collection>




<auth-constraint>




<role-name>JBossAdmin</role-name>




</auth-constraint>




</security-constraint>





在此处可以看出,为登录配置了角色JBossAdmin。
iii) 在第一步中的jmx-console安全域和第二步中的运行角色JBossAdmin都是在login-config.xml中配置,我们在JBoss安装目录/server/default/config下找到它。查找名字为:jmx-console的application-policy:


<application-policy name = "jmx-console">


<authentication>


<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"


flag = "required">


<module-option name="usersProperties">props/jmx-console-users.properties</module-option>


<module-option name="rolesProperties">props/jmx-console-roles.properties</module-option>


</login-module>


</authentication>


</application-policy>

在此处可以看出,登录的角色、用户等的信息分别在props目录下的jmx-console-roles.properties和jmx-console-users.properties文件中设置,分别打开这两个文件。
其中jmx-console-users.properties文件的内容如下:


# A sample users.properties file for use with the UsersRolesLoginModule




admin=admin



该文件定义的格式为:用户名=密码,在该文件中,默认定义了一个用户名为admin,密码也为admin的用户,读者可将其改成所需的用户名和密码。
jmx-console-roles.properties的内容如下:


# A sample roles.properties file for use with the UsersRolesLoginModule




admin=JBossAdmin, HttpInvoker



该文件定义的格式为:用户名=角色,多个角色以“,”隔开,该文件默认为admin用户定义了JBossAdmin和HttpInvoker这两个角色。
配置完成后读者可以通过访问: http://localhost:8088/jmx-console/ ,输入jmx-console-roles.properties文件中定义的用户名和密码,访问jmx-console的页面。
2) web-console 登录的用户名和密码设置
默认情况下,用户访问JBoss的web-console时,不需要输入用户名和密码,为了安全起见,我们通过修改配置来为其加上用户名和密码。步骤如下:
i)找到JBoss安装目录"server"default"deploy"management"console-mgr.sar"web-console.war"WEB-INF"jboss-web.xml文件,去掉<security-domain>java:/jaas/web-console</security-domain>的注释,修改后的文件内容为:


<?xml version='1.0' encoding='UTF-8' ?>




<!DOCTYPE jboss-web




PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"




"http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">




<jboss-web>




<!-- Uncomment the security-domain to enable security. You will




need to edit the htmladaptor login configuration to setup the




login modules used to authentication users.-->




<security-domain>java:/jaas/web-console</security-domain>




<!-- The war depends on the -->




<depends>jboss.admin:service=PluginManager</depends>




</jboss-web>





ii)打开i)中jboss-web.xml同目录下的web.xml文件,去掉<security-constraint>部分的注释,修改后的该部分内容为:


<!-- A security constraint that restricts access to the HTML JMX console




to users with the role JBossAdmin. Edit the roles to what you want and




uncomment the WEB-INF/jboss-web.xml/security-domain element to enable




secured access to the HTML JMX console.-->




<security-constraint>




<web-resource-collection>




<web-resource-name>HtmlAdaptor</web-resource-name>




<description>An example security config that only allows users with the




role JBossAdmin to access the HTML JMX console web application




</description>




<url-pattern>/*</url-pattern>




<http-method>GET</http-method>




<http-method>POST</http-method>




</web-resource-collection>




<auth-constraint>




<role-name>JBossAdmin</role-name>




</auth-constraint>




</security-constraint>





iii)打开JBoss安装目录"server"default"conf下的login-config.xml文件,搜索web-console,可找到如下内容:


<application-policy name = "web-console">




<authentication>




<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"




flag = "required">




<module-option name="usersProperties">web-console-users.properties</module-option>




<module-option name="rolesProperties">web-console-roles.properties</module-option>




</login-module>




</authentication>




</application-policy>





在文件中可以看到,设置登录web-console的用户名和角色等信息分别在login-config.xml文件所在目录下的web-console-users.properties和web-console-roles.properties文件中,但因为该目录下无这两个文件,我们在JBoss安装目录"server"default"conf"props目录下建立这两个文件,文件内容可参考在“jmx-console登录的用户名和密码设置”中的两个相应的配置文件的内容,web-console-users.properties文件的内容如下:


# A sample users.properties file for use with the UsersRolesLoginModule




admin=admin



web-console-roles.properties文件的内容如下:


# A sample roles.properties file for use with the UsersRolesLoginModule




admin=JBossAdmin,HttpInvoker





因为此时这两个文件不与login-config.xml同目录,所以login-config.xml文件需进行少许修改,修改后的<application-policy name = "web-console">元素的内容为:



<application-policy name = "web-console">





<authentication>




<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"




flag
= "required">




<module-option name="usersProperties">props/web-console-users.properties</module-option>




<module-option name="rolesProperties">props/web-console-roles.properties</module-option>




</login-module>




</authentication>




</application-policy>







四.
在MyEclipse 中配置JBoss
笔者的MyEclipse版本:6.5 GA
JBoss版本:5.0

JDK版本:1.6
进入Window-> Preferences-> MyEclipse -> Application Servers -> JBoss5,进行如下设置:



选择JBoss 5下的JDK设置所用的JDK.
好了,开始JBoss之旅吧.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: