首页 > 系统教程 > LINUX > 正文

CentOS 7 简单搭建OpenLDAP服务

DDD
发布: 2025-01-29 15:06:49
原创
1057人浏览过

centos 7 简单搭建openldap服务

**安装OpenLDAP服务**

首先,安装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
登录后复制
**配置OpenLDAP服务**
  1. 创建管理员密码:
slappasswd
登录后复制
登录后复制
登录后复制

记录生成的密码,稍后配置中会用到。

  1. 配置根密码:

使用文本编辑器创建一个名为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
登录后复制
**设置域名和数据库配置**
  1. 创建目录管理员密码:
slappasswd
登录后复制
登录后复制
登录后复制

记录生成的密码。

  1. 配置域名和管理员信息:

创建一个名为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
登录后复制
  1. 创建基础条目:

创建一个名为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
登录后复制
**添加用户**
  1. 生成用户密码:
slappasswd
登录后复制
登录后复制
登录后复制

记录生成的密码。

  1. 创建用户条目:

创建一个名为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
登录后复制
  1. 验证用户:
ldapsearch -x -D "cn=Manager,dc=example,dc=com" -W -b "dc=example,dc=com"
登录后复制

请记住将占位符域名和密码哈希值替换为你自己的值。 在执行命令前,仔细检查所有.ldif文件中的内容,确保没有错误。

以上就是CentOS 7 简单搭建OpenLDAP服务的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号