Configuring MongoDB for SCG
– only versions < SCG 1 2209 –
|
Requires Node.js, debconf-utils, the other tools and MongoDB are installed. |
-
Start the MongoDB service.
Copysystemctl start mongod
-
Create a MongoDB user account with username scg_admin and define a password for it.
Copymongo
> 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 -
Configure the MongoDB database:
-
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).
Copynet:
port: 27017
bindIp: 127.0.0.1,<hostname>
security:
authorization: enabled
keyFile: /etc/mongod.keyfile
replication:
replSetName: "rs0" -
Create a file named mongod.keyfile
Replace <Base64ReplicaSetKey> with a Base64 string.
Copyecho "<Base64ReplicaSetKey>" | tee /etc/mongod.keyfile
chown mongodb:mongodb /etc/mongod.keyfile
chmod 600 /etc/mongod.keyfile -
Restart the mongod service.
Copysystemctl restart mongod
-
-
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.
Copymongo -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