HW1.3 not able to create users

i started the mongod with replica sets as follows
vagrant@database:~ mongod --replSet myReplSet --dbpath ~/M310-HW-1.3/r0/db --logpath ~/M310-HW-1.3/r0/mongodb.log --port 31130 --fork --sslMode requireSSL --clusterAuthMode x509 --sslPEMKeyFile ~/shared/certs/server.pem --sslCAFile ~/share d/certs/ca.pem about to fork child process, waiting until server is ready for connections. forked process: 4580 child process started successfully, parent exiting vagrant@database:~ mongod --replSet myReplSet --dbpath ~/M310-HW-1.3/r1/db --logpath ~/M310-HW-1.3/r1/mongodb.log --por
t 31131 --fork --sslMode requireSSL --clusterAuthMode x509 --sslPEMKeyFile ~/shared/certs/server.pem --sslCAFile ~/share
d/certs/ca.pem
about to fork child process, waiting until server is ready for connections.
forked process: 4607
child process started successfully, parent exiting
vagrant@database:~ mongod --replSet myReplSet --dbpath ~/M310-HW-1.3/r2/db --logpath ~/M310-HW-1.3/r2/mongodb.log --por t 31132 --fork --sslMode requireSSL --clusterAuthMode x509 --sslPEMKeyFile ~/shared/certs/server.pem --sslCAFile ~/share d/certs/ca.pem about to fork child process, waiting until server is ready for connections. forked process: 4634 child process started successfully, parent exiting vagrant@database:~

tried to connect mongo
vagrant@database:~/shared/certs$ mongo --ssl --sslPEMKeyFile client.pem --sslCAFile ca.pem --host database.m310.mongodb.university --port 31130
MongoDB shell version: 3.2.22
connecting to: database.m310.mongodb.university:31130/test
MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.createUser({
… user: “admin”,
… pwd: “webscale”,
… roles: [
… {role: “root”, db: “admin”}
… ]
… })
2019-08-27T08:25:27.588+0000 E QUERY [thread1] Error: couldn’t add user: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1267:15
@(shell):1:1

I am not able to create user because i couldn’t login into client with PRIMARY replica set though i have started mongod with replicasets successfully.

Please guide me if i am missing something.

Thanks

Perhaps you forgot to https://docs.mongodb.com/manual/reference/method/rs.initiate/

I did the rs.initiate() now but giving error as follows

vagrant@database:~/shared/certs$ mongo --ssl --sslPEMKeyFile client.pem --sslCAFile ca.pem --host database.m310.mongodb.university --port 31130
MongoDB shell version: 3.2.22
connecting to: database.m310.mongodb.university:31130/test
MongoDB Enterprise > rs.initiate(
… {
… _id: “myReplSet”,
… version: 1,
… members: [
… { _id: 0, host : “m310.mongodb.university:31130” },
… { _id: 1, host : “.m310.mongodb.university:31131” },
… { _id: 2, host : “.m310.mongodb.university:31132” }
… ]
… }
… )
{
“ok” : 0,
“errmsg” : “No host described in new configuration 1 for replica set myReplSet maps to this node”,
“code” : 93
}

Something is off with your hosts with _id:1 and _id:2. The host name starts with a dot. I am not sure but I think it should be database.m310… for all hosts. I am also very surprised that 31131 and 31132 started correctly. For 31131 it looks like --port has a newline between --por and the letter t while 31132 has a space. Perhabs they both started but are not listening to the correct port. Try ss -tlup to see which process listen to which port. In addition ps -aef | grep mongod | grep -v grep could indicate which mongod are running.

vagrant@database:~ **ss -tlup** Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp UNCONN 0 0 *:bootpc *:* tcp UNCONN 0 0 *:sunrpc *:* tcp UNCONN 0 0 *:36519 *:* tcp UNCONN 0 0 *:48372 *:* tcp UNCONN 0 0 *:848 *:* tcp UNCONN 0 0 127.0.0.1:894 *:* tcp UNCONN 0 0 :::sunrpc :::* tcp UNCONN 0 0 :::41110 :::* tcp UNCONN 0 0 :::848 :::* tcp UNCONN 0 0 :::27497 :::* tcp LISTEN 0 128 *:sunrpc *:* tcp LISTEN 0 128 *:31120 *:* users:(("mongod",3623,7)) tcp LISTEN 0 128 *:31121 *:* users:(("mongod",3650,7)) tcp LISTEN 0 128 *:31122 *:* users:(("mongod",3677,7)) tcp LISTEN 0 128 *:ssh *:* tcp LISTEN 0 128 *:31130 *:* users:(("mongod",4580,7)) tcp LISTEN 0 128 *:31131 *:* users:(("mongod",4607,7)) tcp LISTEN 0 128 *:31132 *:* users:(("mongod",4634,7)) tcp LISTEN 0 128 *:33312 *:* tcp LISTEN 0 128 127.0.0.1:27017 *:* tcp LISTEN 0 128 :::55182 :::* tcp LISTEN 0 128 :::sunrpc :::* tcp LISTEN 0 128 :::ssh :::* vagrant@database:~

vagrant@database:~$ ps -aef | grep mongod | grep -v grep
mongodb 2760 1 0 06:42 ? 00:02:56 /usr/bin/mongod --config /etc/mongod.conf
vagrant 3623 1 1 07:12 ? 00:04:35 mongod --replSet TO_BE_SECURED --dbpath /home/vagrant/M310-HW-1.2/r0/db --logpath /home/vagrant/M310-HW-1.2/r0/mongodb.log --port 31120 --fork --keyFile /home/vagrant/mongodb-keyfile
vagrant 3650 1 1 07:12 ? 00:04:28 mongod --replSet TO_BE_SECURED --dbpath /home/vagrant/M310-HW-1.2/r1/db --logpath /home/vagrant/M310-HW-1.2/r1/mongodb.log --port 31121 --fork --keyFile /home/vagrant/mongodb-keyfile
vagrant 3677 1 1 07:12 ? 00:04:28 mongod --replSet TO_BE_SECURED --dbpath /home/vagrant/M310-HW-1.2/r2/db --logpath /home/vagrant/M310-HW-1.2/r2/mongodb.log --port 31122 --fork --keyFile /home/vagrant/mongodb-keyfile
vagrant 4580 1 0 08:13 ? 00:02:18 mongod --replSet myReplSet --dbpath /home/vagrant/M310-HW-1.3/r0/db --logpath /home/vagrant/M310-HW-1.3/r0/mongodb.log --port 31130 --fork --sslMode requireSSL --clusterAuthMode x509 --sslPEMKeyFile /home/vagrant/shared/certs/server.pem --sslCAFile /home/vagrant/shared/certs/ca.pem
vagrant 4607 1 0 08:14 ? 00:02:17 mongod --replSet myReplSet --dbpath /home/vagrant/M310-HW-1.3/r1/db --logpath /home/vagrant/M310-HW-1.3/r1/mongodb.log --port 31131 --fork --sslMode requireSSL --clusterAuthMode x509 --sslPEMKeyFile /home/vagrant/shared/certs/server.pem --sslCAFile /home/vagrant/shared/certs/ca.pem
vagrant 4634 1 0 08:14 ? 00:02:17 mongod --replSet myReplSet --dbpath /home/vagrant/M310-HW-1.3/r2/db --logpath /home/vagrant/M310-HW-1.3/r2/mongodb.log --port 31132 --fork --sslMode requireSSL --clusterAuthMode x509 --sslPEMKeyFile /home/vagrant/shared/certs/server.pem --sslCAFile /home/vagrant/shared/certs/ca.pem
vagrant 6015 4737 0 13:30 pts/1 00:00:00 mongo --ssl --sslPEMKeyFile client.pem --sslCAFile ca.pem --host database.m310.mongodb.university --port 31130

MongoDB Enterprise > rs.initiate(
… {
… _id: “myReplSet”,
… version: 1,
… members: [
… { _id: 0, host : “database.m310.mongodb.university.:31130” },
… { _id: 1, host : “database.m310.mongodb.university.:31131” },
… { _id: 2, host : “database.m310.mongodb.university:31132” }
… ]
… }
… )
{
“ok” : 0,
“errmsg” : “No host described in new configuration 1 for replica set myReplSet maps to this node”,
“code” : 93
}
MongoDB Enterprise >

still getting error after correcting hostname

In the future please format your output to be more readable the html tags code or pre can be use for this. It looks like your keyboard is not working well since you have other typing errors.

For _id:0 and _id:1 the host names end with a dot.

1 Like