0

I have a mongo shared cluster and replica sets:

The ShardA Replica set:

A1. 10.77.14.241 

A2. 10.77.14.242

AA. 10.77.14.243 Arbiter

Some parameters of /etc/mongod.conf:

#bind_ip=127.0.0.1
auth=true
replSet=ShardB
keyFile=/srv/mongodb/mongodb-keyfile

The ShardB Replica set:

B1. 10.77.14.244 

B2. 10.77.14.245

BA. 10.77.14.246 Arbiter

Some parameters of /etc/mongod.conf:

#bind_ip=127.0.0.1
auth=true
replSet=ShardB
keyFile=/srv/mongodb/mongodb-keyfile

The Config and Mongos servers:

C1. 10.77.14.247

C2. 10.77.14.248

C3. 10.77.14.249

All instances of config mongod and mongos are started in /etc/rc.local:

mongod --configsvr  --logpath /var/log/mongodb/mongod.log --keyFile /srv/mongodb/mongodb-keyfile --fork
mongos --configdb 10.77.14.247:27019,10.77.14.248:27019,10.77.14.249:27019 --port 40000 --logpath /data/mongos.log --keyFile /srv/mongodb/mongodb-keyfile --fork

The Replica sets work correctly. If I insert documents in the primary member it replicates on the secondary member.

I have following issue: On any arbiter, mongod config, mongos -

use admin   
switched to db admin    
mongos> db.auth({user: 'admin', pwd: '12345678'})    
Error: 18 Authentication failed.
0

Hence i can't insert documents to a DB over mongos.

Do I have to enable a sharding of the admin a DB?

2

I reread http://docs.mongodb.org/manual/tutorial/enable-authentication-without-bypass/ :)

1) I started on the C1, C2, C3:

mongod --configsvr  --logpath /var/log/mongodb/mongod.log --fork
mongos --configdb 10.77.14.247:27019,10.77.14.248:27019,10.77.14.249:27019 --port 40000 --logpath /data/mongos.log --fork

2) I created a new user on mongos:

use admin
db.createUser(
    {
      user: "admin",
      pwd: "12345678",
      roles: [
         { role: "clusterManager", db: "admin" },
         { role: "userAdminAnyDatabase", db: "admin" }
      ]
    }
)

3) I restarted instances of the mongod config and mongos --keyfile parameter:

  mongod --configsvr  --logpath /var/log/mongodb/mongod.log --fork --keyFile /srv/mongodb/mongodb-keyfile
mongos --configdb 10.77.14.247:27019,10.77.14.248:27019,10.77.14.249:27019 --port 40000 --logpath /data/mongos.log --fork --keyFile /srv/mongodb/mongodb-keyfile

4) Adding Shards was succesful:

db.auth({user:'admin', pwd: '12345678'})
1

sh.addShard("ShardA/10.77.14.241:27017,10.77.14.242:27017,10.77.14.243:27017")
{ "shardAdded" : "ShardA", "ok" : 1 }

sh.addShard("ShardB/10.77.14.244:27017,10.77.14.245:27017,10.77.14.246:27017")
{ "shardAdded" : "ShardB", "ok" : 1 }
  • Very good and simple explanation. Hope MongoDB docs had this. – Nilam Doctor Oct 24 '15 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.