# yum search openldap
# yum install openldap-servers
# yum install openldap-clients
配置:
slapd有个配置文件,
/etc/openldap/slapd.d 和 /etc/openldap/slapd.conf。
rpm默认安装slapd.d。
为了使用slapd.conf,需要把/etc/openldap/slapd.d改名,
然后创建slapd.conf。
include /etc/openldap/schema/core.schema
database bdb
suffix "dc=sy,dc=cn"
rootdn "cn=Manager,dc=sy,dc=cn"
rootpw shenyue
#directory /var/lib/ldap
directory /var/lib/openldap
pidfile /var/run/openldap/slapd.pid
注意,如果没有配置文件(slapd.d或slapd.conf都不存在)
执行slapd后没有任何信息,也启动不了,而且不会报错。
如果没有include core.schema,slaptest报错。
“<suffix> invalid DN 21 (Invalid syntax)”
开启SELinux时要注意权限。
chcon -R --reference /var/lib/ldap /var/lib/openldap/
启动:
使用slaptest测试配置是否正确。
# slaptest
# ps -ef|grep slapd
# config指定的数据库目录。需要所有者为ldap,权限为600
# ll /var/lib/openldap
# rpm默认安装的数据库在/var/lib/ldap/下。
# ll /var/lib/ldap/
# service slapd stop
# service slapd start
# service slapd status
检索ldapsearch:
# ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
# ldapadd -x -D "cn=Manager,dc=test,dc=com" -W -f ex.ldif
-LLL
-v Run in verbose mode, with many diagnostics written to standard output.
-h ldaphost
Specify an alternate host on which the ldap server is running. Deprecated in favor of -H.
-x Use simple authentication instead of SASL.
-D binddn
Use the Distinguished Name binddn to bind to the LDAP directory. For SASL binds, the server
is expected to ignore this value.
-W Prompt for simple authentication. This is used instead of specifying the password on the com-
mand line.
-w passwd
Use passwd as the password for simple authentication.
-p ldapport
Specify an alternate TCP port where the ldap server is listening. Deprecated in favor of -H.
-b searchbase
Use searchbase as the starting point for the search instead of the default.
-s {base|one|sub|children}
Specify the scope of the search to be one of base, one, sub, or children to specify a base
object, one-level, subtree, or children search. The default is sub. Note: children scope
requires LDAPv3 subordinate feature extension.
filter例
objectclass=person 检索含有person及其子类(如inetOrgPerson)的记录
sn 检索含有sn的记录,即使sn为空也会被检索。想检索sn不为空的记录,指定sn=*
cn=Manager 检索cn的值为Manager的记录。