OpenLDAP简介
OpenLDAP 是一款轻量级目录访问协议(Lightweight Directory Access Protocol,LDAP),属于开源集中账号管理架构的实现,且支持众多系统版本,被广大互联网公司所采用。
LDAP 具有两个国家标准,分别是X.500 和LDAP。OpenLDAP 是基于X.500 标准的,而且去除了X.500 复杂的功能并且可以根据自我需求定制额外扩展功能,但与X.500 也有不同之处,例如OpenLDAP 支持TCP/IP 协议等,目前TCP/IP 是Internet 上访问互联网的协议。
OpenLDAP 则直接运行在更简单和更通用的TCP/IP 或其他可靠的传输协议层上,避免了在OSI会话层和表示层的开销,使连接的建立和包的处理更简单、更快,对于互联网和企业网应用更理想。LDAP 提供并实现目录服务的信息服务,目录服务是一种特殊的数据库系统,对于数据的读取、浏览、搜索有很好的效果。目录服务一般用来包含基于属性的描述性信息并支持精细复杂的过滤功能,但OpenLDAP 目录服务不支持通用数据库的大量更新操作所需要的复杂的事务管理或回滚策略等。
安装OpenLDAP
sudo apt install slapd ldap-utils
安装过程中会提示设置管理员密码。

安装完成后ldap会自动启动。
OpenLDAP配置
sudo dpkg-reconfigure slapd
Omit OpenLDAP server configuration: 选择 NO.

DNS Domain name 设置:

机构名称设置:

管理员密码设置:
与第一步安装时的密码一致即可。
存储选择,推荐选择MDB:

配置完成:
Backing up /etc/ldap/slapd.d in /var/backups/slapd-2.4.48+dfsg-1ubuntu1… done. Moving old database directory to /var/backups: directory unknown… done. Creating initial configuration… done. Creating LDAP directory… done.
LDAP客户端配置
sudo vi /etc/ldap/ldap.conf
BASE dc=your-domain,dc=com URI ldap://localhost
your-domain com 替换成自己的域名,以本文为例, BASE dc=lijun,dc=info
如果你需要设置子域名,格式如下:
BASE dc=subdomain,dc=your-domain,dc=com
OpenLDAP服务器测试
ldapsearch -x

Result: 0 Success 表示设置成功,result: 32 No such object 表示设置失败。
使用密码策略
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/ppolicy.ldif
添加完成后需要重启ldap服务:
sudo service slapd restart
OpenLDAP管理
可以安装 phpldapadmin 或者 ApacheDirectoryStudio,具体安装方法请参照其官方文档。下面以Apache Directory Studio为例:


密码为前面设置的管理员密码。
