Allow to set replica for MongoDB configuration backend
Sent by Albéric de Pertat:
I am currently building a three nodes cluster with LemonLDAP::NG 1.9 (Ubuntu 14.04) and storing configuration in a MongoDB cluster (one instance on each LL::NG node, in a replica set). I have been following the official documentation (http://lemonldap-ng.org/documentation/1.9/mongodbconfbackend), which is OK for one node, but not for a cluster.
First, in lemonldap-ng.ini I need to declare the host MongoDB-URI style :
host = mongodb://portail1:27017,portail2:27017,portail3:27017
{code}
But then, lmConfEditor will not work :
{code}
$ /usr/share/lemonldap-ng/bin/lmConfigEditor
Running as uid 33 and gid 33 0
MongoDB::SelectionError: No readable server available for matching read
preference primary. MongoDB server status:
Topology type: Sharded; Member status:
{code}
This is because the MongoDB configuration backend does not allow us to
specify the replica set. I have modified Lemonldap/NG/Common/Conf/MongoDB.pm like this :
{code}
--- MongoDB.pm.orig 2016-03-24 16:42:43.287704391 +0100
+++ MongoDB.pm 2016-03-24 16:43:11.395705731 +0100
@@ -28,7 +28,7 @@
return $self->{_mongoDB} if ( $self->{_mongoDB} );
my $conn_args = {};
foreach my $w (
- qw(host auth_mechanism auth_mechanism_properties
connect_timeout_ms db_name port ssl username password)
+ qw(host auth_mechanism auth_mechanism_properties
connect_timeout_ms db_name port ssl username password replica
_set_name)
)
{
$conn_args->{$w} = $self->{$w} if ( defined $self->{$w} );
{code}
I just need to set the replica set name in lemonldap-ng.ini :
{code}
replica_set_name = llng
And it should work.
This is a quick and dirty hack as I am sure the MongoDB backend would surely benefit from a number of specific options that I do not know of. Anyway, keep up the good work !