How can I initiate the mongo replica with LDAP

I encountered some tough problems . :disappointed_relieved:
I’m try to finish M310/homework 1.6 .
I can’t fully understand description :

The command can success : testsaslauthd -u adam -p password -f /var/run/saslauthd/mux

And first auto-shell :
#!/bin/bash

course="M310"
exercise="HW-1.6"
workingDir="$HOME/${course}-${exercise}"
dbDir="$workingDir/db"
logName="mongo.log"

ports=(31160 31161 31162)
replSetName="TO_BE_SECURED"

host=`hostname -f`
initiateStr="rs.initiate({
                 _id: '$replSetName',
                 members: [
                  { _id: 1, host: '$host:31160' },
                  { _id: 2, host: '$host:31161' },
                  { _id: 3, host: '$host:31162' }
                 ]
                })"

# create working folder
mkdir -p "$workingDir/"{r0,r1,r2}

# launch mongod's
for ((i=0; i < ${#ports[@]}; i++))
do
  mongod --auth  --dbpath "$workingDir/r$i" --logpath "$workingDir/r$i/$logName.log" --port ${ports[
$i]} --replSet $replSetName --fork  --setParameter authenticationMechanisms=PLAIN --setParameter sas
lauthdPath="/var/run/saslauthd/mux"
done

# wait for all the mongods to exit
sleep 3

# initiate the set
mongo --port ${ports[0]} --eval "$initiateStr"

The result is :

So I delete --auth,and kill all mongo process and remove all mongo’s data,run again! initiate success,


and run follow command:
db.getSiblingDB("$external").createUser({user:‘adam’,roles:[{role:‘root’,db:‘admin’}]})
db.getSiblingDB("$external").auth({mechanism:“PLAIN”,user:‘adam’,pwd:‘password’,digestPassword: false})
now, the result:

but when I reboot with --auth, the errorlog:

So I try to start only one server:
initiate success,create user:‘adam’ success,and auth success. But add member :


How can I deployment the mongo replica with LDAP?

Since this is related to mongodb university lab you may get better response from University forum

LDAP is an external authentication mechanism.You still need a keyfile for internal authentication between nodes

It is about to change.

Yah! I have forget add " --keyfile " :rofl: :rofl: :rofl:
All problems have been solved.
Thanks ! :smiling_face_with_three_hearts:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.