Chinese To English     英文 轉(zhuǎn) 中文             
                   
          隨筆-27  評論-53  文章-0  trackbacks-0

          JBOSS5.0 Beta4 配置詳解

          一.              下載與安裝JBoss

          在本文中,我下載的JBoss版本為:JBOSS5.0 Beta4

          下載地址: http://www.jboss.org/jbossas/downloads/

          在如上的下載頁中下載JBOSS5.0 Beta4.zip文件。

          下載完成后,將其解壓縮后即可完成安裝,解壓縮后將其放置到一個(gè)不帶空格的目錄(若目錄帶有空格,例如:C:"Program Files,日后可能會產(chǎn)生一些莫名的錯(cuò)誤)egE:"JBossJBOSS5.0 Beta4。同時(shí)在“環(huán)境變量設(shè)置”中設(shè)置名為JBOSS_HOME的環(huán)境變量,值為JBoss的安裝路徑,如下圖所示:

          在此,JBoss的安裝工作已經(jīng)結(jié)束,可通過如下方式測試安裝是否成功:

          運(yùn)行JBoss安裝目錄"bin"run.bat,如果窗口中沒有出現(xiàn)異常,且出現(xiàn):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/ 進(jìn)入JBoss的歡迎界面,點(diǎn)擊JBoss Management下的JMX Console可進(jìn)入JBoss的控制臺。

          若啟動(dòng)失敗,可能由以下原因引起:

          1)              JBoss所用的端口(8080109910988083等)被占用。一般情況下為8080端口被占用(例如,Oracle占用了8080端口),此時(shí)需要修改JBoss的端口,方法為進(jìn)入JBoss安裝目錄"server"default"deploy"jboss-web.deployer目錄,修改其下的server.xml目錄,在此文件中搜索8080,將其改成你想要的端口即可(例如8088);

          2)              JDK安裝不正確;

          3)              JBoss下載不完全。

          二.             JBoss 的目錄結(jié)構(gòu)說明

          目錄

          描述

          bin

          啟動(dòng)和關(guān)閉 JBoss 的腳本( run.bat windows 系統(tǒng)下的啟動(dòng)腳本, shutdown.bat windows 系統(tǒng)下的關(guān)閉腳本)。

          client

          客戶端與 JBoss 通信所需的 Java 庫( JARs )。

          docs

          配置的樣本文件(數(shù)據(jù)庫配置等)。

          docs/dtd

          JBoss 中使用的各種 XML 文件的 DTD

          lib

          一些 JAR JBoss 啟動(dòng)時(shí)加載,且被所有 JBoss 配置共享。(不要把你的庫放在這里)

          server 

          各種 JBoss 配置。每個(gè)配置必須放在不同的子目錄。子目錄的名字表示配置的名字。 JBoss 包含 3 個(gè)默認(rèn)的配置: minimial default all ,在你安裝時(shí)可以進(jìn)行選擇。

          server/all

          JBoss 的完全配置,啟動(dòng)所有服務(wù),包括集群和 IIOP

          server/default

          JBoss 的默認(rèn)配置。在沒有在 JBoss 命令行中指定配置名稱時(shí)使用。 ( 我們下載的 JBOSS5.0 Beta4 版本默認(rèn)采用此配置

          server/default/conf 

          JBoss 的配置文件。

          server/default/data

          JBoss 的數(shù)據(jù)庫文件。比如,嵌入的數(shù)據(jù)庫,或者 JBossMQ

          server/default /deploy

          JBoss 的熱部署目錄。放到這里的任何文件或目錄會被 JBoss 自動(dòng)部署。 EJB WAR EAR ,甚至服務(wù)。

          server/default /lib

          一些 JAR JBoss 在啟動(dòng)特定配置時(shí)加載他們。 (default minimial 配置也包含這個(gè)和下面兩個(gè)目錄。

          server/default/log

          JBoss 的日志文件。

          server/default/tmp

          JBoss 的臨時(shí)文件。

          三.             JBoss 的配置

          1.       日志文件設(shè)置

          若需要修改JBoss默認(rèn)的log4j設(shè)置,可修改JBoss安裝目錄"server"default"conf下的jboss-log4j.xml文件,在該文件中可以看到,log4j的日志輸出在JBoss安裝目錄"server"default"log下的server.log文件中。對于log4j的設(shè)置,讀者可以在網(wǎng)上搜索更加詳細(xì)的信息。

          2.       web 服務(wù)的端口號的修改

          這點(diǎn)在前文中有所提及,即修改JBoss安裝目錄"server"default"deploy"jboss-web.deployer下的server.xml文件,內(nèi)容如下:

          <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端口修改為你想要的端口即可。重新啟動(dòng)JBoss后訪問:http://localhost/:新設(shè)置的端口,可看到JBoss的歡迎界面。

          3.       JBoss 的安全設(shè)置

          1) jmx-console 登錄的用戶名和密碼設(shè)置

          默認(rèn)情況訪問 http://localhost:8080/jmx-console 就可以瀏覽jboss的部署管理的一些信息,不需要輸入用戶名和密碼,使用起來有點(diǎn)安全隱患。下面我們針對此問題對jboss進(jìn)行配置,使得訪問jmx-console也必須要知道用戶名和密碼才可進(jìn)去訪問。步驟如下:

          i) 找到JBoss安裝目錄/server/default/deploy/jmx-console.war/WEB-INF/jboss-web.xml文件,去掉<security-domain>java:/jaas/jmx-console</security-domain>的注釋。修改后的該文件內(nèi)容為:

           

          <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/>節(jié)點(diǎn),去掉它的注釋,修改后該部分內(nèi)容為:

          <!-- 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安全域和第二步中的運(yùn)行角色JBossAdmin都是在login-config.xml中配置,我們在JBoss安裝目錄/server/default/config下找到它。查找名字為:jmx-consoleapplication-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.propertiesjmx-console-users.properties文件中設(shè)置,分別打開這兩個(gè)文件。

          其中jmx-console-users.properties文件的內(nèi)容如下:

           

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

          admin=admin

           

          該文件定義的格式為:用戶名=密碼,在該文件中,默認(rèn)定義了一個(gè)用戶名為admin,密碼也為admin的用戶,讀者可將其改成所需的用戶名和密碼。

          jmx-console-roles.properties的內(nèi)容如下:

           

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

          admin=JBossAdmin, HttpInvoker

           

          該文件定義的格式為:用戶名=角色,多個(gè)角色以“,”隔開,該文件默認(rèn)為admin用戶定義了JBossAdminHttpInvoker這兩個(gè)角色。

          配置完成后讀者可以通過訪問: http://localhost:8088/jmx-console/ ,輸入jmx-console-roles.properties文件中定義的用戶名和密碼,訪問jmx-console的頁面。

          2) web-console 登錄的用戶名和密碼設(shè)置

          默認(rèn)情況下,用戶訪問JBossweb-console時(shí),不需要輸入用戶名和密碼,為了安全起見,我們通過修改配置來為其加上用戶名和密碼。步驟如下:

          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>的注釋,修改后的文件內(nèi)容為:

          <?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>部分的注釋,修改后的該部分內(nèi)容為:

          <!-- 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,可找到如下內(nèi)容:

          <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>


            在文件中可以看到,設(shè)置登錄web-console的用戶名和角色等信息分別在login-config.xml文件所在目錄下的web-console-users.propertiesweb-console-roles.properties文件中,但因?yàn)樵撃夸浵聼o這兩個(gè)文件,我們在JBoss安裝目錄"server"default"conf"props目錄下建立這兩個(gè)文件,文件內(nèi)容可參考在“jmx-console登錄的用戶名和密碼設(shè)置”中的兩個(gè)相應(yīng)的配置文件的內(nèi)容,web-console-users.properties文件的內(nèi)容如下:

           

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

          admin=admin

           

          web-console-roles.properties文件的內(nèi)容如下:


           

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

          admin=JBossAdmin,HttpInvoker

          因?yàn)榇藭r(shí)這兩個(gè)文件不與login-config.xml同目錄,所以login-config.xml文件需進(jìn)行少許修改,修改后的<application-policy name = "web-console">元素的內(nèi)容為:

          <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

          進(jìn)入Window-> Preferences-> MyEclipse -> Application Servers -> JBoss5,進(jìn)行如下設(shè)置:
              

          選擇JBoss 5下的JDK設(shè)置所用的JDK.

          好了,開始JBoss之旅吧.


                 ----------------------------------------------------------------------------------------
                 本文轉(zhuǎn)載自:http://www.aygfsteel.com/supercrsky/articles/226139.html
                         

          杰森 
          郵箱:json.shen(at)gmail.com
          網(wǎng)站:www.shenjia.org
          posted on 2009-03-10 17:10 杰森 閱讀(787) 評論(0)  編輯  收藏 所屬分類: JavaEE
          嗨117
          主站蜘蛛池模板: 阿鲁科尔沁旗| 平邑县| 沙坪坝区| 山阳县| 荥阳市| 墨江| 保德县| 武胜县| 衡阳市| 西峡县| 五常市| 鞍山市| 平利县| 修水县| 安义县| 腾冲县| 仁化县| 厦门市| 子长县| 安吉县| 临桂县| 吉木乃县| 眉山市| 两当县| 全椒县| 凤凰县| 鄯善县| 新晃| 晋中市| 时尚| 南投市| 马边| 额尔古纳市| 故城县| 抚松县| 襄垣县| 东乡| 射洪县| 东方市| 安阳县| 泰宁县|