官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 闽侯县| 额济纳旗| 称多县| 沙湾县| 绥中县| 赤壁市| 偃师市| 自治县| 刚察县| 辽源市| 诸城市| 永城市| 鹤峰县| 孟州市| 岳阳县| 綦江县| 府谷县| 礼泉县| 米泉市| 凤山市| 洛隆县| 海林市| 平湖市| 黔南| 旬阳县| 庆云县| 吉林省| 蒙自县| 湖南省| 格尔木市| 霍邱县| 三穗县| 东海县| 黔西| 永城市| 墨江| 普兰县| 库尔勒市| 江门市| 萨嘎县| 峨山|