连接到Node-red时,MongoDB群集超时

发布于 2025-01-24 12:59:11 字数 3684 浏览 5 评论 0原文

我在尝试将我的mongodb:3.4群集与节点红色:2使用docker swarm连接起来时面临麻烦。

我的环境由一台领导者机器,两个工人组成(mongo1mongo2),以及其中一名工人的节点红色容器。

我通过以下命令成功地启动了我的群集:

rs.initiate({
   _id : "rs1",
   members: [
      { _id: 1, host: "mongo1:27017" },
      { _id: 2, host: "mongo2:27017" }
   ]
})

与Mongo Express的连接在我的群集的主要节点和次要节点上都成功。

但是,当我尝试使用“ nofollow noreferrer”> node-node-redred时-Node-MongoDB 模块,我收到以下错误:

MongoNetworkError: failed to connect to server [mongo2:27017] on first connect [MongoNetworkTimeoutError: connection timed out
    at connectionFailureError (/data/node_modules/mongodb/lib/core/connection/connect.js:362:14)
    at Socket.<anonymous> (/data/node_modules/mongodb/lib/core/connection/connect.js:330:16)
    at Object.onceWrapper (events.js:519:28)
    at Socket.emit (events.js:400:28)
    at Socket._onTimeout (net.js:495:8)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)]

这是配置MongoDB节点的方式:

  • host:mongo1,mongo2
  • 连接拓扑:relicaset/cluster(mongodb:/mongodb:/ /)
  • 连接选项:replicaset = rs1&amp; tls = true&amp; tlsallowInvalidCertificates = true&amp; wtimeoutms = 10000&amp; slaveok = true

,这些是docker-compose的相关部分。 yml文件:

version: '3.4'


services:
  NodeRed:
    user: root
    networks:
      - mynetwork
    volumes:
      - /home/ssmanager/nfsdata/nodered:/data
      - /home/ssmanager/nfsdata/records:/data/records
      - /home/ssmanager/nfsdata/cdr:/data/cdr
      - /home/ssmanager/nfsdata/html/decrypted_temp:/data/records/decrypted
    image: nodered/node-red:2
    deploy:
      placement:
        constraints:
          - "node.hostname!=ssmanager3"
      endpoint_mode: dnsrr
      mode: replicated
      replicas: 1
      update_config:
        delay: 10s
      restart_policy:
        condition: any
        max_attempts: 5
 
 mongo1:
    image: mongo:3.4
    command: mongod --replSet rs1 --noauth --oplogSize 3
    environment:
      TERM: xterm
    volumes:
      - /etc/localtime:/etc/localtime:ro
    networks:
      - mynetwork
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.mongo.replica == 1
          - "node.hostname!=ssmanager3"
          
  mongo2:
    image: mongo:3.4
    command: mongod --replSet rs1 --noauth --oplogSize 3
    environment:
      TERM: xterm
    volumes:
      - /etc/localtime:/etc/localtime:ro
    networks:
      - mynetwork
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.mongo.replica == 2
          - "node.hostname!=ssmanager3"

  express:
    container_name: express
    image: mongo-express:0.54.0
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: admin
      ME_CONFIG_BASICAUTH_PASSWORD: password
      ME_CONFIG_MONGODB_ENABLE_ADMIN: "true"
      ME_CONFIG_MONGODB_PORT: 27017
      ME_CONFIG_MONGODB_SERVER: mongo1
      ME_CONFIG_MONGODB_URL: mongodb://mongo:27017
      ME_CONFIG_REQUEST_SIZE: 100Mb
    command:
      - "mongo-express"
    networks:
      - mynetwork
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - "node.hostname!=dcsynmgr01"
          - "node.hostname!=ssmanager3"
    ports:
      - target: 8081
        published: 8081
        protocol: tcp
        mode: host


networks:
  host_mode:
    external:
      name: 'host'
  mynetwork:
    attachable: true

I am facing troubles while trying to connect my MongoDB:3.4 cluster to Node-RED:2 using Docker Swarm.

My environment consists of one leader machine, two workers with one Mongo node on each (mongo1 and mongo2), and the Node-RED container on one of the workers.

I successfully initiated my cluster with the below command:

rs.initiate({
   _id : "rs1",
   members: [
      { _id: 1, host: "mongo1:27017" },
      { _id: 2, host: "mongo2:27017" }
   ]
})

A connection with Mongo Express was successful on both the primary and secondary nodes of my cluster.

But when I tried to connect to the cluster from node-RED using the node-red-node-mongodb module, I got the following error:

MongoNetworkError: failed to connect to server [mongo2:27017] on first connect [MongoNetworkTimeoutError: connection timed out
    at connectionFailureError (/data/node_modules/mongodb/lib/core/connection/connect.js:362:14)
    at Socket.<anonymous> (/data/node_modules/mongodb/lib/core/connection/connect.js:330:16)
    at Object.onceWrapper (events.js:519:28)
    at Socket.emit (events.js:400:28)
    at Socket._onTimeout (net.js:495:8)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)]

This is how the MongoDB node was configured:

  • Host: mongo1,mongo2
  • Connection topology: RelicaSet/Cluster (mongodb://)
  • Connection options: replicaSet=rs1&tls=true&tlsAllowInvalidCertificates=true&wtimeoutMS=10000&slaveOk=true

And these are the relevant parts of the docker-compose.yml file:

version: '3.4'


services:
  NodeRed:
    user: root
    networks:
      - mynetwork
    volumes:
      - /home/ssmanager/nfsdata/nodered:/data
      - /home/ssmanager/nfsdata/records:/data/records
      - /home/ssmanager/nfsdata/cdr:/data/cdr
      - /home/ssmanager/nfsdata/html/decrypted_temp:/data/records/decrypted
    image: nodered/node-red:2
    deploy:
      placement:
        constraints:
          - "node.hostname!=ssmanager3"
      endpoint_mode: dnsrr
      mode: replicated
      replicas: 1
      update_config:
        delay: 10s
      restart_policy:
        condition: any
        max_attempts: 5
 
 mongo1:
    image: mongo:3.4
    command: mongod --replSet rs1 --noauth --oplogSize 3
    environment:
      TERM: xterm
    volumes:
      - /etc/localtime:/etc/localtime:ro
    networks:
      - mynetwork
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.mongo.replica == 1
          - "node.hostname!=ssmanager3"
          
  mongo2:
    image: mongo:3.4
    command: mongod --replSet rs1 --noauth --oplogSize 3
    environment:
      TERM: xterm
    volumes:
      - /etc/localtime:/etc/localtime:ro
    networks:
      - mynetwork
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.labels.mongo.replica == 2
          - "node.hostname!=ssmanager3"

  express:
    container_name: express
    image: mongo-express:0.54.0
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: admin
      ME_CONFIG_BASICAUTH_PASSWORD: password
      ME_CONFIG_MONGODB_ENABLE_ADMIN: "true"
      ME_CONFIG_MONGODB_PORT: 27017
      ME_CONFIG_MONGODB_SERVER: mongo1
      ME_CONFIG_MONGODB_URL: mongodb://mongo:27017
      ME_CONFIG_REQUEST_SIZE: 100Mb
    command:
      - "mongo-express"
    networks:
      - mynetwork
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - "node.hostname!=dcsynmgr01"
          - "node.hostname!=ssmanager3"
    ports:
      - target: 8081
        published: 8081
        protocol: tcp
        mode: host


networks:
  host_mode:
    external:
      name: 'host'
  mynetwork:
    attachable: true

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文