3

I am deploy a monodb sharding, I have deploy a replica set in three machines:

dev41:27017,dev42:27017,dev193:27017

and configsvr in three machine:

dev41:27019,dev42:27019,dev193:27019

and also a mongos in machine:

dev41:28000

at last I try to add my replica into mongos:

mongo dev41:28000/admin
sh.addShard('rs0/dev41,dev42,dev193')

then I got errors:

{
    "ok" : 0,
    "errmsg" : "could not find host matching read preference { mode: \"primary\" } for set rs0",
    "code" : 133
}
  • Please note that using the same three servers for both a shard server replica set and config server is not a recommended production configuration. During operation, there will be extensive resource contention between multiple mongod processes within each machine, which may result in sub-optimal performance or worse. – kevinadi Nov 24 '16 at 22:09

10 Answers 10

2

I faced the same issue then looked into Mongos log file and it was saying

can't authenticate to hostname as internal user, error: Authentication failed.

Please see here: internal user authentication and happens with SecKey file and auth- Enabled.

Resolution

I opened mongod.conf file and

security: authorization: enabled    
keyFile: /var/run/mongodb/secKey.key

was missing so I added that and restart the mongod. Then I created shard again from Mongos and it is working now.

1

I had this same issue, and found out that I simply had the name of the replica set wrong in the addShard command.

1

I had the same issue, but my problem was that before calling sh.addShard() I needed to login to the new shard server (not mongos), and call the following command:

rs.initiate({ _id : "REPLICA_SET_NAME", members: [ { _id : 0, host : "HOSTNAME:27017" } ] })

After that, I was able to call sh.addShard() without problems.

Note that this works without security: authorization: enabled in my mongo.conf

Cheers,

  • i did ``` rs.initiate( { _id: "rs1", configsvr: true, members: [ { _id : 0, host : "mongo-ubuntu16-001:27019" }, { _id : 1, host : "mongo-ubuntu16-002:27019" }, { _id : 2, host : "mongo-ubuntu16-003:27019" } ] } ) ``` and then mongos --configdb rs1/mongo-ubuntu16-001:27019,mongo-ubuntu16-002:27019 --bind_ip localhost,10.142.0.2 still i am getting "code" : 133 error while adding shard sh.addShard() please help – maswadkar May 15 '18 at 21:44
1

I had a same issue. Problem in my configuration was that hosts where I set config servers to run did not have in /etc/hosts each shard member that I was supposing to add as a new shard. Problem fixed when I added missing shard members in /etc/hosts.

  • Good one, it fixed it for me - Adding the shards to the hosts files of the CONFIG servers - – octohedron Dec 18 '18 at 21:57
1

I had the same symptom, however, my issue was the keyfiles were not consistent bewteen mongod and config nodes.

1

This adds to @Miroslav's answer except that the hostname found in /etc/hostname had to match the hostname found in /etc/hosts (dont forget to reboot when changed).

I was using a common /etc/hosts file for all my servers but wasn't updating the /etc/hostname file to match.

Goodluck

0

This error will also occur if the shard host that is being specified in addShard() command is not reachable. Exit out of mongos and try to telnet it for e.g.

telnet dev42 27017 

If telnet did not work then that needs to be fixed first.

0

I had what appears to me to be the same problem.

In my case, the issue was that 2 of my shard servers went down. I simply started them up again and it took a while for the commands to propagate (I did a remove and some docs were still showing up in a collection), but after a minute or so everything was correct.

0

Check if mongod service running on Arbiter node, this solved my problem

0
  1. Need to be sure that your Replicaset name is the correct.
  2. Ensure to at least add the ip or hostname of the master in the replicaset.
  3. Ensure to add the correct port of the master node in the replicaset.
  4. Check that you are using the correct keyfile defined in mongos and rs.

After that you just need to use:

sh.addShard("your_rs_name/rs_master_ip_or_hostname:port")

and it's all, mongos will take all the members in the rs you just have added. Good luck

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.