Sei sulla pagina 1di 9

Search

Home

LinuxServer

LinuxCommand

PHP

Forum

HowtoinstallOpenLDAPwithMySQLasbackenddataon
Debian664bit
Tweet

Like

Submittedbywinggundamthon3November,201115:00

Tags:
LinuxServer Debian MySQL OpenLDAP

Linux
LDAP(LightweightDirectoryAccessProtocol)asitsname,isaprotocoltoaccesstoDirectory
Service.WellknownLDAPisActiveDirectorythatspecificonWindowsServer.ButfortheLinux
oneisOpenLDAP
NormallyOpenLDAPwillkeepalltheDirectorydatainLDIFFileFormat(sample)butversionprior
2.0OpenLDAPsupportbacksqlthatwillkeepdatainRDBMSsowecanimportdatadirectlyfrom
databasetoOpenLDAP.
ThisarticlewillfocusoninstallOpenLDAPwithMySQLasbackenddataonDebian664bit.IfI
havetimeIwillwritemoreabouthowtocreateMySQLschemaforOpenLDAP
WestartwithInstallDebian664bit
slapd(OpenLDAPServer)thatcomewithaptgetnotsupportedbacksql.Sowehavetocompile
andinstallfromsourcewiththesecommands
aptgetinstalllibssldevlibdbdevunixodbcdevtime
wgetftp://ftp.openldap.org/pub/OpenLDAP/openldaprelease/openldap2.4.26.tgz
tarxvfzopenldap*.tgz
cdopenldap*
./configureenablesql
makedepend
make
makeinstall

AndwewillinstallMySQLServerandcreateuseranddatabaseforOpenLDAP

aptgetinstallmysqlserverlibmyodbc
#putmysqlrootpasswordandconfirmpasswordthatyouwant
mysqlurootp
#putmysqlrootpassword
CREATEUSER'openldap'@'localhost'IDENTIFIEDBY'yourpassword';
CREATEDATABASEIFNOTEXISTSopenldap;
GRANTALLPRIVILEGESONopenldap.*TO'openldap'@'localhost';
FLUSHPRIVILEGES;
exit

Don'tforgettochangeyourpassword
WewillconfigODBCthatslapdcanreadfromMySQLdatabase.edit/etc/odbc.ini
[openldap]
Description=ExampleforOpenLDAP'sbacksql
Driver=MySQL
Trace=No
Database=openldap
Servername=localhost
UserName=openldap
Password=yourpassword
ReadOnly=No
RowVersioning=No
ShowSystemTables=No
ShowOidColumn=No
FakeOidIndex=No
ConnSettings=
SOCKET=/var/run/mysqld/mysqld.sock

andedit/etc/odbcinst.ini
[MySQL]
Description=ODBCforMySQL
Driver=/usr/lib/odbc/libmyodbc.so
FileUsage=1

TrytoimportsampleMySQLthatcomewithopenldap2.4.26.tgz
cdservers/slapd/backsql/rdbms_depend/mysql/
mysqluopenldappopenldap<backsql_create.sql
mysqluopenldappopenldap<testdb_create.sql
mysqluopenldappopenldap<testdb_data.sql
mysqluopenldappopenldap<testdb_metadata.sql
#putmysqlopenldapuser

edit/usr/local/etc/openldap/slapd.conf
#$OpenLDAP$
#
#Seeslapd.conf(5)fordetailsonconfigurationoptions.
#ThisfileshouldNOTbeworldreadable.

#
include/usr/local/etc/openldap/schema/core.schema
include/usr/local/etc/openldap/schema/cosine.schema
include/usr/local/etc/openldap/schema/inetorgperson.schema

#DefineglobalACLstodisabledefaultreadaccess.

#DonotenablereferralsuntilAFTERyouhaveaworkingdirectory
#serviceANDanunderstandingofreferrals.
#referralldap://root.openldap.org

pidfile/usr/local/var/slapd.pid
argsfile/usr/local/var/slapd.args

#######################################################################
#sqldatabasedefinitions
#######################################################################

databasesql
suffix"dc=example,dc=com"
rootdn"cn=root,dc=example,dc=com"
rootpwrootpassword
dbnameopenldap
dbuseropenldap
dbpasswdyourpassword
subtree_cond"ldap_entries.dnLIKECONCAT('%',?)"
insentry_stmt"INSERTINTOldap_entries(dn,oc_map_id,parent,keyval)VALUES(?,?,?,?
)"
has_ldapinfo_dn_runo

Don'tforgettoeditrootpasswordtomysqlopenldapuserpassword
Trytotestbyrunslapdindebugmodeanduseldapsearchtosearchingdatainanotherwindows
/usr/local/libexec/slapdd1
ldapsearchxDcn=root,dc=example,dc=comwrootpasswordssubb"dc=example,dc=co
m""(objectClass=*)"

Ifldapsearchfoundthedata.itwillreturn
#numResponses:8
#numEntries:6
#numReferences:1

Butifldapsearchcan'tfindthedataitwillreturnonly#numResponses:1
PressCtrl+ctoexitslapdfromdebugmode.Thenwewillconfigslapdtostartautomaticwhen
bootbycreate/etc/init.d/slapd24fileandputtheselines
#!/bin/sh
###BEGININITINFO
#Provides:slapd24
#RequiredStart:$remote_fs$network$syslog
#RequiredStop:$remote_fs$network$syslog
#DefaultStart:2345

#DefaultStop:016
#ShortDescription:OpenLDAPstandaloneserver(LightweightDirectoryAccessProtocol
)
###ENDINITINFO

#Specifypathvariable
PATH=/sbin:/usr/sbin:/bin:/usr/bin

./lib/lsb/initfunctions

#Killmeonallerrors
sete

#Setthepathstoslapdasavariablesothatsomeonewhoreally
#wantstocanoverridethepathin/etc/default/slapd.
SLAPD=/usr/local/libexec/slapd

#Stopprocessingifslapdisnotthere
[x$SLAPD]||exit0

#debconfmayhavethisfiledescriptoropenanditmakesthingsworkabit
#morereliablyifweredirectitasamatterofcourse.db_stopwilltake
#careofthis,butthiswon'thurt.
exec3>/dev/null

#Sourcetheinitscriptconfiguration
if[f"/etc/default/slapd"];then
./etc/default/slapd
fi

#Loadthedefaultlocationoftheslapdconfigfile
if[z"$SLAPD_CONF"];then
if[e/etc/ldap/slapd.d];then
SLAPD_CONF=/etc/ldap/slapd.d
else
SLAPD_CONF=/usr/local/etc/openldap/slapd.conf
fi
fi

#Stopprocessingiftheconfigfileisnotthere
if[!r"$SLAPD_CONF"];then
log_warning_msg"Noconfigurationfilewasfoundforslapdat$SLAPD_CONF."
#ifthereisnoconfigatall,weshouldassumeslapdisnotrunning
#andexit0onstopsothatunconfiguredpackagescanberemoved.
["x$1"=xstop]&&exit0||exit1
fi

#extendoptionsdependingonconfigtype
if[f"$SLAPD_CONF"];then
SLAPD_OPTIONS="f$SLAPD_CONF$SLAPD_OPTIONS"
elif[d"$SLAPD_CONF"];then
SLAPD_OPTIONS="F$SLAPD_CONF$SLAPD_OPTIONS"
fi

#Findoutthenameofslapd'spidfile
if[z"$SLAPD_PIDFILE"];then
#Ifusingoldonefileconfigurationscheme
if[f"$SLAPD_CONF"];then
SLAPD_PIDFILE=`sedne's/^pidfile[[:space:]]\+\(.\+\)/\1/p'\
"$SLAPD_CONF"`
#Else,ifusingnewdirectoryconfigurationscheme

elif[d"$SLAPD_CONF"];then
SLAPD_PIDFILE=`sedne\
's/^olcPidFile:[[:space:]]\+\(.\+\)[[:space:]]*/\1/p'\
"$SLAPD_CONF"/'cn=config.ldif'`
fi
fi

#XXX:Breaksupgradingifthereisnopidfile(invokerc.dstopwillfail)
#Torsten
if[z"$SLAPD_PIDFILE"];then
log_failure_msg"Thepidfileforslapdhasnotbeenspecified"
exit1
fi

#Makesurethepidfiledirectoryexistswithcorrectpermissions
piddir=`dirname"$SLAPD_PIDFILE"`
if[!d"$piddir"];then
mkdirp"$piddir"
[z"$SLAPD_USER"]||chownR"$SLAPD_USER""$piddir"
[z"$SLAPD_GROUP"]||chgrpR"$SLAPD_GROUP""$piddir"
fi

#Passtheuserandgrouptorunundertoslapd
if["$SLAPD_USER"];then
SLAPD_OPTIONS="u$SLAPD_USER$SLAPD_OPTIONS"
fi

if["$SLAPD_GROUP"];then
SLAPD_OPTIONS="g$SLAPD_GROUP$SLAPD_OPTIONS"
fi

#Checkwhetherwewereconfiguredtonotstarttheservices.
check_for_no_start(){
if[n"$SLAPD_NO_START"];then
echo'Notstartingslapd:SLAPD_NO_STARTsetin/etc/default/slapd'>&
2
exit0
fi
if[n"$SLAPD_SENTINEL_FILE"]&&[e"$SLAPD_SENTINEL_FILE"];then
echo"Notstartingslapd:$SLAPD_SENTINEL_FILEexists">&2
exit0
fi
}

#Telltheuserthatsomethingwentwrongandgivesomehintsfor
#resolvingtheproblem.
report_failure(){
log_end_msg1
if[n"$reason"];then
log_failure_msg"$reason"
else
log_failure_msg"Theoperationfailedbutnooutputwasproduced."

if[n"$SLAPD_OPTIONS"o\
n"$SLAPD_SERVICES"];then
if[z"$SLAPD_SERVICES"];then
if[n"$SLAPD_OPTIONS"];then
log_failure_msg"Commandlineused:slapd$SLA
PD_OPTIONS"
fi
else

log_failure_msg"Commandlineused:slapdh'$SLAPD_S
ERVICES'$SLAPD_OPTIONS"
fi
fi
fi
}

#Starttheslapddaemonandcapturetheerrormessageifanyto
#$reason.
start_slapd(){
if[z"$SLAPD_SERVICES"];then
reason="`startstopdaemonstartquietoknodo\
pidfile"$SLAPD_PIDFILE"\
exec$SLAPD$SLAPD_OPTIONS2>&1`"
else
reason="`startstopdaemonstartquietoknodo\
pidfile"$SLAPD_PIDFILE"\
exec$SLAPDh"$SLAPD_SERVICES"$SLAPD_OPTIONS2>&1`"
fi

#BackwardcompatibilitywithOpenLDAP2.1clientlibraries.
if[!h/var/run/ldapi]&&[!e/var/run/ldapi];then
lnsslapd/ldapi/var/run/ldapi
fi
}

#Stoptheslapddaemonandcapturetheerrormessage(ifany)to
#$reason.
stop_slapd(){
reason="`startstopdaemonstopquietoknodoretryTERM/10\
pidfile"$SLAPD_PIDFILE"\
exec$SLAPD2>&1`"
}

#StarttheOpenLDAPdaemons
start_ldap(){
trap'report_failure'0
log_daemon_msg"StartingOpenLDAP""slapd"
start_slapd
trap""0
log_end_msg0
}

#StoptheOpenLDAPdaemons
stop_ldap(){
trap'report_failure'0
log_daemon_msg"StoppingOpenLDAP""slapd"
stop_slapd
trap""0
log_end_msg0
}

case"$1"in
start)
check_for_no_start
start_ldap;;
stop)
stop_ldap;;
restart|forcereload)
check_for_no_start
stop_ldap

start_ldap
;;
status)
status_of_procp$SLAPD_PIDFILE$SLAPDslapd
;;
*)
echo"Usage:$0{start|stop|restart|forcereload|status}"
exit1
;;
esac

Thenrunthecommand
updaterc.dslapd24defaults

Testbyrebootonetimeandtestwithldapsearchanditshouldreturnthedatacorrectly.
47168reads

Comments
ThankYouwinggundamthNice
Submittedbyvijithon30January,201223:16

ThankYouwinggundamthNiceArticle.iconfiguredSuccessfullycanutellmeHowtocreate
userinMysqldatabase(LDAPuser)?

ItdependsonMySQLstructure
Submittedbywinggundamthon1February,201203:25

ItdependsonMySQLstructure.ForthistutorialI'mjustshowinghowtoinstallwithsample
data.
IreadhowtocreateMySQLstructureforOpenLDAPhere
http://www.flatmtn.com/article/settingldapbacksql.

SocialNetwork

WingFOSS
231likes
LikePageLiked
YoulikethisBethefirstof
yourfriendstolikethis
GantiJeneng

WingFOSS on

Navigation
Home
Knowledge
LinuxCommand
LinuxServer
PHP
Ubuntu
Forum
Search
Recentcontent

Userlogin
Username*

Password*

Requestnewpassword
Login

Recentcomments
AnotherofHowTo,3years8monthsago
Thanksazimbrillion!!!3years8monthsago
YoucanuseWindowsDNS.But3years8monthsago
Ipreferredirectinsteadof3years8monthsago
sudouzimbra/opt/zimbra3years8monthsago
https://webmail.zimbra3years8monthsago
Howcanyouencriptyourweb3years8monthsago
Hello!Nicetutorial!3years8monthsago
ItdependsonMySQLstructure3years8monthsago
NevertryonUbuntuDesktop3years8monthsago

Who'sonline
Therearecurrently0usersonline.

ThisworkislicensedunderaCreativeCommonsAttributionNoncommercialShareAlike3.0Thailand
License.

Potrebbero piacerti anche