MongoError: not authorized on local to execute command while deploy on meteor galaxy

user3931619 picture user3931619 · Mar 21, 2017 · Viewed 8.5k times · Source

I am trying to deploy my app using meteor galaxy using below command

DEPLOY_HOSTNAME=us-east-1.galaxy-deploy.meteor.com meteor deploy icrm.meteorapp.com --settings scalingo.json

but i am getting this error

MongoError: not authorized on local to execute command { find: "oplog.rs", filter: {}, sort: { $natural: -1 }, projection: { ts: 1 }, limit: 1 } in logs

in my scalingo.json, i have set as follow

"galaxy.meteor.com": {
        "env": {
            "MONGO_URL": "mongodb://username:[email protected]:37100/icrm",
            "MONGO_OPLOG_URL": "mongodb://username:[email protected]:37100/local?authSource=icrm",
            "ROOT_URL": "http://icrm.meteorapp.com/"
        }
    }

and when i am accessing http://icrm.meteorapp.com/ i am getting

503 Service Unavailable: No healthy endpoints to handle the request.

I know i am doing some mistake in setting MONGO_OPLOG_URL, i am writing same username and password in both MONGO_URL and MONGO_OPLOG_URL, i am using free sandbox version, please help me to sort out this problem, if possible suggest me solution with free sandbox version...

Thanks a lot

Answer

jordanwillis picture jordanwillis · Mar 21, 2017

It certainly sounds like you have an issue with your mongodb configuration. Unfortunately, there are a lot of differences between the various mongodb service providers, but let me share with you how mine is setup (maybe this will help you in some way). I do want to note that I am managing my own mongodb instance from a cloud linux server (instead of using a mongodb service).

  1. Enable security authorization (e.g. it is enabled in mongod.conf) and ensure that you have created an admin user (which you will use to create all your other users) and a user that your meteor app will use to access mongodb.

    First you must create an "admin" user with the correct roles to add new users. From the mongo shell you can do this.

    admin = db.getSiblingDB("admin");
    admin.createUser(
      {
        user: "admin",
        pwd: "admin-password",
        roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
      }
    );
    

    Then from the shell, login as the above user and create your account used by your meteor app. Note, I am calling my meteor app database meteor_db in this example. Change this to whatever you want.

    db.getSiblingDB("admin").auth("admin", "admin-password" );
    
    use meteor_db;
    
    db.createUser(
      {
        user: "meteor",
        pwd: "meteor",
        roles: [ { role: "readWrite", db: "meteor_db" } ]
      }
    );
    
  2. With that done, you need to configure mongodb to enable the oplog (which meteor will use for tailing). To do this, you must setup replication and 1 replication set by editing mongod.conf and modifying the replication section.

    replication:
        replSetName: rs0
    

    Restart mongodb and then initiate replication on the new member from the mongo shell (you must do this as root). Modify the below example with your specific hostname and port if you are not running mongodb on the default localhost and port number).

    rs.initiate({_id:"rs0", members: [{"_id":0, "host":"127.0.0.1:27017"}]});
    
  3. Now that oplog is enabled, you must create a user that can access the oplog. This is the user you will use to configure MONGO_OPLOG_URL (used by meteor). From the mongo shell, login as the admin user (created above) and create the new oplogger user.

    db.getSiblingDB("admin").auth("admin", "admin-password" );
    
    admin = db.getSiblingDB("admin");
    
    admin.createUser(
      {
        user: "oplogger",
        pwd: "oplogger-password",
        roles: [ { role: "read", db: "local" } ]
      }
    );
    
  4. With all the setup done, you just need to set your meteor env variables and restart your app.

    export MONGO_URL='mongodb://meteor:meteor@<hostname>:<port>/meteor_db'
    export MONGO_OPLOG_URL='mongodb://oplogger:oplogger-password@<hostname>:<port>/local?authSource=admin'
    

Let me know if you run into any issue or have further question. Also, here are some additional resources that I found helpful when I was trying to get all this setup (perhaps they will also help).