- WildFly Cookbook
- Luigi Fugaro
- 774字
- 2021-07-16 13:38:14
Configuring multiple WildFly instances to run on the same machine with different ports
In some cases, mostly because of architectural reasons, you may need to run multiple WildFly instances on a single server. You can do this by isolating each instance and giving it a different binding port.
Getting ready
First of all, we need to create a standalone configuration for each instance that we want to set up and run. All we need to do is replicate the concept explained in the Running WildFly from a custom configuration folder recipe. Suppose we want two running nodes/instances, we use the following commands:
$ cd $WILDFLY_HOME $ cp -a standalone node-1 $ cp -a standalone node-2
Now we are ready to configure each instance.
How to do it…
To achieve such a requirement, you can use either of the methods explained earlier in the Binding WildFly on a custom port recipe. Let's take a look at each of them.
Using jboss.http.port
The first thing to try is to run the two WildFly instances by passing the parameter jboss.http.port
, obviously with different values. Actually, one of them could have the default value:
$ cd $WILDFLY_HOME $ ./bin/standalone.sh -Djboss.server.base.dir=$WILDFLY_HOME//node-1 -Djboss.http.port=8180 ... 10:30:23,924 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTP listener default listening on /127.0.0.1:8180 ...
Now we are going to run another WildFly instance by passing a different jboss.http.port
parameter in a different terminal window:
$ cd $WILDFLY_HOME $ ./bin/standalone.sh -Djboss.server.base.dir=$WILDFLY_HOME$WILDFLY_HOME/node-2 -Djboss.http.port=8280 ... 10:30:34,205 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0006: Undertow HTTP listener default listening on /127.0.0.1:8280 ... 10:30:34,473 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.serverManagement.controller.management.http: org.jboss.msc.service.StartException in service jboss.serverManagement.controller.management.http: WFLYSRV0083: Failed to start the http-interface service ... 10:30:34,685 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0054: Admin console is not enabled 10:30:34,685 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) started (with errors) in 3252ms - Started 196 of 377 services (2 services failed or missing dependencies, 210 services are lazy, passive or on-demand)
Ouch! Something went wrong!
As you can see from the log, http-interface
couldn't start properly because of the Address already in use message. This is because we changed jboss.http.port
, but not the analogous one for the management interface, which is http-interface
defined in standalone.xml
:

"http-interface" defined in the standalone.xml
Every standalone instance has its own management interface, thus we need to change its binding as well. Let's fix it:
$ cd $WILDFLY_HOME $ ./bin/standalone.sh -Djboss.server.base.dir=$WILDFLY_HOME//node-1 -Djboss.http.port=8180 -Djboss.management.http.port=9991 ... 11:11:05,862 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0006: Undertow HTTP listener default listening on /127.0.0.1:8180 ... 11:11:06,405 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9991/management 11:11:06,406 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9991 ...
This is in a different terminal window:
$ cd $WILDFLY_HOME $ ./bin/standalone.sh -Djboss.server.base.dir=$WILDFLY_HOME$WILDFLY_HOME/node-2 -Djboss.http.port=8280 -Djboss.management.http.port=9992 ... 11:11:59,777 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006: Undertow HTTP listener default listening on /127.0.0.1:8280 ... 11:12:00,358 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9992/management 11:12:00,359 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9992 ...
There you go! Now if you check the open sockets at the OS level, filtering by the java process, you will see the following:

Using jboss.socket.binding.port-offset
Okay, let's try using the port-offset
directive:
$ cd $WILDFLY_HOME $ ./bin/standalone.sh -Djboss.serever.base.dir=$WILDFLY_HOME/node-1 -Djboss.socket.binding.port-offset=100 ... 11:35:05,783 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006: Undertow HTTP listener default listening on /127.0.0.1:8180 ... 11:35:06,512 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:10090/management 11:35:06,513 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:10090 11:35:06,513 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) started in 3228ms - Started 202 of 379 services (210 services are lazy, passive or on-demand)
The following is keyed in a different terminal window:
$ cd $WILDFLY_HOME $ ./bin/standalone.sh -Djboss.serever.base.dir=$WILDFLY_HOME/node-2 -Djboss.socket.binding.port-offset=200 ... 11:35:23,389 INFO [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0006: Undertow HTTP listener default listening on /127.0.0.1:8280 ... 11:35:24,030 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:10190/management 11:35:24,030 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:10190 11:35:24,031 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) started in 3191ms - Started 202 of 379 services (210 services are lazy, passive or on-demand)
As you have noticed, both servers start up regularly without any additional configuration or precaution. Lastly, just check the socket at the OS level:

There's more...
Using the jboss.socket.binding.port-offset
directive facilitates all configuration needs, in contrast to every single configuration update needed when using jboss.http.port
.
Furthermore, with WildFly, you could benefit even more by using the port-offset
configuration, as you would also need to adjust the remoting socket.
- 案例式C語言程序設計
- Oracle 11g從入門到精通(第2版) (軟件開發視頻大講堂)
- Photoshop智能手機APP UI設計之道
- WSO2 Developer’s Guide
- C++程序設計基礎教程
- 教孩子學編程:C++入門圖解
- Getting Started with Python Data Analysis
- Python機器學習編程與實戰
- C/C++程序員面試指南
- Java Fundamentals
- Learning Python Data Visualization
- Photoshop CC移動UI設計案例教程(全彩慕課版·第2版)
- UML基礎與Rose建模實用教程(第三版)
- Java編程指南:語法基礎、面向對象、函數式編程與項目實戰
- Visual FoxPro程序設計實驗教程