Problem adding a replica set member

While working on HW-1.6, I am having issues adding the second member to the replica set. Here is how it goes:

MongoDB Enterprise HW-1.6:PRIMARY>
MongoDB Enterprise HW-1.6:PRIMARY> rs.add(‘database.m310.mongodb.university:31161’)
{
“ok” : 0,
“errmsg” : “Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: database:31160; the following nodes did not respond affirmatively: database.m310.mongodb.university:31161 failed with not authorized on admin to execute command { replSetHeartbeat: “HW-1.6”, pv: 1, v: 2, from: “database:31160”, fromId: 0, checkEmpty: false }”,
“code” : 74
}
MongoDB Enterprise HW-1.6:PRIMARY>

For information in case this may be useful:

MongoDB Enterprise HW-1.6:PRIMARY> rs.isMaster()
{
“hosts” : [
“database:31160”
],
“setName” : “HW-1.6”,
“setVersion” : 1,
“ismaster” : true,
“secondary” : false,
“primary” : “database:31160”,
“me” : “database:31160”,
“electionId” : ObjectId(“7fffffff0000000000000001”),
“maxBsonObjectSize” : 16777216,
“maxMessageSizeBytes” : 48000000,
“maxWriteBatchSize” : 1000,
“localTime” : ISODate(“2020-11-26T07:36:05.172Z”),
“maxWireVersion” : 4,
“minWireVersion” : 0,
“ok” : 1
}
MongoDB Enterprise HW-1.6:PRIMARY>

What options/parameters passed to start mongod?
Did you create the user?
Are you using the same session where you did rs.initiate() or logged in with user?

This

database.m310.mongodb.university:31161

and

database:31160

make me think that the second one was not started with its fully qualified host name.

Yes I created the user without any apparent problem.

I launched mongodb with these commands:

mongod --replSet HW-1.6 --dbpath ./M310-HW-1.6/r0 --logpath ./M310-HW-1.6/r0/mongodb.log --port 31160 --auth --setParameter authenticationMechanisms=PLAIN --setParameter saslauthdPath="/var/run/saslauthd/mux" --fork

mongod --replSet HW-1.6 --dbpath ./M310-HW-1.6/r1 --logpath ./M310-HW-1.6/r1/mongodb.log --port 31161 --auth --setParameter authenticationMechanisms=PLAIN --setParameter saslauthdPath="/var/run/saslauthd/mux" --fork

mongod --replSet HW-1.6 --dbpath ./M310-HW-1.6/r2 --logpath ./M310-HW-1.6/r2/mongodb.log --port 31162 --auth --setParameter authenticationMechanisms=PLAIN --setParameter saslauthdPath="/var/run/saslauthd/mux" --fork

In case this can be useful:

vagrant@database:~$ ps ex

PID TTY STAT TIME COMMAND
7878 ? S 0:00 sshd: vagrant@pts/0
7879 pts/0 Ss 0:00 -bash LC_CTYPE=UTF-8 USER=vagrant LOGNAME=vagrant HOME=/home/vagrant PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games MAIL=
8781 ? Sl 1:20 mongod --replSet HW-1.6 --dbpath ./M310-HW-1.6/r0 --logpath ./M310-HW-1.6/r0/mongodb.log --port 31160 --auth --setParameter authenticationMechanisms=PLAIN --setParamete
8808 ? Sl 1:19 mongod --replSet HW-1.6 --dbpath ./M310-HW-1.6/r1 --logpath ./M310-HW-1.6/r1/mongodb.log --port 31161 --auth --setParameter authenticationMechanisms=PLAIN --setParamete
8835 ? Sl 1:19 mongod --replSet HW-1.6 --dbpath ./M310-HW-1.6/r2 --logpath ./M310-HW-1.6/r2/mongodb.log --port 31162 --auth --setParameter authenticationMechanisms=PLAIN --setParamete
8943 pts/0 Sl+ 0:01 mongo --host HW-1.6/database.m310.mongodb.university:31160 XDG_SESSION_ID=4 TERM=xterm-256color SHELL=/bin/bash SSH_CLIENT=10.0.2.2 50897 22 SSH_TTY=/dev/pts/0 LC_ALL=C
9513 ? S 0:00 sshd: vagrant@pts/1
9514 pts/1 Ss 0:00 -bash LC_CTYPE=UTF-8 USER=vagrant LOGNAME=vagrant HOME=/home/vagrant PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games MAIL=
9542 pts/1 R+ 0:00 ps ex XDG_SESSION_ID=6 TERM=xterm-256color SHELL=/bin/bash SSH_CLIENT=10.0.2.2 49531 22 SSH_TTY=/dev/pts/1 LC_ALL=C USER=vagrant LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:
vagrant@database:~$

While trying to solve the problem once more and reading the text of the HW-1.6 again, I realize that I may have missed some important detail.

I read in the text:

Part of your provided scripts in the handout setup OpenLDAP and add a user named adam with the password password .

Then later I read:

Create an account for adam .

I don’t know what to understand or I am missing something here.

Is the account for adam provided ? Or am I supposed to create it ?

Or I forgot some detail and need to review some lecture ??

There is 2 things to do.

  1. Add the user in the LDAP server. OpenLDAP in this case but can be ActiveDirectory.

  2. Add the user in mongod that indicates that the user authentication is external LDAP.

This way when a client connects to mongod and claim he is adam, mongod see that adam is in fact an external LDAP user. It then communicates with the LDAP server to authenticate the user.

OK. Thank you; I will try that.

But I still don’t quite get it all. The last line in the setup-hw-1.6.sh script is this:

python ~/shared/ldapconfig.py add -u adam -p password

Isn’t this supposed to add a user in LDAP ? In other words your first step?

If I am missing something, please explain if your can.

For the time being the only thing I can understand is that the first step you write is not to do. It is already done be the script. (Let me know if this is not right)

For the second step, is this what needs to be done ?

db.getSiblingDB("$external").runCommand({createUser: “adam”, roles: [{role: ‘root’, db:‘admin’}]})

Or is it something else?

Also to connect to mongod for the first time. Is this command OK ?

mongo --host database.m310.mongodb.university --port 31160

… Though I made some progress, I am still having problems.
I created a new thread ( Can’t add a replica set member / HW-1.6) with my current situation.