ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

openLDAP 部署(亲测可用)

2021-03-30 18:05:20  阅读:263  来源: 互联网

标签:dn cn 部署 dc openLDAP LDAP com example 亲测


前言

最近在搭建openLDAP时候百度了挺多文章,大多都缺失一部分,或者进行不下去。个人整理出文章供大家参考 ,如有错误请指出。

介绍

轻型目录访问协议(简称LDAP)是一种行业标准的轻量级协议,广泛用于访问目录服务。目录服务是一种共享的信息基础结构,用于访问,管理,组织和更新日常项目和网络资源,例如用户,组,设备,电子邮件地址,电话号码,容量和许多其他对象。

该LDAP信息模型是基于条目。LDAP目录中的条目代表单个单位或信息,并由所谓的专有名称(DN)唯一标识。每个条目的属性都有一个类型和一个或多个值。
  
属性是与条目关联的一条信息。这些类型通常是助记符字符串,例如,“ cn ”代表通用名称,“ mail ”代表电子邮件地址。为每个属性分配一个或多个值,这些值由空格分隔的列表组成。

以下说明了如何在LDAP目录中安排信息。

Ldap信息模型
 
在本文中,我们将展示如何在CentOS 7中安装和配置OpenLDAP服务器以进行集中身份验证。

安装

  • 环境介绍
  • CentOS 7.6
  • 关闭防火墙
  • ldap版本2.4.xx

1.首先,首先使用以下命令安装OpenLDAP,这是LDAP的开源实现和一些传统的LDAP管理实用程序。

#yum -y install openldap compat-openldap openldap-clients openldap-servers openldap-devel 

2.在CentOS 7上,运行以下命令以启动openldap服务器守护程序,使其在启动时自动启动,并检查其是否启动并运行

# systemctl start slapd
# systemctl enable slapd
# systemctl status slapd
# slapd -VV

配置ldap server

注意:不建议手动编辑LDAP配置,您需要将配置添加到文件中,并使用ldapadd或ldapmodify命令将它们加载到LDAP目录中,如下所示。

  1. 现在创建一个OpenLDAP管理用户,并为该用户分配密码。在以下命令中,将为给定密码创建一个哈希值,请注意该哈希值,您将在LDAP配置文件中使用它。
# slappasswd

  1. 然后创建一个LDIF文件(ldaprootpasswd.ldif),该文件用于将条目添加到LDAP目录。
# vim ldaprootpasswd.ldif

dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}PASSWORD_CREATED

explaining the attribute-value pairs above:

> olcDatabase: indicates a specific database instance name and can be typically found inside /etc/openldap/slapd.d/cn=config.
 cn=config: indicates global config options.
 PASSWORD: is the hashed string obtained while creating the administrative user.

3.接下来,通过指定引用ldap服务器和上面文件的URI添加相应的LDAP条目。

# ldapadd -Y EXTERNAL -H ldapi:/// -f ldaprootpasswd.ldif

配置 LDAP 数据

1.现在,将用于slapd的示例数据库配置文件复制到/ var / lib / ldap目录中,并对该文件设置正确的权限。

#  cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
# chown -R ldap:ldap /var/lib/ldap/DB_CONFIG
# systemctl restart slapd

2.接下来,如下所示从/ etc / openldap / schema目录中导入一些基本LDAP模式。

#  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

3.现在,将您的域添加到LDAP数据库中,并为您的域创建一个名为ldapdomain.ldif的文件。

#  vim ldapdomain.ldif

在其中添加以下内容(将示例替换为您的域,并将PASSWORD替换为之前获得的哈希值)

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: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}PASSWORD

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

4.然后使用以下命令将上述配置添加到LDAP数据库中

#  ldapmodify -Y EXTERNAL -H ldapi:/// -f ldapdomain.ldif

5.在这一步中,我们需要向LDAP目录中添加一些条目。使用以下内容创建另一个名为baseldapdomain.ldif的文件。

dn: dc=example,dc=com
objectClass: top
objectClass: dcObject
objectclass: organization
o: example com
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 

Save the file and then add the entries to the LDAP directory.

#  ldapadd -Y EXTERNAL -x -D cn=Manager,dc=example,dc=com -W -f baseldapdomain.ldif

6.下一步是创建LDAP用户(例如tecmint),并为该用户设置密码,如下所示。

#  useradd tecmint
#  passwd tecmint

7.然后在具有以下内容的名为ldapgroup.ldif的文件中为LDAP组创建定义。

dn: cn=Manager,ou=Group,dc=example,dc=com
objectClass: top
objectClass: posixGroup
gidNumber: 1005

在以上配置中,gidNumber是/ etc / group中tecmint的GID,并将其添加到OpenLDAP目录中。

#  ldapadd -Y EXTERNAL -x  -W -D "cn=Manager,dc=example,dc=com" -f ldapgroup.ldif

8.接下来,创建另一个名为ldapuser.ldif的LDIF文件,并添加用户tecmint的定义。

dn: uid=tecmint,ou=People,dc=example,dc=com
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: tecmint
uid: tecmint
uidNumber: 1005
gidNumber: 1005
homeDirectory: /home/tecmint
userPassword: {SSHA}PASSWORD_HERE
loginShell: /bin/bash
gecos: tecmint
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0

然后将配置加载到LDAP目录。

# ldapadd -Y EXTERNAL  -x -D cn=Manager,dc=example,dc=com -W -f  ldapuser.ldif

一旦设置了用于身份验证的中央服务器,最后一部分就是使客户端能够使用LDAP进行身份验证,可以使用phpldapadmin或ldapadmin.exe(推荐)

有关更多信息,请参阅《OpenLDAP软件》文档目录中的相应文档

标签:dn,cn,部署,dc,openLDAP,LDAP,com,example,亲测
来源: https://blog.csdn.net/qq_35961346/article/details/115331677

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有