1.软件安装
1.1系统环境
-
Linux:Fedora 17 x86.64
-
Openldap:openldap2.4.33
-
PostgreSQL:PostgreSQL 9.1.6
-
unixODBC:unixODBC 2.3.1
1.2必须软件包
openldap.x86_64
openldap-clients.x86_64 #提供一些客户端程序,测试可用
openldap-servers.x86_64
openldap-servers-sql.x86_64 #后端数据库相关,必须安装
openldap-devel.x86_64 #devel包,可选择行安装
1.3安装步骤
以上这些必备软件包在fedora17下直接通过yum安装即可:
[root@fedoraopenldap]# yum install openldap.x86_64
[root@fedoraopenldap]# yum install openldap-clients.x86_64
[root@fedoraopenldap]# yum install openldap-servers.x86_64
安装完成后,查看安装包是否全部安装:
[root@fedoraopenldap]# yum list openldap*
2使用PostgreSQL作为后台数据库
2.1导入测试数据
如果使用其它关系型数据库作为LDAP的后台,则需要进行数据库的映射,目录:
/usr/share/doc/openldap-servers-sql-2.4.33/rdbms_depend里提供了各类数据库的映射文件和测试数据。测试数据和映射文件也可以从以下站点中下载:
http://www.openldap.org/faq/data/cache/978.html
导入数据之前要确认PostgreSQL和unixODBC的安装,并且PostgreSQL下建有logink数据库和unixODBC下建有Logink数据源。PostgreSQL和unixODBC的设置请参考《PostgreSQL数据库使用手册》。
往logink数据库中导入数据,运行以下命令:
[root@localhost]#cd /usr/share/doc/openldap-servers-sql-2.4.33/rdbms_depend/pgsql/
[root@localhost]#psql -U postgres logink < backsql_create.sql
[root@localhost]#psql -U postgres logink < testdb_create.sql
[root@localhost]#psql -U postgres logink < testdb_data.sql
[root@localhost]#psql -U postgres logink < testdb_metadata.sql
2.2使用管理员权限打开slapd.conf文件
-
在终端输入su-和密码;
-
运行cd /etc/openldap/;
-
运行geditslapd.conf使用gedit打开文件
2.3配置slapd.conf和ldap.conf文件
slapd.conf文件(红色部分为修改部分):
#
#See slapd.conf(5) for details on configuration options.
#This file should NOT be world readable.
#
include /etc/openldap/schema/corba.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
#Define global ACLs to disable default read access.
#引入读写权限,accessto *代表所有用户
accessto *
by selfwrite
by * read
accessto * by dn="cn=root,dc=wulisuo,dc=com" write
#Do not enable referrals until AFTER you have a working directory
#service AND an understanding of referrals.
#referral ldap://root.openldap.org
pidfile /usr/local/var/run/slapd.pid
#slapd.pid是程序运行时才生成的文件,路径可以随意指定
argsfile /usr/local/var/run/slapd.args
#同上,原本这两个文件都没有
#Load dynamic backend modules:
#modulepath /usr/local/libexec/openldap
#moduleload back_bdb.la
#moduleload back_hdb.la
#moduleload back_ldap.la
#Sample security restrictions
# Requireintegrity protection (prevent hijacking)
# Require112-bit (3DES or better) encryption for updates
# Require63-bit encryption for simple bind
#security ssf=1 update_ssf=112 simple_bind=64
#Sample access control policy:
# RootDSE: allow anyone to read it
# Subschema(sub)entry DSE: allow anyone to read it
# OtherDSEs:
# Allowself write access
# Allowauthenticated users read access
# Allowanonymous users to authenticate
# Directivesneeded to implement policy:
#access to dn.base="" by * read
#access to dn.base="cn=Subschema" by * read
#access to *
# byself write
# byusers read
# byanonymous auth
#
#if no access controls are present, the default policy
#allows anyone and everyone to read anything but restricts
#updates to rootdn. (e.g., "access to * by * read")
#
#rootdn can always read and write EVERYTHING!
#设定日志
loglevel 256
#如果想要使用PostgreSQL或MySQL数据库必须导入以下两行
modulepath /usr/lib64/openldap
moduleload back_sql.la
#######################################################################
#sqldatabase definitions
#######################################################################
database sql
#修改合适的前缀
suffix "dc=wulisuo,dc=com"
rootdn "cn=root,dc=wulisuo,dc=com"
rootpwsecret
#dbname代表ODBC中设置的数据源
dbname Logink
#dbuser代表postgresql用户
dbuser postgres
dbpasswd postgres
insentry_stmt "insertinto ldap_entries (id,dn,oc_map_id,parent,keyval) values ((selectmax(id)+1 from ldap_entries),?,?,?,?)"
upper_func "upper"
strcast_func "text"
concat_pattern "?||?"
has_ldapinfo_dn_ru no
设置完文件后运行:/usr/sbin/slaptest-f /etc/openldap/slapd.conf进行测试,如果PostgreSQL数据库中没有存在测试数据,则会出现“bi-db-openfailed! Test would using the -u ”。导入测试数据请查看相应的步骤,如果出现其他错误则根据提示进行相应改写。
ldap.conf文件:
可以不进行配置,如果要进行配置则修改以下两行:
#BASEdc=wulisuo,dc=com
#URIldap://ldap.wulisuo.comldap://ldap-master.wulisuo.com:666
2.4启动LDAP服务
启动LDAP服务之前先要启动PostgreSQL服务,然后运行以下命令:
[root@localhost~]# /usr/sbin/slapd -d 256 -f /etc/openldap/slapd.conf
关闭服务:运行kill-INT `cat /usr/local/var/run/slapd.pid`,其中slapd.pid的路径可以在slapd.conf中查询。
3 LDAP后端数据库操作
3.1插入节点
-
打开终端,运行vi init.ldif文件;
-
输入i开始编辑文件;
-
输入以下内容,其中dc和cn字段参照之前在slapd.conf中的设置:
dn:dc=wulisuo,dc=com
objectClass:dcObject
objectClass:organization
dc:wulisuo
o:wulisuoCompany
description: dCorporation
-
退出init.ldif文件的编辑;
-
执行添加命令:
ldapadd-f init.ldif -x -D "cn=root,dc=wulisuo,dc=com" -w secret
其中secret代表你设置的密码,如果没有设置过便为secret;
-
查询记录是否添加成功,运行以下命令:
/usr/bin/ldapsearch-x -b "dc=wulisuo,dc=com"
如果出现以下内容则表示记录添加成功,否则重新查看ldif文件里的内容:
dn:dc=wulisuo,dc=com
objectClass:dcObject
objectClass:organization
dc: wulisuo
o: wulisuoCompany
description: dCorporation
# searchresult
search: 2
result: 0Success
#numResponses: 3
# numEntries:2
3.2数据库操作
以下数据的插入需要自定义