edgexfoundry

 找回密码
 立即注册
搜索
热搜: meta core rules
查看: 12739|回复: 0

edgexfoundry docker 部署实战

[复制链接]

10

主题

10

帖子

370

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
370
发表于 2018-10-23 09:40:41 | 显示全部楼层 |阅读模式
本帖最后由 灰哥哥 于 2019-3-18 14:25 编辑

一、环境准备


二、镜像制作

2.1  基础镜像myalpine-openjdk8-curl制作

      此镜像将其它镜像公有的部分抽取出来(如jdk,curl工具),减少制作edgexfoundry各服务的步骤。

      2.1.1 Dockerfile文件
  1. FROM alpine
  2. #为了下载加速,替换为mirrors.ustc.edu.cn
  3. RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
  4. RUN apk --update add openjdk8-jre
  5. RUN apk --update add curl

  6. CMD /bin/sh
复制代码
       2.1.2 镜像制作命令
  1. sudo docker build -t myalpine-openjdk8-curl .
复制代码


2.2  镜像myedgex/myedgex-volume:java制作

      2.2.1 Dockerfile文件
  1. FROM ubuntu:latest
  2. MAINTAINER Cloud Tsai <Cloud.Tsai@Dell.com>

  3. RUN addgroup consul && \
  4.     adduser --system --ingroup consul consul

  5. # standard mongo db data dir directories
  6. RUN mkdir /data
  7. RUN mkdir /data/db
  8. RUN echo "this directory is reserved for EdgeX database files" > /data/db/README

  9. # EdgeX shared directories
  10. ENV EDGEX_BASE=/edgex
  11. RUN mkdir $EDGEX_BASE
  12. RUN mkdir $EDGEX_BASE/logs
  13. RUN echo "this directory is reserved for EdgeX log files" > $EDGEX_BASE/logs/README

  14. #用来持久化规则引擎模块中的文件(规则模板与用户定义的规则),确定容器停止后这些文件不丢失
  15. ENV EDGEX_RULES=/edgex/edgex-support-rulesengine
  16. RUN mkdir $EDGEX_RULES
  17. RUN mkdir $EDGEX_RULES/rules
  18. RUN mkdir $EDGEX_RULES/templates

  19. # Consul config and data directories
  20. # The /consul/data dir is used by Consul to store state. The agent will be started
  21. # with /consul/config as the configuration directory so you can add additional
  22. # config files in that location.
  23. RUN mkdir /consul
  24. RUN mkdir /consul/config
  25. RUN mkdir /consul/data
  26. RUN echo "this directory is reserved for EdgeX Consul config files" > /consul/config/README
  27. RUN echo "this directory is reserved for EdgeX data files" > /consul/data/README
  28. #将consul 对 mongodb配置文件
  29. COPY static-services-config.json /consul/config


  30. ENTRYPOINT /usr/bin/tail -f /dev/null

复制代码
      

2.2.3 static-services-config.json文件

consul读取此文件,注册mongdb服务


  1. {
  2.   "service": {
  3.       "name": "edgex-mongo", #edgex-mongo在consul上显示的名字
  4.       "tags": [
  5.           "database",
  6.           "nosql"
  7.       ],
  8.           "address": "edgex-mongo",           #edgex-mongo服务地址
  9.       "port": 27017,                                #edgex-mongo端口
  10.       "check": {
  11.           "name": "status",
  12.           "tcp": "edgex-mongo:27017",      #edgex-mongo心跳检测服务地址
  13.           "interval": "20s",      #第20秒中检测一次
  14.                   "timeout": "5s"       #5秒超时
  15.       }
  16.    }
  17. }
复制代码



2.2.4 镜像制作命令
  1. sudo docker build -t myedgex/myedgex-volume:java .
复制代码


2.3  镜像myedgex/core-config-seed:java制作

      2.3.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/core-config-seed
  4. ENV APP=core-config-seed

  5. ENV WAIT_FOR_A_WHILE=10

  6. ENV CONSUL_ARGS="-server -client=0.0.0.0 -bootstrap -ui"
  7. #将注册到consul的配置信息文件拷入到镜像,注意这个路径是/edgex/core-config-seed/config ,在后面的launch-consul-config.sh文件使用路径保持一致
  8. COPY ./config $APP_DIR/config
  9. COPY *.sh $APP_DIR/
  10. RUN chmod +x $APP_DIR/*.sh
  11. #将已下载consul应用程序拷入镜像
  12. COPY consul /usr/local/bin/
  13. RUN chmod +x /usr/local/bin/consul

  14. #set the working directory

  15. WORKDIR $APP_DIR
  16. #此步可以不同实现方法,你可以使用COPY命令将编译好的jar包拷入。下面我是通过nexus私服中获取,为了加快下载速度,我选择了172.17.0.1内网地址(容器访问主机的地址)
  17. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  18. #call the wrapper to launch consul and main app
  19. #执行如下脚本,拉起consul,并读入config配置信息
  20. CMD $APP_DIR/launch-consul-config.sh
复制代码
目录结构如下:


2.3.2 launch-consul-config.sh文件        
  1. #!/bin/sh
  2. set -e

  3. if [ -z $ARCH ]
  4.         then
  5. #因为$ARCH为空,执行此行,注意此行需要加上source
  6.         rm -rf /consul/data/* && source docker-entrypoint.sh agent $CONSUL_ARGS | tee /edgex/logs/core-consul.log &
  7. else
  8.         rm -rf /consul/data/* && source $APP_DIR/docker-entrypoint.sh agent $CONSUL_ARGS | tee /edgex/logs/core-consul.log &
  9. fi

  10. echo "Waiting for $WAIT_FOR_A_WHILE seconds until consul is configured"
  11. sleep $WAIT_FOR_A_WHILE

  12. #将config配置信息写入到consul中去。edgex/core-config-seed/config路径需要与Dockerfile定义的一致(使用了绝对路径)
  13. java -jar $APP.jar --configPath=/edgex/core-config-seed/config

  14. wait

复制代码

2.3.3 docker-entrypoint.sh文件       

此脚本启动consul

  1. #!/bin/bash
  2. set -e
  3. # to Consul.
  4. CONSUL_BIND=
  5. if [ -n "$CONSUL_BIND_INTERFACE" ]; then
  6.   CONSUL_BIND_ADDRESS=$(ip -o -4 addr list $CONSUL_BIND_INTERFACE | head -n1 | awk '{print $4}' | cut -d/ -f1)
  7.   if [ -z "$CONSUL_BIND_ADDRESS" ]; then
  8.     echo "Could not find IP for interface '$CONSUL_BIND_INTERFACE', exiting"
  9.     exit 1
  10.   fi

  11.   CONSUL_BIND="-bind=$CONSUL_BIND_ADDRESS"
  12.   echo "==> Found address '$CONSUL_BIND_ADDRESS' for interface '$CONSUL_BIND_INTERFACE', setting bind option..."
  13. fi

  14. # You can set CONSUL_CLIENT_INTERFACE to the name of the interface you'd like to
  15. # bind client intefaces (HTTP, DNS, and RPC) to and this will look up the IP and
  16. # pass the proper -client= option along to Consul.
  17. CONSUL_CLIENT=
  18. if [ -n "$CONSUL_CLIENT_INTERFACE" ]; then
  19.   CONSUL_CLIENT_ADDRESS=$(ip -o -4 addr list $CONSUL_CLIENT_INTERFACE | head -n1 | awk '{print $4}' | cut -d/ -f1)
  20.   if [ -z "$CONSUL_CLIENT_ADDRESS" ]; then
  21.     echo "Could not find IP for interface '$CONSUL_CLIENT_INTERFACE', exiting"
  22.     exit 1
  23.   fi

  24.   CONSUL_CLIENT="-client=$CONSUL_CLIENT_ADDRESS"
  25.   echo "==> Found address '$CONSUL_CLIENT_ADDRESS' for interface '$CONSUL_CLIENT_INTERFACE', setting client option..."
  26. fi

  27. # CONSUL_DATA_DIR is exposed as a volume for possible persistent storage. The
  28. # CONSUL_CONFIG_DIR isn't exposed as a volume but you can compose additional
  29. # config files in there if you use this image as a base, or use CONSUL_LOCAL_CONFIG
  30. # below.
  31. CONSUL_DATA_DIR=/consul/data
  32. CONSUL_CONFIG_DIR=/consul/config

  33. # You can also set the CONSUL_LOCAL_CONFIG environemnt variable to pass some
  34. # Consul configuration JSON without having to bind any volumes.
  35. if [ -n "$CONSUL_LOCAL_CONFIG" ]; then
  36.     echo "$CONSUL_LOCAL_CONFIG" > "$CONSUL_CONFIG_DIR/local.json"
  37. fi

  38. # If the user is trying to run Consul directly with some arguments, then
  39. # pass them to Consul.
  40. if [ "${1:0:1}" = '-' ]; then
  41.     set -- consul "$@"
  42. fi

  43. # Look for Consul subcommands.
  44. if [ "$1" = 'agent' ]; then
  45.     shift
  46.     set -- consul agent \
  47.         -data-dir="$CONSUL_DATA_DIR" \
  48.         -config-dir="$CONSUL_CONFIG_DIR" \
  49.         $CONSUL_BIND \
  50.         $CONSUL_CLIENT \
  51.         "$@"
  52. elif [ "$1" = 'version' ]; then
  53.     # This needs a special case because there's no help output.
  54.     set -- consul "$@"
  55. elif consul --help "$1" 2>&1 | grep -q "consul $1"; then
  56.     set -- consul "$@"
  57. fi

  58. # If we are running Consul, make sure it executes as the proper user.
  59. if [ "$1" = 'consul' ]; then
  60.     if [ ! -z ${CONSUL_ALLOW_PRIVILEGED_PORTS+x} ]; then
  61.         setcap "cap_net_bind_service=+ep" /bin/consul
  62.     fi

  63. #    set -- consul "$@"
  64. fi

  65. exec "$@"


复制代码

2.3.4 镜像制作命令
  1. sudo docker build -t myedgex/core-config-seed:java .
复制代码


2.4  镜像myedgex/myedgex-mongo:java制作

      2.4.1 Dockerfile文件
  1. FROM mongo:3.4.9
  2. MAINTAINER Jim White <james_white2@dell.com>

  3. #copy initialization script for later initialization
  4. COPY *.js /edgex/mongo/config/
  5. COPY launch-edgex-mongo.sh /edgex/mongo/config/
  6. RUN chmod +x /edgex/mongo/config/launch-edgex-mongo.sh
  7. #expose Mongodb's port
  8. EXPOSE 27017
  9. #启动mongodb并初始化数据
  10. CMD /edgex/mongo/config/launch-edgex-mongo.sh

复制代码
2.4.2 launch-edgex-mongo.sh文件
  1. set -e
  2. #以smallfiles方式启动mongodb 服务
  3. mongod --smallfiles &

  4. while true; do
  5. #客户端工具执初始化数据库(建用户、库、集合)
  6.   mongo /edgex/mongo/config/init_mongo.js && break
  7.   sleep 5
  8. done

  9. wait
复制代码


2.4.3 镜像制作命令

  1. sudo docker build -t myedgex/myedgex-mongo:java .
复制代码


2.5 镜像myedgex/support-logging:java制作

2.5.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-support-logging
  4. ENV APP=support-logging
  5. ENV APP_PORT=48061

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  13. #kick off the micro service
  14. ENTRYPOINT java -jar $APP.jar


复制代码
2.5.2 镜像制作命令

  1. sudo docker build -t myedgex/support-logging:java .
复制代码



2.6 镜像myedgex/support-notifications:java制作

2.6.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-support-notifications
  4. ENV APP=support-notifications
  5. ENV APP_PORT=48060

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  13. #kick off the micro service
  14. ENTRYPOINT java -jar $APP.jar
复制代码

2.6.2 镜像制作命令

  1. sudo docker build -t myedgex/support-notifications:java .
复制代码


2.7 镜像myedgex/core-metadata:java制作

2.7.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-core-metadata
  4. ENV APP=core-metadata
  5. ENV APP_PORT=48081

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  13. #kick off the micro service
  14. ENTRYPOINT java -jar $APP.jar

复制代码

2.7.2 镜像制作命令

  1. sudo docker build -t myedgex/core-metadata:java .
复制代码





2.8 镜像myedgex/core-metadata:java制作

2.8.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-core-metadata
  4. ENV APP=core-metadata
  5. ENV APP_PORT=48081

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN
  13. curl -o $APP.jar
  14. http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  15. #kick off the micro service
  16. ENTRYPOINT java -jar $APP.jar
复制代码

2.8.2 镜像制作命令
  1. sudo docker build -t myedgex/core-metadata:java .
复制代码
2.9 镜像myedgex/core-data:java制作

2.9.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-core-data
  4. ENV APP=core-data
  5. ENV APP_PORT=48080

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  13. #kick off the micro service
  14. ENTRYPOINT java -jar $APP.jar
复制代码

2.9.2 镜像制作命令
  1. sudo docker build -t myedgex/core-data:java .
复制代码


2.10 镜像myedgex/core-command:java制作

2.10.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-core-command
  4. ENV APP=core-command
  5. ENV APP_PORT=48082

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  13. #kick off the micro service
  14. ENTRYPOINT java -jar $APP.jar
复制代码

2.10.2 镜像制作命令
  1. sudo docker build -t myedgex/core-command:java .
复制代码

2.11 镜像myedgex/export-client:java制作

2.11.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-export-client
  4. ENV APP=export-client
  5. ENV APP_PORT=48071

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  13. #kick off the micro service
  14. ENTRYPOINT java -jar $APP.jar
复制代码
2.11.2 镜像制作命令
  1. sudo docker build -t myedgex/export-client:java .
复制代码

2.12 镜像myedgex/export-distro:java制作

2.12.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/etrol-export-distro
  4. ENV APP=export-distro
  5. ENV APP_PORT=48070

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/

  8. #expose logging port
  9. EXPOSE $APP_PORT

  10. #set the working directory
  11. WORKDIR $APP_DIR
  12. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  13. #kick off the micro service
  14. ENTRYPOINT java -jar $APP.jar
复制代码
2.12.2 镜像制作命令
  1. sudo docker build -t myedgex/export-distro:java .
复制代码

2.13 镜像myedgex/support-rulesengine:java制作

2.13.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/edgex-support-rulesengine
  4. ENV APP=support-rulesengine
  5. ENV APP_PORT=48075
  6. ENV TEMPLATE_DIR=/edgex/edgex-support-rulesengine/templates

  7. #copy JAR and property files to the image
  8. #COPY *.properties $APP_DIR/
  9. #确保使用最新的规则引擎模板拷入
  10. RUN rm -rf $TEMPLATE_DIR/*.drl
  11. COPY *.drl $TEMPLATE_DIR/

  12. #RUN mkdir /edgex/edgex-support-rulesengine/rules
  13. #RUN chmod 777 /edgex/edgex-support-rulesengine/rules
  14. #expose logging port
  15. EXPOSE $APP_PORT

  16. #set the working directory
  17. WORKDIR $APP_DIR
  18. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  19. #kick off the micro service
  20. ENTRYPOINT java -jar $APP.jar

复制代码
2.13.2 镜像制作命令
  1. sudo docker build -t myedgex/support-rulesengine:java .
复制代码

2.14 镜像myedgex/device-virtual:java制作

2.14.1 Dockerfile文件
  1. FROM myalpine-openjdk8-curl

  2. # environment variables
  3. ENV APP_DIR=/edgex/device-virtual
  4. ENV APP=device-virtual
  5. ENV APP_PORT=49990

  6. #copy JAR and property files to the image
  7. #COPY *.properties $APP_DIR/
  8. #将设备文件目录拷入到镜像,虚拟机启动时默认会加载此两目录下的设备文件
  9. COPY bacnet_sample_profiles $APP_DIR/bacnet_sample_profiles/
  10. COPY modbus_sample_profiles $APP_DIR/modbus_sample_profiles/

  11. #expose logging port
  12. EXPOSE $APP_PORT

  13. #set the working directory
  14. WORKDIR $APP_DIR
  15. RUN curl -o $APP.jar http://172.17.0.1:8081/nexus/content/repositories/releases/org/edgexfoundry/$APP/0.5.0-docker-RELEASE/$APP-0.5.0-docker-RELEASE.jar
  16. #kick off the micro service
  17. ENTRYPOINT java -jar  $APP.jar
复制代码

2.14.2 镜像制作命令
  1. sudo docker build -t myedgex/device-virtual:java .
复制代码

此至,主要的镜像已制作完毕!

三、docker-compose运行edgexfoundry
3.1 docker-compose-java.yml文件
下面显示缩进有问题,可参考文件:



  1. version: '3'

  2. volumes:
  3.   db-data:
  4.   log-data:
  5.   consul-config:
  6.   consul-data:

  7. services:
  8.   volume:
  9.     image: myedgex/myedgex-volume:java
  10.     container_name: edgex-files
  11.     networks:
  12.       - edgex-network
  13.     volumes:
  14.       - db-data:/data/db
  15.       - log-data:/edgex/logs
  16.       - consul-config:/consul/config
  17.       - consul-data:/consul/data

  18.   config-seed:
  19.     image: myedgex/core-config-seed:java
  20.     ports:
  21.         - "8400:8400"
  22.         - "8500:8500"
  23.         - "8600:8600"
  24.     container_name: core-config-seed
  25.     hostname: core-config-seed
  26.     networks:
  27.       edgex-network:
  28.        #考虑到与go语言版的复用,此处我用了两个网络别名,都可以访问到consul,这个与bootstrap.properties设置有关
  29.         aliases:
  30.             - core-consul
  31.             - edgex-core-consul
  32.     volumes:
  33.       - db-data:/data/db
  34.       - log-data:/edgex/logs
  35.       - consul-config:/consul/config
  36.       - consul-data:/consul/data
  37.     depends_on:
  38.       - volume

  39.   mongo:
  40.     image: myedgex/myedgex-mongo:java
  41.     ports:
  42.       - "27017:27017"
  43.     container_name: edgex-mongo
  44.     hostname: edgex-mongo
  45.     networks:
  46.       - edgex-network
  47.     volumes:
  48.       - db-data:/data/db
  49.       - log-data:/edgex/logs
  50.       - consul-config:/consul/config
  51.       - consul-data:/consul/data
  52.     depends_on:
  53.       - volume

  54.   logging:
  55.     image: myedgex/support-logging:java
  56.     ports:
  57.       - "48061:48061"
  58.     container_name: support-logging
  59.     hostname: support-logging
  60.     networks:
  61.       - edgex-network
  62.     volumes:
  63.       - db-data:/data/db
  64.       - log-data:/edgex/logs
  65.       - consul-config:/consul/config
  66.       - consul-data:/consul/data
  67.     depends_on:
  68.       - volume
  69.       - config-seed
  70.       - mongo

  71.   notifications:
  72.     image: myedgex/support-notifications:java
  73.     ports:
  74.       - "48060:48060"
  75.     container_name: support-notifications
  76.     hostname: support-notifications
  77.     networks:
  78.       - edgex-network
  79.     volumes:
  80.       - db-data:/data/db
  81.       - log-data:/edgex/logs
  82.       - consul-config:/consul/config
  83.       - consul-data:/consul/data
  84.     depends_on:
  85.       - volume
  86.       - config-seed
  87.       - mongo
  88.       - logging

  89.   metadata:
  90.     image: myedgex/core-metadata:java
  91.     ports:
  92.       - "48081:48081"
  93.     container_name: core-metadata
  94.     hostname: core-metadata
  95.     networks:
  96.       - edgex-network
  97.     volumes:
  98.       - db-data:/data/db
  99.       - log-data:/edgex/logs
  100.       - consul-config:/consul/config
  101.       - consul-data:/consul/data
  102.     depends_on:
  103.       - volume
  104.       - config-seed
  105.       - mongo
  106.       - logging

  107.   data:
  108.     image: myedgex/core-data:java
  109.     ports:
  110.       - "48080:48080"
  111.       - "5563:5563"
  112.     container_name: core-data
  113.     hostname: core-data
  114.     networks:
  115.       - edgex-network
  116.     volumes:
  117.       - db-data:/data/db
  118.       - log-data:/edgex/logs
  119.       - consul-config:/consul/config
  120.       - consul-data:/consul/data
  121.     depends_on:
  122.       - volume
  123.       - config-seed
  124.       - mongo
  125.       - logging
  126.       - notifications

  127.   command:
  128.     image: myedgex/core-command:java
  129.     ports:
  130.       - "48082:48082"
  131.     container_name: core-command
  132.     hostname: core-command
  133.     networks:
  134.       - edgex-network
  135.     volumes:
  136.       - db-data:/data/db
  137.       - log-data:/edgex/logs
  138.       - consul-config:/consul/config
  139.       - consul-data:/consul/data
  140.     depends_on:
  141.       - volume
  142.       - config-seed
  143.       - mongo
  144.       - logging
  145.       - metadata
  146.   
  147.   scheduler:
  148.     image: myedgex/support-scheduler:java
  149.     ports:
  150.       - "48085:48085"
  151.     container_name: support-scheduler
  152.     hostname: support-scheduler
  153.     networks:
  154.       - edgex-network
  155.     volumes:
  156.       - db-data:/data/db
  157.       - log-data:/edgex/logs
  158.       - consul-config:/consul/config
  159.       - consul-data:/consul/data
  160.     depends_on:
  161.       - volume
  162.       - config-seed
  163.       - mongo
  164.       - logging
  165.       - metadata
  166.       - command

  167.   export-client:
  168.     image: myedgex/export-client:java
  169.     ports:
  170.       - "48071:48071"
  171.     container_name: export-client
  172.     hostname: export-client
  173.     networks:
  174.       - edgex-network
  175.     volumes:
  176.       - db-data:/data/db
  177.       - log-data:/edgex/logs
  178.       - consul-config:/consul/config
  179.       - consul-data:/consul/data
  180.     depends_on:
  181.       - volume
  182.       - config-seed
  183.       - mongo
  184.       - logging
  185.       - notifications
  186.       - metadata
  187.       - data

  188.   export-distro:
  189.     image: myedgex/export-distro:java
  190.     ports:
  191.       - "48070:48070"
  192.       - "5566"
  193.     container_name: export-distro
  194.     hostname: export-distro
  195.     networks:
  196.       - edgex-network
  197.     volumes:
  198.       - db-data:/data/db
  199.       - log-data:/edgex/logs
  200.       - consul-config:/consul/config
  201.       - consul-data:/consul/data
  202.     depends_on:
  203.       - volume
  204.       - config-seed
  205.       - mongo
  206.       - logging
  207.       - notifications
  208.       - metadata
  209.       - data
  210.       - export-client

  211.   rulesengine:
  212.     image: myedgex/support-rulesengine:java
  213.     ports:
  214.       - "48075:48075"
  215.     container_name: support-rulesengine
  216.     hostname: support-rulesengine
  217.     networks:
  218.       - edgex-network
  219.     volumes:
  220.       - db-data:/data/db
  221.       - log-data:/edgex/logs
  222.       - consul-config:/consul/config
  223.       - consul-data:/consul/data
  224.     depends_on:
  225.       - volume
  226.       - config-seed
  227.       - mongo
  228.       - logging
  229.       - metadata
  230.       - command
  231.       - export-distro

  232.   device-virtual:
  233.     image: myedgex/device-virtual:java
  234.     ports:
  235.       - "49990:49990"
  236.     container_name: edgex-device-virtual
  237.     hostname: edgex-device-virtual
  238.     networks:
  239.       - edgex-network
  240.     volumes:
  241.       - db-data:/data/db
  242.       - log-data:/edgex/logs
  243.       - consul-config:/consul/config
  244.       - consul-data:/consul/data
  245.     depends_on:
  246.       - volume
  247.       - config-seed
  248.       - mongo
  249.       - logging
  250.       - metadata
  251.       - data
  252.       - command

  253. networks:
  254.   edgex-network:
  255.     driver: "bridge"
复制代码
3.2 运行edgexfounry服务

3.2.1 方式一


依次执行如下命令:
  1. docker-compose -f docker-compose-registry-java.yml up -d volume
  2. docker-compose -f docker-compose-registry-java.yml up -d config-seed
  3. docker-compose -f docker-compose-registry-java.yml up -d mongo
  4. docker-compose -f docker-compose-registry-java.yml up -d logging
  5. docker-compose -f docker-compose-registry-java.yml up -d notifications
  6. docker-compose -f docker-compose-registry-java.yml up -d metadata
  7. docker-compose -f docker-compose-registry-java.yml up -d data
  8. docker-compose -f docker-compose-registry-java.yml up -d command
  9. docker-compose -f docker-compose-registry-java.yml up -d export-client
  10. docker-compose -f docker-compose-registry-java.yml up -d export-distro
  11. docker-compose -f docker-compose-registry-java.yml up -d rulesengine
  12. docker-compose -f docker-compose-registry-java.yml up -d device-virtual
复制代码
3.2.2 方式二

执行一个脚本,解压此文件,运行如下:

  1. chmod +x run-all.sh
  2. ./run-all.sh  docker-compose-java.yml
复制代码
注:docker-compose-java.yml为上面3.1节提到的文件。

3.2.3 运行结果
在浏览器中输入 “http://localhost:8500/ui/dc1/services” , 可打开consul界面,  如下图:


3.2.4 日志查看方法

进入到docker-compose-java.yml文件同目录下,执行:
  1. docker-compose -f docker-compose-registry-java.yml logs device-virtual
复制代码
说明:device-virtual 是 docker-compose-registry-java.yml中定义的服务名

3.2.4 停止edgexfoundry服务

停止所有服务,并删除容器:

  1. docker-compose -f docker-compose-registry-java.yml down
复制代码


暂停与继续运行某个服务:

  1. docker-compose -f docker-compose-registry-java.yml stop device-virtual  #暂停
  2. docker-compose -f docker-compose-registry-java.yml start device-virtual  #继续运行
复制代码
3.2.4 其它

查看 edgexfoundry服务
  1. 命令:docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}\t{{.RunningFor}}"

  2. 结果:
  3. NAMES                   STATUS              PORTS                                                                    CREATED
  4. edgex-device-virtual    Up 3 minutes        0.0.0.0:49990->49990/tcp                                                 3 minutes ago
  5. support-rulesengine     Up 4 minutes        0.0.0.0:48075->48075/tcp                                                 4 minutes ago
  6. export-distro           Up 4 minutes        0.0.0.0:48070->48070/tcp, 0.0.0.0:32769->5566/tcp                        4 minutes ago
  7. export-client           Up 4 minutes        0.0.0.0:48071->48071/tcp                                                 4 minutes ago
  8. core-command            Up 5 minutes        0.0.0.0:48082->48082/tcp                                                 5 minutes ago
  9. core-data               Up 5 minutes        0.0.0.0:5563->5563/tcp, 0.0.0.0:48080->48080/tcp                         5 minutes ago
  10. core-metadata           Up 5 minutes        0.0.0.0:48081->48081/tcp                                                 5 minutes ago
  11. support-notifications   Up 5 minutes        0.0.0.0:48060->48060/tcp                                                 6 minutes ago
  12. support-logging         Up 5 minutes        0.0.0.0:48061->48061/tcp                                                 6 minutes ago
  13. edgex-mongo             Up 6 minutes        0.0.0.0:27017->27017/tcp                                                 6 minutes ago
  14. core-config-seed        Up 6 minutes        0.0.0.0:8400->8400/tcp, 0.0.0.0:8500->8500/tcp, 0.0.0.0:8600->8600/tcp   6 minutes ago
  15. edgex-files             Up 7 minutes                                                                                 7 minutes ago
复制代码


进入容器查看

注明:下面命令中的“edgex-files” 是上面查看 edgexfoundry服务结果的第一列(Name列),如进入volume服务(容器名为:edgex-files)
  1. docker exec -it edgex-files /bin/sh
复制代码

拷贝容器里的文件到宿主主机
  1. docker cp edgex-files:/edgex/logs/core-consul.log ./
复制代码

从volume容器中拷贝core-consul.log到宿主主机整个过程如下面所示
  1. myEdgex@ubuntu:~$ docker exec -it edgex-files /bin/sh
  2. # ls
  3. bin  boot  consul  data  dev  edgex  etc  home
  4.        lib  lib64  media  mnt        
  5. opt  proc  root  run  sbin  srv  sys  tmp  usr        var
  6. # cd edgex
  7. # ls
  8. edgex-support-rulesengine  logs
  9. # cd logs
  10. # ls
  11. README              core-consul.log          edgex-core-data.log      edgex-export-client.log    edgex-support-logging.log     edgex-support-rulesengine.log
  12. core-config-seed.log  edgex-core-command.log  edgex-core-metadata.log  edgex-export-distro.log    edgex-support-notifications.log  edgex-device-virtual.log
  13. # exit
  14. myEdgex@ubuntu:~$ docker cp edgex-files:/edgex/logs/core-consul.log ./
  15. myEdgex@ubuntu:~$ ls
  16. core-consul.log  docker-compose-registry-java.yml  Documents  Downloads  Music  Pictures  Public  run-all.sh  Templates  Videos
复制代码
volumes在主宿中存放的路径是/var/lib/docker/volumes/dockercompose_*,因为我是在 docker-compose目录下执行的docker-compose,所以为“dockercompose_”前辍
(需要root用户权限查看)
  1. root@instance-nbpwqv5z80:/var/lib/docker/volumes# tree -L 2 dockercompose_*
  2. dockercompose_consul-config
  3. └── _data
  4.     ├── README
  5.     └── static-services-config.json
  6. dockercompose_consul-data
  7. └── _data
  8. dockercompose_db-data
  9. └── _data
  10.     ├── collection-0--4777480234174622526.wt
  11.     ├── collection-0--8386283062836517086.wt
  12.     ├── collection-11--4777480234174622526.wt
  13.     ├── collection-14--4777480234174622526.wt
  14.     ├── collection-16--4777480234174622526.wt
  15.     ├── collection-19--4777480234174622526.wt
  16.     ├── collection-22--4777480234174622526.wt
  17.     ├── collection-2--4777480234174622526.wt
  18.     ├── collection-25--4777480234174622526.wt
  19.     ├── collection-28--4777480234174622526.wt
  20.     ├── collection-31--4777480234174622526.wt
  21.     ├── collection-34--4777480234174622526.wt
  22.     ├── collection-37--4777480234174622526.wt
  23.     ├── collection-40--4777480234174622526.wt
  24.     ├── collection-42--4777480234174622526.wt
  25.     ├── collection-44--4777480234174622526.wt
  26.     ├── collection-47--4777480234174622526.wt
  27.     ├── collection-49--4777480234174622526.wt
  28.     ├── collection-51--4777480234174622526.wt
  29.     ├── collection-5--4777480234174622526.wt
  30.     ├── collection-55--4777480234174622526.wt
  31.     ├── collection-7--4777480234174622526.wt
  32.     ├── collection-9--4777480234174622526.wt
  33.     ├── diagnostic.data
  34.     ├── index-10--4777480234174622526.wt
  35.     ├── index-12--4777480234174622526.wt
  36.     ├── index-13--4777480234174622526.wt
  37.     ├── index-1--4777480234174622526.wt
  38.     ├── index-15--4777480234174622526.wt
  39.     ├── index-17--4777480234174622526.wt
  40.     ├── index-1--8386283062836517086.wt
  41.     ├── index-18--4777480234174622526.wt
  42.     ├── index-20--4777480234174622526.wt
  43.     ├── index-21--4777480234174622526.wt
  44.     ├── index-23--4777480234174622526.wt
  45.     ├── index-24--4777480234174622526.wt
  46.     ├── index-26--4777480234174622526.wt
  47.     ├── index-27--4777480234174622526.wt
  48.     ├── index-29--4777480234174622526.wt
  49.     ├── index-30--4777480234174622526.wt
  50.     ├── index-32--4777480234174622526.wt
  51.     ├── index-33--4777480234174622526.wt
  52.     ├── index-3--4777480234174622526.wt
  53.     ├── index-35--4777480234174622526.wt
  54.     ├── index-36--4777480234174622526.wt
  55.     ├── index-38--4777480234174622526.wt
  56.     ├── index-39--4777480234174622526.wt
  57.     ├── index-41--4777480234174622526.wt
  58.     ├── index-43--4777480234174622526.wt
  59.     ├── index-4--4777480234174622526.wt
  60.     ├── index-45--4777480234174622526.wt
  61.     ├── index-46--4777480234174622526.wt
  62.     ├── index-48--4777480234174622526.wt
  63.     ├── index-50--4777480234174622526.wt
  64.     ├── index-52--4777480234174622526.wt
  65.     ├── index-53--4777480234174622526.wt
  66.     ├── index-54--4777480234174622526.wt
  67.     ├── index-56--4777480234174622526.wt
  68.     ├── index-6--4777480234174622526.wt
  69.     ├── index-8--4777480234174622526.wt
  70.     ├── journal
  71.     ├── _mdb_catalog.wt
  72.     ├── mongod.lock
  73.     ├── README
  74.     ├── sizeStorer.wt
  75.     ├── storage.bson
  76.     ├── WiredTiger
  77.     ├── WiredTigerLAS.wt
  78.     ├── WiredTiger.lock
  79.     ├── WiredTiger.turtle
  80.     └── WiredTiger.wt
  81. dockercompose_log-data
  82. └── _data
  83.     ├── core-config-seed.log
  84.     ├── core-consul.log
  85.     ├── edgex-core-command.log
  86.     ├── edgex-core-data.log
  87.     ├── edgex-core-metadata.log
  88.     ├── edgex-core-scheduler.log
  89.     ├── edgex-device-virtual.log
  90.     ├── edgex-device-virtual.log.1
  91.     ├── edgex-support-logging.log
  92.     ├── edgex-support-notifications.log
  93.     ├── edgex-support-rulesengine.log
  94.     ├── edgex-device-virtual.log
  95.     └── README
  96. dockercompose_rules-templates
  97. └── _data
  98.     └── rule-template.drl
  99. dockercompose_rules-uploads
  100. └── _data
  101.     └── motortoofastsignal.drl

复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ号:15599633|管理员邮箱:admin@edgexfoundry.net|Archiver|手机版|小黑屋|edgexfoundry ( 赣ICP备19008954号 )

GMT+8, 2020-7-11 03:02 , Processed in 0.034860 second(s), 22 queries .

© 2018-2019 edgexfoundry.net

快速回复 返回顶部 返回列表