# 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
data 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 '( class=*)' 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 search
Use search as the starting point for the search instead of the default.
-s { |one|sub|children}
Specify the scope of the search to be one of , one, sub, or children to specify a
, one-level, subtree, or children search. The default is sub. Note: children scope
requires LDAPv3 subordinate feature extension.
filter例
class=person 检索含有person及其子类(如inetOrgPerson)的记录
sn 检索含有sn的记录,即使sn为空也会被检索。想检索sn不为空的记录,指定sn=*
cn=Manager 检索cn的值为Manager的记录。
继续阅读与本文标签相同的文章
-
Mysql中的Redo Log解析(二)
2026-05-26栏目: 教程
-
T5 模型:NLP Text-to-Text 预训练模型超大规模探索
2026-05-26栏目: 教程
-
20个堪称神器的 Linux 命令行软件
2026-05-26栏目: 教程
-
面试从不曾缺席,常见算法Java版
2026-05-26栏目: 教程
-
Second_Behind_Master值
2026-05-26栏目: 教程
