首先,安装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部分的权限设置。 以下是一个示例,请根据你的需求修改:
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文件中的内容,确保没有错误。
以上就是CentOS 7 简单搭建OpenLDAP服务的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号