您的位置:首页 > 运维架构 > Docker

【docker】--JBoss集群的搭建

2017-07-16 21:44 267 查看
【前言】

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

其中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 --silent4、构建镜像:
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 /。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: