Wildfly 9 部署簡(jiǎn)介 (Domain方式)

簡(jiǎn)要介紹

Wildfly是一個(gè)開源的基于JavaEE的輕量級(jí)應(yīng)用服務(wù)器缰冤,最新版本是Wildfly 10,遵循LGPL許可喳魏,意味著可以在任何商業(yè)應(yīng)用中免費(fèi)使用锋谐。具有啟動(dòng)速度快、輕量截酷、強(qiáng)大的管理界面涮拗、支持JavaEE7(Wildfly 10)、易于測(cè)試等特性迂苛。
但是一旦說起Wildfly三热,我們一定要提到JBoss,Wildfly既是JBoss改名而來三幻。2006年就漾,JBoss被Redhat公司收購(gòu)。 JBoss AS目前作為Redhat公司的商業(yè)產(chǎn)品JBoss Enterprise Application Platform的上游基礎(chǔ)念搬,為了使這兩個(gè)產(chǎn)品有差異化抑堡,避免用戶混淆,因此該公司在去年10月份就尋求為JBoss AS找一個(gè)新名字朗徊。

Wildfly

RedHat公司稱首妖,新名稱WildFly反映了服務(wù)器“非常靈活、輕量爷恳、不羈有缆、自由”的特性。**其實(shí)就是更新會(huì)快些,可以不再那么束縛開發(fā)者棚壁,而且商業(yè)版本還能有錢賺杯矩。但是不管怎么說,對(duì)于JBoss袖外、開發(fā)者史隆、使用者都是好的! **

本文僅僅是介紹基礎(chǔ)操作和安裝配置曼验,更詳細(xì)逆害、準(zhǔn)確、進(jìn)階的蚣驼,請(qǐng)查看官方文檔:
https://docs.jboss.org/author/display/WFLY9/Documentation

基礎(chǔ)知識(shí) & 操作說明

以下內(nèi)容將使用網(wǎng)頁端控制臺(tái),沒有安裝好Wildfly的請(qǐng)先安裝和配置相艇。

Wildfly Deployments

Deployments是指server相關(guān)的項(xiàng)目部署颖杏,server與deployments是分開的,一個(gè)server可以有多個(gè)deployments坛芽,一個(gè)deployments可以指向多個(gè)server留储。這點(diǎn)與Weblogic是一樣的。

新增deployment

這里只講解unmanaged deployment咙轩,這樣可以指定一個(gè)部署路徑(需要指向的Server所在Host的部署路徑)获讳,而不需要上傳項(xiàng)目EAR文件。
在deployments中配置的路徑活喊,是指此deployments所要分配的server所在host的路徑丐膝,而并非Domain主機(jī)的路徑。
選擇 Create an unmanaged deployment

Add Deploy Step 1

Path填寫項(xiàng)目部署文件路徑钾菊,注意這里的Runtime Name必需以.war結(jié)尾
Add Deploy Step 2

分配deployment

新增deployments之后帅矗,需要分配到已創(chuàng)建的server group,以運(yùn)行此deployment
注意這里是分配給server group煞烫,而不能直接分配給server浑此,這是因?yàn)閃ildfly注重可擴(kuò)展、易管理的操作方式滞详。這點(diǎn)在之后的Profiles凛俱、Groups會(huì)講到。


Assign Deploy

Wildfly Configuration

Configuration 中可以配置Profiles料饥、Socket Binding蒲犬,這是運(yùn)行一個(gè)server基本的配置項(xiàng)。

Wildfly Profiles

Profiles是一個(gè)定義ServerGroup配置的集合岸啡,你可以配置所有關(guān)于應(yīng)用容器相關(guān)的內(nèi)容暖哨,例如Datasources、Logging、Web Services等等篇裁。Wildfly內(nèi)置了default/full/full-ha/ha四個(gè)Profile沛慢。

Profiles

Basically,你的項(xiàng)目用不到這其中的任何配置达布,最常見的是使用Datasources团甲,這需要你在項(xiàng)目中支持Wildfly的框架,比如你怎么連接到Wildfly提供的JNDI的代碼段黍聂。

這里我們直接使用內(nèi)置的任何一個(gè)都可以躺苦,并不會(huì)對(duì)我們的項(xiàng)目產(chǎn)生影響。

Wildfly Socket Binding

Socket Binding

Socket binding定義了在指定的網(wǎng)絡(luò)接口啟用HTTP/HTTPS等方式的起始端口的配置产还,支持MuiltCast方式匹厘,但是暫時(shí)沒有用到。

注意脐区,這里的Socket binding是用于Server Group的愈诚,在此Server Group中的Server根據(jù)需要,指定端口偏移值牛隅,才是Server的端口炕柔。
例如,Socket Binding中的standard-sockets定義了http端口是8080媒佣,如果test-group應(yīng)用了standard-sockets匕累,test-group其中的test-server-1在創(chuàng)建時(shí),必需設(shè)定8080的偏移值默伍,如果是1欢嘿,則test-server-1的http訪問方式為IP:8081。

更改起始端口

選擇需要更改的Socket類型也糊,例如https际插,點(diǎn)擊edit修改起始端口


Update Port

Wildfly Runtime

Runtime,運(yùn)行時(shí)显设。用于管理應(yīng)用容器的運(yùn)行時(shí)生命周期框弛,例如新增、啟動(dòng)捕捂、停止等等瑟枫。

Runtime

Wildfly Host

Host即主機(jī),你需要一個(gè)用于運(yùn)行Server的host指攒,這個(gè)就是domain/configuration/host.xml中配置的主機(jī)慷妙。每個(gè)主機(jī)的wildfly服務(wù)在啟動(dòng)之后,將連接到Domain允悦,由Domain統(tǒng)一管理膝擂。
包括Domain自身也屬于一個(gè)host,只不過同時(shí)是管理Domain的入口。
所有的Host在Domain看來都是一致的架馋,每個(gè)Host中運(yùn)行的Wildfly版本應(yīng)該一致狞山,而且Domain可以訪問他們?nèi)魏我粋€(gè)Host。

Wildfly Server Group

Server Group是同一業(yè)務(wù)類型的Server的集合叉寂,可以批量的管理在該集合之下的所有server萍启,
Wildfly中使用了Server Group強(qiáng)制代替了直接管理Server的方式,也就是說屏鳍,在創(chuàng)建Server之前勘纯,你必須要?jiǎng)?chuàng)建Server Group,再在這個(gè)Server Group中創(chuàng)建Server钓瞭。

創(chuàng)建 Server Group

指定需要使用的Profile驳遵、Socket Binding,從而基本定義了這個(gè)Server Group山涡。


Add Server Group

Wildfly Server

這里的Server才是最終運(yùn)行的服務(wù)堤结,但是Server自身只能定義自己的端口偏移值,JVM參數(shù)佳鳖,System Properties等信息,其他的都由Server Group使用的Profiles和Socket Binding配置媒惕。

創(chuàng)建 Server

你需要指定此Server運(yùn)行于哪個(gè)Host系吩,屬于哪個(gè)Server Group,端口偏移值和是否需要自啟動(dòng)等信息妒蔚。


Add Server

更新 Server JVM

Config Server

安裝和配置

這里開始講解如何以Domain方式安裝和配置Wildfly穿挨,在配置并啟動(dòng)后,所有其他操作盡量在網(wǎng)頁控制臺(tái)中進(jìn)行肴盏,不要隨意更改domain.xml或者h(yuǎn)ost.xml
Domain的方式即一個(gè)管理節(jié)點(diǎn)(domain)科盛,多個(gè)受控節(jié)點(diǎn)(slave)。

DOMAIN & SLAVE: 安裝JDK

[root@localhost opt]# ll
total 138892
-rw-r--r--. 1 root root 142216602 Jun  1 17:31 jdk-7u71-linux-x64.tar.gz
drwxr-xr-x. 2 root root      4096 May 10  2012 rh
[root@localhost opt]# tar zxf jdk-7u71-linux-x64.tar.gz

DOMAIN & SLAVE: 安裝Wildfly

## 將wildfly的安裝包放置在用戶目錄下
[irm@localhost ~]$ tar zxf wildfly-9.0.2.Final.tar.gz

DOMAIN & SLAVE: 配置環(huán)境變量

[irm@localhost ~]$ vi .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

JAVA_HOME=/opt/jdk1.7.0_71
export JBOSS_HOME=/home/irm/wildfly-9.0.2.Final
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export PATH

DOMAIN : 創(chuàng)建Wildfly管理用戶

[irm@localhost ~]$ wildfly-9.0.2.Final/bin/add-user.sh 
What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
# 輸入a菜皂,以添加管理用戶
(a): a

Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
# 輸入用戶名
Username : test
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password should be different from the username
 - The password should not be one of the following restricted values {root, admin, administrator}
 - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
# 輸入用戶密碼
Password : 
WFLYDM0099: Password should have at least 8 characters!
# 確認(rèn)則輸入yes
Are you sure you want to use the password entered yes/no? yes
# 重新輸入密碼
Re-enter Password : 
# 留空即可
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: 
About to add user 'test' for realm 'ManagementRealm'
# 繼續(xù)則輸入yes
Is this correct yes/no? yes
Added user 'test' to file '/home/irm/wildfly-9.0.2.Final/standalone/configuration/mgmt-users.properties'
Added user 'test' to file '/home/irm/wildfly-9.0.2.Final/domain/configuration/mgmt-users.properties'
Added user 'test' with groups  to file '/home/irm/wildfly-9.0.2.Final/standalone/configuration/mgmt-groups.properties'
Added user 'test' with groups  to file '/home/irm/wildfly-9.0.2.Final/domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process? 
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
# 繼續(xù)則輸入yes
yes/no? yes
這里需要注意贞绵,用戶添加完畢后,將回饋給你此用戶的secret value恍飘,可在domain與slave 的通信中用到榨崩,下文中會(huì)講到
To represent the user add the following to the server-identities definition <secret value="YWFhYWFh" />

DOMAIN: 配置Wildfly Domain

[irm@localhost ~]$ cd wildfly-9.0.2.Final/domain/configuration/
[irm@localhost configuration]$ vi host.xml
<!-- 更改hostname為標(biāo)識(shí)本機(jī)的host名稱,與系統(tǒng)的hostname無關(guān) -->
<host name="irms_host_1" xmlns="urn:jboss:domain:3.0">
....
<!-- 編輯server-identities標(biāo)簽章母,配置文件中沒有的手動(dòng)添加這一段母蛛,更改secret value為剛剛添加用戶返回的值 -->
<management>
        <security-realms>
            <security-realm name="ManagementRealm">
                <server-identities>
                    <secret value="YWFhYWFh"/>
                </server-identities>
<!-- 注意下面的http-interface security-realm="ManagementRealm" 是與slave配置的不同之處,slave沒有這段配置 -->
    <management-interfaces>
        <native-interface security-realm="ManagementRealm">
            <socket interface="management" port="${jboss.management.native.port:9999}"/>
        </native-interface>
        <http-interface security-realm="ManagementRealm" http-upgrade-enabled="true">
            <socket interface="management" port="${jboss.management.http.port:9990}"/>
        </http-interface>
    </management-interfaces>
....
<!--這里的domain-controller中的內(nèi)容是空的乳怎,因?yàn)楸緳C(jī)服務(wù)器是domain彩郊,所以無需指定誰是controller-->
    <domain-controller>
        <local/>
    </domain-controller>
....
<!-- 編輯下面的IP地址為本機(jī)的IP地址 -->
    <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:10.174.243.1}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:10.174.243.1}"/>
        </interface>
        <interface name="unsecure">
            <inet-address value="${jboss.bind.address.unsecure:10.174.243.1}"/>
        </interface>
    </interfaces>
....
    <!--清空servers標(biāo)簽中的內(nèi)容,原內(nèi)容為server 的example-->
    <servers>

    </servers>

SLAVE: 配置Wildfly Slave

[irm@localhost ~]$ cd wildfly-9.0.2.Final/domain/configuration/
#### 刪除domain.xml,或者重命名
[irm@localhost configuration]$ mv domain.xml domain.xml_bak
#### 編輯slave配置文件
[irm@localhost configuration]$ vi host.xml
<!-- 更改hostname為標(biāo)識(shí)本機(jī)的host名稱秫逝,與系統(tǒng)的hostname無關(guān) -->
<host name="hostname" xmlns="urn:jboss:domain:3.0">
.....
<!-- 編輯server-identities標(biāo)簽恕出,配置文件中沒有的手動(dòng)添加這一段,更改secret value為與domain一樣的配置 -->
<management>
        <security-realms>
            <security-realm name="ManagementRealm">
                <server-identities>
                    <secret value="YWFhYWFh"/>
                </server-identities>
<!-- 更改domain-controller中的host為Wildfly Domain的IP地址 -->
<domain-controller>
        <remote protocol="remote" host="10.174.243.1" port="9999" security-realm="ManagementRealm" username="slave"/>
    </domain-controller>
<!-- 更改下面三個(gè)IP地址為本機(jī)IP地址-->
    <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:10.174.243.5}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:10.174.243.5}"/>
        </interface>
        <interface name="unsecure">
            <inet-address value="${jboss.bind.address.unsecure:10.174.243.5}"/>
        </interface>
    </interfaces>
....
    <!--清空servers標(biāo)簽中的內(nèi)容筷登,原內(nèi)容為server 的example-->
    <servers>

    </servers>

DOMAIN & SLAVE: 配置系統(tǒng)服務(wù)

#### 編輯Wildfly服務(wù)所需的配置文件
[root@localhost /]# vi /etc/default/wildfly.conf
## JDK目錄
JAVA_HOME="/opt/jdk1.7.0_71"

## JBOSS_HOME是Wildfly的安裝根目錄
JBOSS_HOME="/home/irm/wildfly-9.0.2.Final"

## 這里需要改為執(zhí)行wildfly的用戶
JBOSS_USER=irm

## 指定運(yùn)行模式為domain
JBOSS_MODE=domain

## 指定domain的配置文件為domain.xml剃根,slave的配置文件為host.xml
JBOSS_DOMAIN_CONFIG=domain.xml
JBOSS_HOST_CONFIG=host.xml
# 安裝和啟用服務(wù),先啟動(dòng)Domain的服務(wù)前方,再啟動(dòng)各個(gè)Slave
[root@localhost /]# cp wildfly-9.0.2.Final/bin/init.d/wildfly-init-redhat.sh /etc/init.d/wildfly
[root@localhost /]# chmod +x /etc/init.d/wildfly
[root@localhost /]# chkconfig --add wildfly
[root@localhost /]# chkconfig wildfly on
[root@localhost /]# service wildfly start

訪問Wildfly

在瀏覽器中訪問http://DomainIP:9990/console/App.html 以管理Wildfly狈醉,這里的用戶名和密碼是在運(yùn)行add-user.sh時(shí)配置的。

需注意的問題

  • Wildfly 9 的控制臺(tái)對(duì)IE瀏覽器支持不佳惠险,盡量使用Chrome或者其他瀏覽器代替
  • deployments的runtime name必需以.war結(jié)尾
  • 如果項(xiàng)目中使用了slf4j苗傅,或者項(xiàng)目中包含log4j.properties,則需要禁用Wildfly自身的日志功能班巩,因?yàn)檫@會(huì)產(chǎn)生沖突
    在項(xiàng)目的WEB-INF目錄中渣慕,編輯或新增jboss-deployment-structure.xml文件,內(nèi)容如下:
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclusions>
            <module name="org.apache.commons.logging" />
            <module name="org.apache.log4j" />
            <module name="org.jboss.logging" />
            <module name="org.jboss.logging.jul-to-slf4j-stub" />
            <module name="org.jboss.logmanager" />
            <module name="org.jboss.logmanager.log4j" />
            <module name="org.slf4j" />
            <module name="org.slf4j.impl" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>
  • 如果需要禁用Wildfly的歡迎頁面抱慌,需在項(xiàng)目的WEB-INF目錄中逊桦,編輯或新增jboss-deployment-structure.xml文件,內(nèi)容如下:
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <exclude-subsystems>
            <subsystem name="webservices" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>
  • 指定項(xiàng)目需要使用的URL后綴抑进,即location强经,需編輯或新增項(xiàng)目中的WEB-INF/jboss-web.xml,內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/test</context-root>
</jboss-web>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末寺渗,一起剝皮案震驚了整個(gè)濱河市匿情,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌信殊,老刑警劉巖炬称,帶你破解...
    沈念sama閱讀 219,366評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異涡拘,居然都是意外死亡玲躯,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門鳄乏,熙熙樓的掌柜王于貴愁眉苦臉地迎上來府蔗,“玉大人,你說我怎么就攤上這事汞窗⌒粘啵” “怎么了?”我有些...
    開封第一講書人閱讀 165,689評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵仲吏,是天一觀的道長(zhǎng)不铆。 經(jīng)常有香客問我蝌焚,道長(zhǎng),這世上最難降的妖魔是什么誓斥? 我笑而不...
    開封第一講書人閱讀 58,925評(píng)論 1 295
  • 正文 為了忘掉前任只洒,我火速辦了婚禮,結(jié)果婚禮上劳坑,老公的妹妹穿的比我還像新娘毕谴。我一直安慰自己,他們只是感情好距芬,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,942評(píng)論 6 392
  • 文/花漫 我一把揭開白布涝开。 她就那樣靜靜地躺著,像睡著了一般框仔。 火紅的嫁衣襯著肌膚如雪舀武。 梳的紋絲不亂的頭發(fā)上太颤,一...
    開封第一講書人閱讀 51,727評(píng)論 1 305
  • 那天揍障,我揣著相機(jī)與錄音蓝角,去河邊找鬼潦蝇。 笑死,一個(gè)胖子當(dāng)著我的面吹牛移国,可吹牛的內(nèi)容都是我干的兆龙。 我是一名探鬼主播壁熄,決...
    沈念sama閱讀 40,447評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼核偿,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼诚欠!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起宪祥,我...
    開封第一講書人閱讀 39,349評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤聂薪,失蹤者是張志新(化名)和其女友劉穎家乘,沒想到半個(gè)月后蝗羊,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,820評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡仁锯,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,990評(píng)論 3 337
  • 正文 我和宋清朗相戀三年耀找,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片业崖。...
    茶點(diǎn)故事閱讀 40,127評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡野芒,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出双炕,到底是詐尸還是另有隱情狞悲,我是刑警寧澤,帶...
    沈念sama閱讀 35,812評(píng)論 5 346
  • 正文 年R本政府宣布妇斤,位于F島的核電站摇锋,受9級(jí)特大地震影響丹拯,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜荸恕,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,471評(píng)論 3 331
  • 文/蒙蒙 一乖酬、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧融求,春花似錦咬像、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至茅糜,卻和暖如春七芭,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背蔑赘。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工狸驳, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人缩赛。 一個(gè)月前我還...
    沈念sama閱讀 48,388評(píng)論 3 373
  • 正文 我出身青樓耙箍,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親酥馍。 傳聞我的和親對(duì)象是個(gè)殘疾皇子辩昆,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,066評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容