簡(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è)新名字朗徊。
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
Path填寫項(xiàng)目部署文件路徑钾菊,注意這里的Runtime Name必需以.war結(jié)尾
分配deployment
新增deployments之后帅矗,需要分配到已創(chuàng)建的server group,以運(yùn)行此deployment
注意這里是分配給server group煞烫,而不能直接分配給server浑此,這是因?yàn)閃ildfly注重可擴(kuò)展、易管理的操作方式滞详。這點(diǎn)在之后的Profiles凛俱、Groups會(huì)講到。
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沛慢。
Basically,你的項(xiàng)目用不到這其中的任何配置达布,最常見的是使用Datasources团甲,這需要你在項(xiàng)目中支持Wildfly的框架,比如你怎么連接到Wildfly提供的JNDI的代碼段黍聂。
這里我們直接使用內(nèi)置的任何一個(gè)都可以躺苦,并不會(huì)對(duì)我們的項(xiàng)目產(chǎn)生影響。
Wildfly 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修改起始端口
Wildfly Runtime
Runtime,運(yùn)行時(shí)显设。用于管理應(yīng)用容器的運(yùn)行時(shí)生命周期框弛,例如新增、啟動(dòng)捕捂、停止等等瑟枫。
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山涡。
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)等信息妒蔚。
更新 Server JVM
安裝和配置
這里開始講解如何以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>