在特定的mongodb设置中部署fiware-orion

时间:2018-03-01 10:11:22

标签: mongodb fiware-orion

我使用mongodb分片并用docker复制。 (托管15个容器的3个虚拟机)。我的Mongodb集群是完全正常的。

现在我尝试连接Orion CB。 Normaly我必须将它连接到Mongo路由器,但它不起作用。

这是我的MongoDB堆栈文件

version: "3.4"
services:

  db1-1:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm1]
    image: mongo:3.6.2
    hostname: db1-1
    environment:
      - MONGODB_REPLICA_SET_MODE=primary
    ports:
      - "27011:27011"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db1-1:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs1 --shardsvr --dbpath /data/db --port 27011
    networks:
      STC-nw-mongo1:
        aliases:
          - db1-1

  db1-2:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm2]
    image: mongo:3.6.2
    hostname: db1-2
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary

    ports:
      - "27012:27012"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db1-2:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs1 --shardsvr --dbpath /data/db --port 27012
    networks:
      STC-nw-mongo1:
        aliases:
          - db1-2

  db1-3:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm3]
    image: mongo:3.6.2
    hostname: db1-3
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "27013:27013"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db1-3:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs1 --shardsvr --dbpath /data/db --port 27013
    networks:
      STC-nw-mongo1:
        aliases:
          - db1-3

  db2-1:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm1]
    image: mongo:3.6.2
    hostname: db2-1
    environment:
      - MONGODB_REPLICA_SET_MODE=primary
    ports:
      - "27021:27021"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db2-1:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs2 --shardsvr --dbpath /data/db --port 27021
    networks:
      STC-nw-mongo1:
        aliases:
          - db2-1

  db2-2:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm2]
    image: mongo:3.6.2
    hostname: db2-2
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "27022:27022"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db2-2:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs2 --shardsvr --dbpath /data/db --port 27022
    networks:
      STC-nw-mongo1:
        aliases:
          - db2-2

  db2-3:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm3]
    image: mongo:3.6.2
    hostname: db2-3
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "27023:27023"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db2-3:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs2 --shardsvr --dbpath /data/db --port 27023
    networks:
      STC-nw-mongo1:
        aliases:
          - db2-3

  db3-1:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm1]
    image: mongo:3.6.2
    hostname: db3-1
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "27031:27031"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db3-1:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs3 --shardsvr --dbpath /data/db --port 27031
    networks:
      STC-nw-mongo1:
        aliases:
          - db3-1

  db3-2:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm2]
    image: mongo:3.6.2
    hostname: db3-2
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "27032:27032"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db3-2:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs3 --shardsvr --dbpath /data/db --port 27032
    networks:
      STC-nw-mongo1:
        aliases:
          - db3-2

  db3-3:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm3]
    image: mongo:3.6.2
    hostname: db3-3
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "27033:27033"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/db3-3:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet iot-rs3 --shardsvr --dbpath /data/db --port 27033
    networks:
      STC-nw-mongo1:
        aliases:
          - db3-3

  dbconfig1:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm1]
    image: mongo:3.6.2
    hostname: dbconfig1
    environment:
      - MONGODB_REPLICA_SET_MODE=primary
    ports:
      - "37001:37001"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/dbconfig1:/data/configdb
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet conf-serv --configsvr --port 37001
    networks:
      STC-nw-mongo1:
        aliases:
          - dbconfig1

  dbconfig2:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm2]
    image: mongo:3.6.2
    hostname: dbcoonfig2
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "37002:37002"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/dbconfig2:/data/configdb
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet conf-serv --configsvr --port 37002
    networks:
      STC-nw-mongo1:
        aliases:
          - dbconfig2

  dbconfig3:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm3]
    image: mongo:3.6.2
    hostname: dbconfig3
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
    ports:
      - "37003:37003"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/dbconfig3:/data/configdb
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongod --replSet conf-serv --configsvr --port 37003
    networks:
      STC-nw-mongo1:
        aliases:
          - dbconfig3

  dbrouter1:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm1]
    image: mongo:3.6.2
    hostname: dbrouter1
    ports:
      - "27997:27997"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/dbrouter1:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongos --configdb conf-serv/dbconfig1:37001,dbconfig2:37002,dbconfig3:37003 --port 27997 --bind_ip_all
    networks:
      STC-nw-mongo1:
        aliases:
          - dbrouter1

  dbrouter2:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm2]
    image: mongo:3.6.2
    hostname: dbrouter2
    ports:
      - "27998:27998"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/dbrouter2:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongos --configdb conf-serv/dbconfig1:37001,dbconfig2:37002,dbconfig3:37003 --port 27998 --bind_ip_all
    networks:
      STC-nw-mongo1:
        aliases:
          - dbrouter2

  dbrouter3:
    deploy:
      placement:
        constraints: [node.hostname == docker-vm3]
    image: mongo:3.6.2
    hostname: dbrouter3
    ports:
      - "27999:27999"
    volumes:
      - /var/lib/docker/config/STC-mongo1/data/dbrouter3:/data/db
      - /var/lib/docker/config/STC-mongo1/data/certificats:/etc/ssl/iot-certs
      - /var/lib/docker/config/STC-mongo1/config:/etc/config
    command: mongos --configdb conf-serv/dbconfig1:37001,dbconfig2:37002,dbconfig3:37003 --port 27999 --bind_ip_all
    networks:
      STC-nw-mongo1:
        aliases:
          - dbrouter3

networks:
  STC-nw-mongo1:

这是我的猎户座的码头组成

version: '3.4'
services:

  orion1:
    deploy:
        placement:
          constraints: [node.hostname == docker-vm1]
    image: fiware/orion:latest
    hostname: orion1
    ports:
      - "1026:1026"
    volumes:
      - /var/lib/docker/config/STC-orion/config:/etc/sysconfig
    command: -dbhost "dbrouter1:27997,dbrouter2:27998,dbrouter3:27999" -rplSet "iot-rs1,iot-rs2,iot-rs3" -corsOrigin __ALL
    networks: 
      STC-nw-orion:
        aliases:
          - orion1

networks:
  STC-nw-orion:
    external:
      name: STC-mongo1_STC-nw-mongo1

我的orion容器正在运行,但是当我查看日志时,我只有这些信息:

docker logs -f STC-orion_orion1.1.iiv0xf6qe4pco4fk679b1s3i9 time=Wednesday 28 Feb 14:07:47 2018.732Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=mongoConnectionPool.cpp[195]:mongoConnect | msg=Database Startup Error (cannot connect to mongo - doing 100 retries with a 1000 microsecond interval)

感谢您的帮助

3 个答案:

答案 0 :(得分:2)

我不是分片专家,我从来没有用Orion测试它,但从技术上讲,@ fgalan是对的。

当您使用mongo分片时,访问通过充当路由器的mongos,即他们通过配置服务器知道将写入和读取路由到正确的分片群集,这也意味着他们处理与分片副本的连接为访问路由器的客户端设置。所以你不需要指定任何replicaset,你只需要列出你要连接的路由器(可能是驱动程序用循环方法选择的,但我不确定,你应该检查C ++传统驱动程序实施以验证)。

是的,路由器是无头服务所以(假设你正在使用堆栈部署)我会有一个你可以向上和向下扩展的服务,这样你就不需要在前面放置一个负载均衡器了(诚实地测试)

要拥有更具可配置性/可扩展性的docker服务,您可以调整我们在这里所做的工作:

当然,如果您愿意,请随意做拉动请求。

答案 1 :(得分:1)

日志中的消息基本上意味着Orion无法连接到MongoDB。可能-rplSet "iot-rs1,iot-rs2,iot-rs3"无效,因为它只需要一个副本集名称。

我不记得MongoDB分片设置的配置方面很好,其中每个分片都是由副本集实现的,但我要说副本集名称是每个分片中的内部方面。换句话说,访问mongos的过程(在本例中为Context Broker)不应该知道每个分片内部使用的副本集名称。

我建议首先使用以下简单设置:

command: -dbhost dbrouter1:27997 -corsOrigin __ALL

一旦你开始工作,尝试同时使用第二和第三个mongos进化。但是,不确定猎户座驱动程序是否会支持它。请注意,典型的多mongos部署假定应用程序的多个实例(即3个带CB的节点)在每个节点中本地运行mongos(即,在具有CB的3个节点中的每个节点中有一个mongos,每个CB与其本地mongos连接)。

following link可能很有用(althogh我不确定那个模型是否与你试图实现的情况相同)。

答案 2 :(得分:0)

感谢您的所有建议。这是我的猎户座堆栈文件。

version: '3.4'
services:

  orion1:
    deploy:
        placement:
          constraints: [node.hostname == docker-vm1]
    image: fiware/orion:latest
    hostname: orion1
    ports:
      - "1026:1026"
    command: -dbhost dbrouter1:27997 -corsOrigin __ALL
    networks: 
      STC-nw-orion:
        aliases:
          - orion1

  orion2:
    deploy:
        placement:
          constraints: [node.hostname == docker-vm2]
    image: fiware/orion:latest
    hostname: orion2
    ports:
      - "1027:1026"
    command: -dbhost dbrouter2:27998 -corsOrigin __ALL
    networks: 
      STC-nw-orion:
        aliases:
          - orion2

  orion3:
    deploy:
        placement:
          constraints: [node.hostname == docker-vm3]
    image: fiware/orion:latest
    hostname: orion3
    ports:
      - "1028:1026"
    command: -dbhost dbrouter3:27999 -corsOrigin __ALL
    networks: 
      STC-nw-orion:
        aliases:
          - orion3

networks:
  STC-nw-orion:
    external:
      name: STC-mongo1_STC-nw-mongo1

我现在配置我的HAProxy以进行负载平衡。下一步将身份验证添加到我的特殊MongoDB群集。