Skip to main content

Convert MongoDB Single Node to Replica Set

Based on the system architecture of this product, MongoDB single nodes are divided into using storage component mirroring built-in MongoDB or using separately deployed MongoDB. In addition, on this basis, it is also necessary to distinguish whether to enable authentication. So it includes the following 4 situations:

  • Use built-in MongoDB without authentication enabled
  • Turn on authentication using built-in MongoDB
  • When using external MongoDB, authentication is not enabled
  • Use external MongoDB to enable authentication

Built-in MongoDB refers to the MongoDB component included in the mingdaoyun-sc:3.2.0 image

  1. Add ENV_MONGODB_DAEMON_ARGS: "--replSet sc-mongodb" in docker-compose.yaml as follows:

    After adding ENV_MONGODB_DAEMON_ARGS, it will automatically convert to replica set mode. The built-in script is: rs.initiate({_id: "sc-mongodb",members:[ {_id : 1, host : "sc:27017"} ]}) (If there are other clients connecting to this MongoDB, you need to add a host resolution record for the sc service name on the client)

    services:
    core:
    image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-core:7.4.2
    environment: &app-environment
    ENV_MONGODB_DAEMON_ARGS: "--replSet sc-mongodb"
  2. Restart the service and execute in the root directory of the manager:

    bash ./service.sh restartall