【docker】--JBoss集群的搭建

【前言】

      配置完成后的文件夹中要下面这些文件:


其中apptest.war就是你要放到docker中的程序。

【开始】

 1、搭建网络

docker network create \
 --driver=bridge \
 --subnet=172.28.0.0/16 \
 --ip-range=172.28.5.0/24 \
 --gateway=172.28.5.254 \
 wildnetwork

您可以使用所需的子网,范围和网关。只要做到正确

2、配置standalone.xml文件

在对应standalone-ha-*.xml文件的<interface></interface>里面添加:

standalone-ha-1.xml

<interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:172.28.5.0}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:172.28.5.0}"/>
        </interface>
        <interface name="private">
            <inet-address value="${jboss.bind.address.private:172.28.5.0}"/>
        </interface>
 </interfaces>

standalone-ha-2.xml

<interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:172.28.5.2}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:172.28.5.2}"/>
        </interface>
        <interface name="private">
            <inet-address value="${jboss.bind.address.private:172.28.5.2}"/>
        </interface>
</interfaces>

standalone-ha-3.xml

<interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:172.28.5.3}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:172.28.5.3}"/>
        </interface>
        <interface name="private">
            <inet-address value="${jboss.bind.address.private:172.28.5.3}"/>
        </interface>
</interfaces>
3、编写Dockerfile

FROM jboss/wildfly
 
# Environment variable with default value
ARG APP_FILE=appfile.war
 
# Add your application to the deployment folder
ADD ${APP_FILE} /opt/jboss/wildfly/standalone/deployments/${APP_FILE}
 
# Add standalone-ha.xml - set your own network settings
ADD standalone-ha-1.xml /opt/jboss/wildfly/standalone/configuration/standalone-ha-1.xml
ADD standalone-ha-2.xml /opt/jboss/wildfly/standalone/configuration/standalone-ha-2.xml
ADD standalone-ha-3.xml /opt/jboss/wildfly/standalone/configuration/standalone-ha-3.xml
 
# Add user for adminstration purpose
RUN /opt/jboss/wildfly/bin/add-user.sh admin admin123 --silent
4、构建镜像:

docker build -t wildfly-cluster --build-arg APP_FILE=apptest.war .
这个单行命令将构建一个名为“wildfly-cluster”的映像(设备),部署“apptest.war”。 不要忘记结束的点,这意味着在当前文件夹中有一个Docker文件。apptest.war 也应该在文件夹中。

我们把它们放在一起,并与一个负载平衡器:

docker run -d --name wild-balancer -p 80:80 \
  --link wild1:wild1 \
  --link wild2:wild2 \
  --link wild3:wild3 \
  --env-file ./env.list \
  --network=wildnetwork \
  --ip 172.28.5.4 jasonwyatt/nginx-loadbalancer

到此,JBoss集群在docker中就搭建成功了。现在试着去访问: HTTP://本地主机/ apptest /

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值