- Log into mongodb1
- Configure the replicaset (with a secondary and arbiter)
rs.initiate()
rs.add('ip-internal-ip-of-mongodb2')
rs.addArb('ip-internal-ip-of-mongodb3')
- To check the replicaset config do
rs.conf()
, to check the status dors.status()
To use authentication with a replicaSet, in the ansible host config you must set a shared key such as:
auth_key: doesnt-matter-what-this-is-as-you-cant-guess-it
Authentication is set per db, with an admin db for db-wide auth.
First, create a super admin user
use admin
db.addUser( { user: "percolate", pwd: "foobar", roles: [ "userAdminAnyDatabase", "readWriteAnyDatabase", "clusterAdmin", "dbAdminAnyDatabase" ] } )
To show the configured users, do
db.system.users.find()
To add a user for e.g the atmosphere db, do
use atmosphere
db.addUser( { user: "atmosphere", pwd: "foobar", roles: ["readWrite", "dbAdmin"]})
To add a read-only user for e.g the atmosphere db, do
use atmosphere
db.addUser( { user: "reader", pwd: "$PASSWORD", roles: ["read"]})
To add an oplogger user for meteor, do
Mongodb 2.4
use admin
db.addUser({user: "oplogger", pwd: "foobar", roles: [], otherDBRoles: {local: ["read"]}})
Mongodb 2.6
use admin
db.createUser({user: "oplogger", pwd: "foobar", roles: [{role: "read", db: "local"}]})
The env vars for meteor become
MONGO_URL=mongodb://atmosphere:[email protected],db2.percolatestudio.com/atmosphere
MONGO_OPLOG_URL=mongodb://oplogger:[email protected],db2.percolatestudio.com/local?authSource=admin
To login to the mongo shell as the admin user do mongo -u percolate -p "$PASSWORD" --authenticationDatabase admin
- Connect to the target db e.g
mongo db1-staging.versoapp.com/verso
- Drop the database
db.dropDatabase();
- Clone e.g
db.cloneDatabase("db1.versoapp.com")
Unfortunately You must delete the db before you clone, so be careful!
- Connect to 2.4 database with a 2.6 shell, run
db.upgradeCheckAllDBs()
- Upgrade mongo package on the server by adding the
mongodb_version: 2.6
variable intoinventory/group_vars/tag_Mongodb.yaml
and running thegcontrol/ansible/playbooks/provision_mongodb.yaml
playbook.
- [NOTE AT THIS POINT YOU CANNOT RESTART THE METEOR APP WITHOUT UPDATING TO 1.1]
- Update authorization schema:
- connect to 2.6 server,
admin
db - run
db.getSiblingDB("admin").runCommand({authSchemaUpgrade: 1 });
- run
db.runCommand({grantRolesToUser: 'oplogger', roles: [{role: "read", db: "local"}]})
- Restart Meteor application.