Skip to content

Instantly share code, notes, and snippets.

@LeCoupa
Last active February 27, 2020 05:54
Show Gist options
  • Save LeCoupa/b9a7958a1e28071995ad to your computer and use it in GitHub Desktop.
Save LeCoupa/b9a7958a1e28071995ad to your computer and use it in GitHub Desktop.
Meteor: Set up Oplog Tailing on Ubuntu --> https://github.com/LeCoupa/awesome-cheatsheets
# How to set up Oplog Tailing on your Meteor application on Ubuntu. (production environment)
# We are going to create a replica set with only one member (the primary) so as to benefit from oplog tailing.
# More: https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver
# 1. Stop MongoDB
$ sudo service mongodb stop
# 2. Edit the MongoDB configuration.
$ sudo nano /etc/mongodb.conf
# 3. Uncomment the default port, the replSet parameter
# and add fork at the bottom of the file
port = 27017
replSet = rs0 # set to something you can easily remember
fork = true # so that you can use your shell after spawning the server instance
# 4. Start the replication member.
$ mongod --config /etc/mongodb.conf
$ ps aux | grep mongo # to check that the process is running
# 5. Be sure your admin user have the clusterAdmin role.
$ mongo
> use admin
> db.auth('admin', 'pwd')
> db.users.update({'user':'admin'}, {$addToSet: {'roles' :'clusterAdmin'}})
# 6. Start the replication set.
> rs.initiate()
# 7. Your prompt should change to rs0:PRIMARY>. Then, add the oplogger user into the admin database.
rs0:PRIMARY> rs.status() # check the status and display replica set members.
rs0:PRIMARY> use admin
# For MongoDB 2.4
rs0:PRIMARY> db.addUser({ user:'oplogger', pwd:'pwd', roles:[], otherDBRoles:{ local: ['read'] } }) # can read everything that is written to the local database.
# For MongoDB 2.6
rs0:PRIMARY> db.createUser({ user:'oplogger', pwd:'pwd', roles:[] })
rs0:PRIMARY> db.runCommand({ createRole: "oplogger", privileges: [ { resource: { db: 'local', collection: 'system.replset'}, actions: ['find']}, ], roles: [{role: 'read', db: 'local'}] })
rs0:PRIMARY> db.runCommand({ grantRolesToUser: 'oplogger', roles: ['oplogger']})
rs0:PRIMARY> show users # you should see the new oplogger user appear
# 8. Launch Meteor with the environment variable "MONGO_OPLOG_URL". (in production)
# Note: Of course, you need to set MONGO_URL as usual.
$ export PORT=58080
$ export ROOT_URL='http://localhost/'
$ export MONGO_URL='mongodb://userDB:pwd@127.0.0.1:27017/DB'
$ export MONGO_OPLOG_URL='mongodb://oplogger:pwd@127.0.0.1:27017/local?authSource=admin'
$ forever start --append --uid "meteorApp" main.js
# 9. How to tell if your queries are using OplogObserveDriver?
# https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver#how-to-tell-if-your-queries-are-using-oplogobservedriver
@SNY7
Copy link

SNY7 commented Feb 7, 2017

Very useful, thanks for your sharing

@jpggvilaca
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment