项目作者: tommaso-borgato

项目描述 :
A wildfly cluster of 2 nodes running on Docker
高级语言: Shell
项目地址: git://github.com/tommaso-borgato/wildfly-cluster-on-docker.git


Prerequisites

Must have Docker (Community Edition will suffice) running.

Build war

Build war file to have something to deploy on wildfly:

  1. mvn clean install

this application uses replicated HTTP session (<distributable></distributable> tag in src/main/webapp/WEB-INF/web.xml).

Build docker image with wildfly+war

Build a Docker image containig war running inside wildfly configured to run in clustered mode (-server-config=standalone-ha.xml)

  1. docker build -t wildfly-cluster-node .

Create a dedicated Docker network

Defining a Docker network specifing gateway and subnet is necessary to assign specific IPs to containers:

  1. docker network ls
  2. docker network create --driver bridge --gateway 172.19.0.1 --subnet 172.19.0.0/16 cluster_nw
  3. docker network inspect cluster_nw

Run a Docker web GUI

  1. docker run --restart=always -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

The console is now available at:
http://localhost:9000/#/dashboard

Run 2 Docker containers

Run 2 containers.
Note that specific IPs are only needed to configure a mod_jk balancer later.

  1. docker run --network=cluster_nw --ip 172.19.0.2 -d -p 8081:8080 -p 9991:9990 --name wildfly-cluster-node-1 -t wildfly-cluster-node
  2. docker run --network=cluster_nw --ip 172.19.0.3 -d -p 8082:8080 -p 9992:9990 --name wildfly-cluster-node-2 -t wildfly-cluster-node

Check clustering is working

http://localhost:8081/wildfly/helloworld
http://localhost:8082/wildfly/helloworld

Inspect a Docker container

  1. docker container ls --all
  2. docker exec -it 24d9244eb9f0 bash

Remove a Docker container

  1. docker container stop 8b64379c60e4
  2. docker container rm 8b64379c60e4

Load Balancer with mod_jk

go to src/mod_jk folder

  1. docker build -t httpd-mod_jk .

then run

  1. docker run --network=cluster_nw --ip 172.19.0.4 -d -p 80:80 --name mod_jk -t httpd-mod_jk

finally try url http://localhost/wildfly/helloworld for cluster
try url http://localhost:???/mcm for console

Load Balancer with mod_cluster

using https://hub.docker.com/r/karm/mod_cluster-master-dockerhub (GIT https://github.com/Karm/mod_cluster-dockerhub):

  1. docker pull karm/mod_cluster-master-dockerhub

build mod_cluster:

  1. cd ./src/mod_cluster
  2. docker build -t mod_cluster_image .

build wildfly:

  1. docker build -f Dockerfile-mod_cluster -t wildfly-mod_cluster-node .

start httpd with mod_cluster:

  1. docker run -P -i -d --network=cluster_nw --ip 172.19.0.5 -p 80:80 --name mod_cluster mod_cluster_image

start wildfly:

  1. docker run --network=cluster_nw --ip 172.19.0.6 -p 8086:8080 -p 9996:9990 --name wildfly-mod_cluster-node-1 -t wildfly-mod_cluster-node
  2. docker run --network=cluster_nw --ip 172.19.0.7 -p 8087:8080 -p 9997:9990 --name wildfly-mod_cluster-node-2 -t wildfly-mod_cluster-node