Configuring MongoDB for SCG

– only versions < SCG 1 2209

Requires 

Node.js, debconf-utils, the other tools and MongoDB are installed.

  1. Start the MongoDB service.

    Copy
    systemctl start mongod
  2. Create a MongoDB user account with username scg_admin and define a password for it.

    Copy
    mongo

    > use admin
    > db.createUser(
      {
        user: "scg_admin",
        pwd: "<scg_admin_password>",
        roles: [{role: 'userAdminAnyDatabase', db: 'admin'}, {role: 'readWriteAnyDatabase', db: 'admin'}, {role: 'clusterManager', db: 'admin'}]
      }
    )
    > exit
  3. Configure the MongoDB database:

    1. Edit the /etc/mongod.conf file and ensure that the relevant values are set for network, security and cluster.

      Replace <hostname> with the hostname of your SCG machine (to be identified via hostname command).

      Copy
      net:
        port: 27017
        bindIp: 127.0.0.1,<hostname>
      security:
        authorization: enabled
        keyFile: /etc/mongod.keyfile
      replication:
        replSetName: "rs0"
    2. Create a file named mongod.keyfile

      Replace <Base64ReplicaSetKey> with a Base64 string.

      Copy
      echo "<Base64ReplicaSetKey>" | tee /etc/mongod.keyfile
      chown mongodb:mongodb /etc/mongod.keyfile
      chmod 600 /etc/mongod.keyfile
    3. Restart the mongod service.

      Copy
      systemctl restart mongod
  4. Create a replica set with the desired number of members/instances. Replace the password parameter with your MongoDB user password defined above. If required, add more instances.

    Copy
    mongo -u scg_admin -p <scg_admin_password>
    > rs.status()
    // should print out: "no replset config has been received"
    > rs.initiate({_id: "rs0", members: [{_id: 0, host: "<hostname>"}]})
    > exit