安装:
yum install openldap openldap-servers openldap-clients
拷贝数据库配置文件
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap /var/lib/ldap/DB_CONFIG
DB_CONIFG中主要是关于Berkeley DB的相关的一些配置
启动OpenLDAP Server:
systemctl start slapd
systemctl enable slapd
systemctl status slapd
slapd即standard alone ldap daemon,该进程默认监听389端口
设置root用户密码
先用一个命令生成一个LDAP管理用户root密码:
slAppasswd
New password:
Re-enter new password:
{SSHA}krOGXDmiCdSXuXocOf10F96LJO5ijdXo #记住这个,下面会用到
新建一个rootpwd.ldif(名称是自定义的)的文件:
vi rootpwd.ldif
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}krOGXDmiCdSXuXocOf10F96LJO5ijdXo
下面使用ldapadd命令将上面的rootpwd.ldif文件写入LDAP:
ldapadd -Y EXTERNAL -H ldapi:/// -f rootpwd.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={0}config,cn=config"
导入schema
导入schema,schema包含为了支持特殊场景相关的属性,可根据选择导入,这里先全部导入:
ls /etc/openldap/schema/*.ldif | while read f; do ldapadd -Y EXTERNAL -H ldapi:/// -f $f; done
设定默认域
先使用slappasswd生成一个密码:
slappasswd
New password:
Re-enter new password:
{SSHA}OpMcf0c+pEqFLZm3i+YiI2qhId1G/yM3
新建一个domain.ldif的文件:
vi domain.ldif
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth"
read by dn.base="cn=Manager,dc=zhidaoauto,dc=com" read by * none
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=zhidaoauto,dc=com
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=zhidaoauto,dc=com
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}OpMcf0c+pEqFLZm3i+YiI2qhId1G/yM3 #替换上面生成的密码
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
dn="cn=Manager,dc=zhidaoauto,dc=com" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=zhidaoauto,dc=com" write by * read
写入:
ldapmodify -Y EXTERNAL -H ldapi:/// -f domain.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={1}monitor,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
添加基本目录
新建一个basedomain.ldif的文件:
dn: dc=zhidaoauto,dc=com
objectClass: top
objectClass: dcObject
objectclass: organization
o: zhidaoauto com
dc: zhidaoauto
dn: cn=Manager,dc=zhidaoauto,dc=com
objectClass: organizationalRole
cn: Manager
description: Directory Manager
dn: ou=People,dc=zhidaoauto,dc=com
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=zhidaoauto,dc=com
objectClass: organizationalUnit
ou: Group
写入:
ldapadd -x -D cn=Manager,dc=zhidaoauto,dc=com -W -f basedomain.ldif
Enter LDAP Password:
adding new entry "dc=zhidaoauto,dc=com"
adding new entry "cn=Manager,dc=zhidaoauto,dc=com"
adding new entry "ou=People,dc=zhidaoauto,dc=com"
adding new entry "ou=Group,dc=zhidaoauto,dc=com"
测试:
ldapsearch -LLL -W -x -D "cn=Manager,dc=zhidaoauto,dc=com" -H ldap://localhost -b "dc=zhidaoauto,dc=com"
Enter LDAP Password:
dn: dc=zhidaoauto,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: zhidaoauto com
dc: zhidaoauto
dn: cn=Manager,dc=zhidaoauto,dc=com
objectClass: organizationalRole
cn: Manager
description: Directory Manager
dn: ou=People,dc=zhidaoauto,dc=com
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=zhidaoauto,dc=com
objectClass: organizationalUnit
ou: Group
管理工具
Docker run -d --privileged -p 10004:80 --name myphpldapadmin --env PHPLDAPADMIN_HTTPS=false --env PHPLDAPADMIN_LDAP_HOSTS="192.168.10.240" --detach osixia/phpldapadmin