本文首先介绍Managed Domain的概念,管理域最主要的功能是“统一部署,统一配置”。接下来通过一个实例在“统一配置”部分实现一个双机配置起来的域,最后在“统一部署”部分,我们将一个war包部署到域组的所有成员当中并测试部署效果。
管理域组织各物理机上的虚拟服务为服务组,使得所有服务器在一个地方统一配置、统一部署。配置为同一服务组内的机器可以自动扩展,也可以在一台主机上根据不同的端口绑定来设置多个实例。Managed Domain要区别与Cluster,Cluster的主要功能是负载均衡、容灾,而Managed domain的目的主要在于统一管理。
二、Managed domains的统一配置
此配置的主要内容是6台虚拟机,分别在两台物理主机上。两台主机分别取名为Master(192.168.0.115)和Server2(192.168.0.116)。由Master来负责整个Domain的统一配置和统一部署。
wzdacyl@leo115:~/Downloads/server/jboss-eap-6.2/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): <strong>a</strong> Enter the details of the new user to add. Using realm 'ManagementRealm' as discovered from the existing property files. Username : <strong>admin</strong> Password : Re-enter Password : What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[ ]: Updated user 'admin' to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/standalone/configuration/mgmt-users.properties' Updated user 'admin' to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/domain/configuration/mgmt-users.properties' Updated user 'admin' with groups to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/standalone/configuration/mgmt-groups.properties' Updated user 'admin' with groups to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/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. yes/no? yes To represent the user add the following to the server-identities definition <secret value="<strong>YTgxNTcyOCs=</strong>" />
wzdacyl@leo115:~/Downloads/server/jboss-eap-6.2/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): <strong>a</strong> Enter the details of the new user to add. Using realm 'ManagementRealm' as discovered from the existing property files. Username : <strong>server2</strong> Password : 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 'server2' for realm 'ManagementRealm' Is this correct yes/no? yes Added user 'server2' to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/standalone/configuration/mgmt-users.properties' Added user 'server2' to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/domain/configuration/mgmt-users.properties' Added user 'server2' with groups to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/standalone/configuration/mgmt-groups.properties' Added user 'server2' with groups to file '/home/wzdacyl/Downloads/server/jboss-eap-6.2/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. yes/no? yes To represent the user add the following to the server-identities definition <secret value="<strong>YTgxNTcyOCs=</strong>" />
进入主机server2,编辑$JBOSS_HOME/domain/configuration/host.xml,添加粗体部分,
<?xml version='1.0' encoding='UTF-8'?> <host <strong>name="server2"</strong> xmlns="urn:jboss:domain:1.5"> <management> <security-realms> <security-realm name="ManagementRealm"> <strong><server-identities> <secret value="YTgxNTcyOCs="/> </server-identities></strong>
server2的host.xml的<management>标签后加入<domain-controller>标签,如下,
<domain-controller> <!-- Alternative remote domain controller configuration with a host and port --> <remote host="<strong>192.168.0.115</strong>" port="<strong>9999</strong>" security-realm="<strong>ManagementRealm</strong>"/> </domain-controller>
配置Master的host.xml,找到interfaces标签,将其中的127.0.0.1修改为本机IP(192.168.0.115),使得外界能够访问到jboss在本机上的服务。
<interfaces> <interface name="management"> <inet-address value="${jboss.bind.address.management:192.168.0.115}"/> </interface> <interface name="public"> <inet-address value="${jboss.bind.address:192.168.0.115}"/> </interface> <interface name="unsecure"> <!-- Used for IIOP sockets in the standard configuration. To secure JacORB you need to setup SSL --> <inet-address value="${jboss.bind.address.unsecure:192.168.0.115}"/> </interface> </interfaces>
配置Server2的host.xml,找到interfaces标签,将其中的127.0.0.1修改为本机IP(192.168.0.116),使得外界能够访问到jboss在本机上的服务。
<interfaces> <interface name="management"> <inet-address value="${jboss.bind.address.management:192.168.0.116}"/> </interface> <interface name="public"> <inet-address value="${jboss.bind.address:192.168.0.116}"/> </interface> <interface name="unsecure"> <!-- Used for IIOP sockets in the standard configuration. To secure JacORB you need to setup SSL --> <inet-address value="${jboss.bind.address.unsecure:192.168.0.116}"/> </interface> </interfaces>
配置Master的host.xml,找到servers标签,做如下修改。
<servers> <!-- server name="server-one" group="main-server-group" --> <server name="server-one" group="other-server-group"> <!-- Remote JPDA debugging for a specific server <jvm name="default"> <jvm-options> <option value="-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"/> </jvm-options> </jvm> --> </server> <server name="server-two" group="other-server-group" auto-start="true"> <!-- server-two avoids port conflicts by incrementing the ports in the default socket-group declared in the server-group --> <socket-bindings port-offset="150"/> </server> <server name="server-three" group="other-server-group" auto-start="true"> <!-- server-three avoids port conflicts by incrementing the ports in the default socket-group declared in the server-group --> <socket-bindings port-offset="250"/> </server> </servers>
配置server2的domain.xml,找到servers标签,做如下修改。
<span style="font-size:12px;"> <servers> <server name="server-four" group="main-server-group"> <!-- Remote JPDA debugging for a specific server <jvm name="default"> <jvm-options> <option value="-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"/> </jvm-options> </jvm> --> </server> <server name="server-five" group="main-server-group" auto-start="true"> <!-- server-two avoids port conflicts by incrementing the ports in the default socket-group declared in the server-group --> <socket-bindings port-offset="150"/> </server> <server name="server-six" group="other-server-group" auto-start="true"> <!-- server-three avoids port conflicts by incrementing the ports in the default socket-group declared in the server-group --> <socket-bindings port-offset="250"/> </server> </servers></span>
跟名或者删除server2中$JBOSS_HOME/domain/configuration中的domain.xml文件
wzdacyl@leo116:~/Downloads/server/jboss-eap-6.2/domain/configuration$ mv domain.xml domain_xml
启动后能从master的console中看到如下日志表明成功启动各个虚拟机,
...... [Server:server-one] 04:51:05,300 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started in 8194ms - Started 197 of 261 services (63 services are passive or on-demand) ...... [Server:server-two] 04:51:12,466 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started in 12675ms - Started 249 of 374 services (124 services are passive or on-demand) ...... [Server:server-three] 04:51:17,290 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started in 11340ms - Started 249 of 374 services (124 services are passive or on-demand)
...... [Server:server-four] 04:29:54,278 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started in 7620ms - Started 197 of 260 services (62 services are passive or on-demand) ...... [Server:server-five] 04:30:01,833 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started in 13180ms - Started 197 of 260 services (62 services are passive or on-demand) ...... [Server:server-six] 04:30:10,515 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started in 15491ms - Started 199 of 320 services (120 services are passive or on-demand)
[Host Controller] 04:29:46,373 INFO [org.jboss.as.domain] (slave-request-threads - 1) JBAS010918: Registered remote slave host "server2", JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14)
有了如上的2.1到2.7的步骤,一个包含两台物理机,6台虚拟机的Managed Domain就配置好了。这一小节主要介绍统一配置。整个域统一配置的地方在master的$JBOSS_HOME/domain/configuration/domain.xml文件中。
我们倒着往上看domain.xml这个文件:
<server-groups>用于配置管理组各组对应的主要配置profile。
<server-groups> <server-group name="main-server-group" profile="full"> <jvm name="default"> <heap size="1303m" max-size="1303m"/> <permgen max-size="256m"/> </jvm> <socket-binding-group ref="full-sockets"/> </server-group> <server-group name="other-server-group" profile="full-ha"> <jvm name="default"> <heap size="64m" max-size="512m"/> <permgen max-size="124m"/> </jvm> <socket-binding-group ref="full-ha-sockets"/> </server-group> </server-groups>
再往上是</socket-binding-groups>,其中可以有多个<socket-binding-group>标签,指明访问端口。
<socket-binding-group name="full-ha-sockets" default-interface="public"> <socket-binding name="ajp" port="8009"/> <socket-binding name="http" port="8080"/> <socket-binding name="https" port="8443"/> <socket-binding name="jacorb" interface="unsecure" port="3528"/> <socket-binding name="jacorb-ssl" interface="unsecure" port="3529"/> <socket-binding name="jgroups-mping" port="0" multicast-address="${jboss.default.multicast.address:192.168.0.110}" multicast-port="10001"/> <socket-binding name="jgroups-tcp" port="7600"/> <socket-binding name="jgroups-tcp-fd" port="57600"/> <socket-binding name="jgroups-udp" port="55200" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45688"/> <socket-binding name="jgroups-udp-fd" port="54200"/> <socket-binding name="messaging" port="5445"/> <socket-binding name="messaging-group" port="0" multicast-address="${jboss.messaging.group.address:231.7.7.7}" multicast-port="${jboss.messaging.group.port:9876}"/> <socket-binding name="messaging-throughput" port="5455"/> <socket-binding name="modcluster" port="0" multicast-address="224.0.1.105" multicast-port="23364"/> <socket-binding name="remoting" port="4447"/> <socket-binding name="txn-recovery-environment" port="4712"/> <socket-binding name="txn-status-manager" port="4713"/> <outbound-socket-binding name="mail-smtp"> <remote-destination host="localhost" port="25"/> </outbound-socket-binding> </socket-binding-group>
再往上是<interfaces>这个在host.xml中各自单独设置。
再往上是<profiles>标签,用于具体组件的申明和配置。配制方法与单机的standalone.xml一样,在此就不过多赘述。到此为止整个域就基本配置好了。进入下一章节查看统一部署部分,介绍查看Managed Domain以及统一部署实验。
这一节部署一个任意一个War包到domain中,点击Mange Deployments选项,进入下图,
点击Add按钮开始添加应用,可添加ear,war或者ejb_jar。在这里我们如下选择添加的war包,
然后next进入如下页面,
点击save完成上传。
接下来将包部署到具体的虚拟机中,如3.2.1中的图中点击Assign按钮,进入下图,选择需要部署的管理组。
再此我们选择other-server-group并勾选Enable。点击SAVE之后在master和server2的log中我们能看到war包被部署到具体的虚拟主机中,
Master
[Server:server-three] 04:44:43,559 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "HelloDomain.war" (runtime-name: "HelloDomain.war") [Server:server-two] 04:44:43,577 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "HelloDomain.war" (runtime-name: "HelloDomain.war") [Server:server-three] 04:44:43,750 INFO [org.jboss.web] (ServerService Thread Pool -- 66) JBAS018210: Register web context: /HelloDomain [Server:server-two] 04:44:43,761 INFO [org.jboss.web] (ServerService Thread Pool -- 66) JBAS018210: Register web context: /HelloDomain [Server:server-three] 04:44:43,983 INFO [org.jboss.as.server] (host-controller-connection-threads - 3) JBAS018559: Deployed "HelloDomain.war" (runtime-name : "HelloDomain.war") [Server:server-two] 04:44:43,987 INFO [org.jboss.as.server] (host-controller-connection-threads - 3) JBAS018559: Deployed "HelloDomain.war" (runtime-name : "HelloDomain.war")
[Server:server-six] 04:44:43,636 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "HelloDomain.war" (runtime-name: "HelloDomain.war") [Server:server-six] 04:44:43,759 INFO [org.jboss.web] (ServerService Thread Pool -- 66) JBAS018210: Register web context: /HelloDomain [Server:server-six] 04:44:44,054 INFO [org.jboss.as.server] (host-controller-connection-threads - 3) JBAS018559: Deployed "HelloDomain.war" (runtime-name : "HelloDomain.war")
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Hello Domain</title> </head> <body> <% java.util.Date date = new java.util.Date(); %> Current time is <%= date %> </body> </html>
我们使用3.3节生成的war包来检验统一部署的结果,所有的other-server-group的成员都部署上并能否通过相应端口访问到此项目,
server-two: 192.168.0.115: 8080+150(偏移量在2.8节中有介绍)
server-three: 192.168.0.115: 8080+250
server-six: 192.168.0.116: 8080+250
本文主要介绍JBOSS EAP 6.1(JBOSS7.2)新增的Managed Domain的概念。接着通过一个实力介绍了管理域的主要特性:统一配置和统一部署。