After use admin. When you add the user db. addUser ("admin", "123456"), because other nodes do not have the admin user and use the-keyFile parameter, permission authentication is required. The first time a user cannot be created.
Symptoms:
The code is as follows: |
Copy code |
Switched to db admin { "User": "admin ", "ReadOnly": false, "Pwd": "dfb2b4f665d248c6887cfba7b1f0c9fc ", "_ Id": ObjectId ("50b41bb41e7bf4084c43a793 ") } Tue Nov 27 09:47:32 uncaught exception: couldn't add user: SyncClusterConnection: insert prepare failed: 10.200.7.106: 10021: {errmsg: "need to login", OK: 0.0} 10.200.7.221: 10021: {errmsg: "need to login", OK: 0.0} 10.200.7.226: 10021: {errmsg: "need to login", OK: 0.0} |
Solution.Do not add the-keyFile parameter during the first startup. Create an admin user after startup. Then stop all nodes.
Add the-keyFile parameter. Restart the cluster. You can.
The code is as follows: |
Copy code |
. /Bin/mongod-shardsvr-replSet shard1-port 10020-dbpath data/shard1a-keyFile/data/support/mongodb-2.2.1/primary key-oplogSize 100-logpath logs/shard1a. log-logappend-fork-rest -- nojournal |