
首先,安装OpenLDAP服务器和客户端组件:
yum install -y openldap-servers openldap-clients
复制并配置数据库配置文件:
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG chown ldap. /var/lib/ldap/DB_CONFIG
启动并启用OpenLDAP服务:
systemctl start slapd systemctl enable slapd
- 创建管理员密码:
slappasswd
记录生成的密码,稍后配置中会用到。
- 配置根密码:
使用文本编辑器创建一个名为chrootpw.ldif的文件,并将生成的管理员密码添加到olcRootPW字段中。 例如:
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx // 将xxxxxxxxxxxxxxxxxxxxxxxx替换为你的密码哈希值
然后导入配置:
ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif
导入必要的模式文件:
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
- 创建目录管理员密码:
slappasswd
记录生成的密码。
- 配置域名和管理员信息:
创建一个名为chdomain.ldif的文件,替换dc=jumpserver,dc=tk为你自己的域名,并将生成的目录管理员密码添加到olcRootPW字段中。 请注意olcAccess部分的权限设置。 以下是一个示例,请根据你的需求修改:
OpenWBS B2C商城系统是一款功能强大的企业商城管理系统,主要面向广大的电商企业用户,系统支持快速搭建电商商城,以提高商家营销能力和平台运营能力为核心,为企业打造便捷高效的电子商务商城网站。 系统特点:功能强大安全稳定无漏洞操作简单 部署方式:独立部署(系统和数据库安装到企业客户自己的服务器里,保证安全) 授权类型:商业授权(年版授权、终身授权、源码授权) 配
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=example,dc=com" read by * none
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=example,dc=com // 替换为你的域名
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=example,dc=com // 替换为你的域名和管理员DN
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx // 将xxxxxxxxxxxxxxxxxxxxxxxx替换为你的密码哈希值
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=example,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=example,dc=com" write by * read
然后导入配置:
ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif
- 创建基础条目:
创建一个名为basedomain.ldif的文件,替换dc=jumpserver,dc=tk为你自己的域名。 例如:
dn: dc=example,dc=com // 替换为你的域名 objectClass: top objectClass: dcObject objectclass: organization o: Example Organization dc: example dn: cn=Manager,dc=example,dc=com // 替换为你的域名 objectClass: organizationalRole cn: Manager description: Directory Manager dn: ou=People,dc=example,dc=com // 替换为你的域名 objectClass: organizationalUnit ou: People dn: ou=Group,dc=example,dc=com // 替换为你的域名 objectClass: organizationalUnit ou: Group
然后导入配置:
ldapadd -x -D cn=Manager,dc=example,dc=com -W -f basedomain.ldif
允许LDAP服务通过防火墙:
firewall-cmd --add-service=ldap --permanent firewall-cmd --reload
- 生成用户密码:
slappasswd
记录生成的密码。
- 创建用户条目:
创建一个名为ldapuser.ldif的文件,替换dc=jumpserver,dc=tk为你自己的域名,并将生成的密码添加到userPassword字段中。 例如:
dn: uid=test,ou=People,dc=example,dc=com // 替换为你的域名
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: test
sn: Linux
userPassword: {SSHA}xxxxxxxxxxxxxxxxx // 将xxxxxxxxxxxxxxxxx替换为你的密码哈希值
loginShell: /bin/bash
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/test
dn: cn=test,ou=Group,dc=example,dc=com // 替换为你的域名
objectClass: posixGroup
cn: test
gidNumber: 1000
memberUid: test
然后导入配置:
ldapadd -x -D cn=Manager,dc=example,dc=com -W -f ldapuser.ldif
- 验证用户:
ldapsearch -x -D "cn=Manager,dc=example,dc=com" -W -b "dc=example,dc=com"
请记住将占位符域名和密码哈希值替换为你自己的值。 在执行命令前,仔细检查所有.ldif文件中的内容,确保没有错误。









