Linux Admin教程

安装和配置Open LDAP

LDAP 称为 轻量级目录访问协议,是一种用于访问企业内从目录中获知的 X.500 服务容器的协议。熟悉 Windows Server 的人管理人员可以认为 LDAP 在本质上与 Active Directory 非常相似。它甚至是将 Windows 工作站交织到 OpenLDAP CentOS 企业中的广泛使用的概念。另一方面,CentOS Linux 工作站可以共享资源并参与 Windows 域中的基本功能。
在 CentOS 上部署 LDAP 作为目录服务器代理、目录系统代理或 DSA(这些首字母缩写词都是一个且相同)类似于使用目录树结构和 NDS 的旧 Novell Netware 安装。

LDAP 简史

LDAP 基本上是作为一种访问具有企业资源的 X.500 目录的有效方式而创建的。 X.500 和 LDAP 具有相同的特征并且非常相似,以至于 LDAP 客户端可以通过一些帮助程序访问 X.500 目录。而 LDAP 也有自己的名为 slapd 的目录服务器。 LDAPDAP 之间的主要区别在于,轻量级版本旨在通过 TCP 运行。
虽然 DAP 使用完整的 OSI 模型。随着 Internet、TCP/IP 和以太网在当今网络中的出现,在特定的传统计算模型之外使用 DAP 和本机 X.500 企业目录的目录服务植入很少见。
用于 CentOS Linux 的 openldap 的主要组件是-
openldap LDAP 支持库
openldap-server LDAP 服务器
openldap-clients LDAP 客户端实用程序
openldap-devel OpenLDAP 的开发库
compay-openldap OpenLDAP 共享库
slapd OpenLDAP 的目录服务器守护进程
slurpd 用于跨企业域的 LDAP 复制
注意-命名您的企业时,最佳做法是使用 .local TLD。使用 .net.com 可能会在隔离在线和内部域基础结构时造成困难。想象一下使用 acme.com 进行外部和内部运营的公司在内部的额外工作。因此,拥有名为 acme.comacme.net 的 Internet 资源可能是明智之举。然后,本地网络企业资源被描述为 acme.local。这将需要配置 DNS 记录,但会以简单、流畅和安全为代价。

在 CentOS 上安装 Open LDAP

YUM 安装 openldap、openldap-servers、openldap-clients 和 migrationstools。
[root@localhost]# yum-y install openldap openldap-servers openldap-clients
migration tools
 Loaded plugins: fastestmirror, langpacks
 updates
 | 3.4 kB  00:00:00
 updates/7/x86_64/primary_db
 | 2.2 MB  00:00:05
 Determining fastest mirrors
 (1/2): extras/7/x86_64/primary_db
 | 121 kB  00:00:01
 (2/2): base/7/x86_64/primary_db
 | 5.6 MB  00:00:16
 package openldap-2.4.40-13.el7.x86_64 already installed and latest version
 Resolving Dependencies
--> Running transaction check
---> package openldap-clients.x86_64 0:2.4.40-13.el7 will be installed
---> package openldap-servers.x86_64 0:2.4.40-13.el7 will be installed
--> Finished Dependency Resolution
 base/7/x86_64/group_gz
 | 155 kB  00:00:00
 
 Dependencies Resolved
 
=============================================================================== 
=============================================================================== 
package                                Arch
Version                             Repository                        Size 
=============================================================================== 
=============================================================================== 
Installing: 
openldap-clients                    x86_64
2.4.40-13.el7                    base                                 188 k 
openldap-servers                    x86_64
2.4.40-13.el7                    base                                 2.1 M  
Transaction Summary 
=============================================================================== 
===============================================================================
Install  2 Packages
Total download size: 2.3 M 
Installed size: 5.3 M 
Downloading packages:
Installed: 
openldap-clients.x86_64 0:2.4.40-13.el7                                       
openldap-servers.x86_64 0:2.4.40-13.el7                                       
Complete! 
[root@localhost]#
现在,让我们启动并启用 slapd 服务-
[root@centos]# systemctl start slapd 
[root@centos]# systemctl enable  slapd
此时,让我们确保 /etc/openldap 中有我们的 openldap 结构。
root@localhost]# ls /etc/openldap/ 
certs  check_password.conf  ldap.conf  schema  slapd.d
[root@localhost]#
然后确保我们的 slapd 服务正在运行。
root@centos]# netstat-antup | grep slapd
tcp        0      0 0.0.0.0:389            0.0.0.0:*              LISTEN      1641/slapd
tcp6       0      0 :::389                 :::*                   LISTEN      1641/slapd
 
[root@centos]#
接下来,让我们配置我们的 Open LDAP 安装。
确保我们的系统 ldap 用户已经创建。
[root@localhost]# id ldap 
uid=55(ldap) gid=55(ldap) groups=55(ldap)
[root@localhost]#
生成我们的 LDAP 凭据。
[root@localhost]# slappasswd  
New password:  
Re-enter new password:  
{SSHA}20RSyjVv6S6r43DFPeJgASDLlLoSU8g.a10
[root@localhost]#
我们需要保存 slappasswd 的输出。

配置开放 LDAP

第 1 步-为域配置 LDAP 并添加管理用户。
首先,我们要设置我们的 openLDAP 环境。以下是用于 ldapmodify 命令的模板。
dn: olcDatabase={2}hdb,cn=config 
changetype: modify 
replace: olcSuffix 
olcSuffix: dc=vmnet,dc=local 
dn: olcDatabase = {2}hdb,cn=config 
changetype: modify 
replace: olcRootDN 
olcRootDN: cn=ldapadm,dc=vmnet,dc=local 
dn: olcDatabase = {2}hdb,cn=config 
changetype: modify 
replace: olcRootPW 
olcRootPW: <output from slap
使用 ldapmodify 命令更改:/etc/openldap/slapd.d/cn=config/olcDatabase = {1}monitor.ldif。
[root@localhost]# ldapmodify-Y EXTERNAL-H ldapi:///-f /home/rdc/Documents/db.ldif  
SASL/EXTERNAL authentication started 
SASL username: gidNumber = 0+uidNumber = 0,cn=peercred,cn=external,cn=auth 
SASL SSF: 0 
modifying entry "olcDatabase = {2}hdb,cn=config" 
modifying entry "olcDatabase = {2}hdb,cn=config" 
modifying entry "olcDatabase = {2}hdb,cn=config" 
[root@localhost cn=config]#
让我们检查修改后的 LDAP 配置。
root@linux1 ~]# vi /etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif
[root@centos]# cat /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}hdb.ldif
 # AUTO-GENERATED FILE-do NOT EDIT!! Use ldapmodify. 
 # CRC32 a163f14c
dn: olcDatabase = {2}hdb
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb
olcDbDirectory: /var/lib/ldap
olcDbIndex: objectclass eq,pres
olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
structuralObjectClass: olcHdbConfig
entryUUID: 1bd9aa2a-8516-1036-934b-f7eac1189139
creatorsName: cn=config
createTimestamp: 20170212022422Z
olcSuffix: dc=vmnet,dc=local
olcRootDN: cn=ldapadm,dc=vmnet,dc=local
olcRootPW:: e1NTSEF1bUVyb1VzZTRjc2dkYVdGaDY0T0k = 
entryCSN: 20170215204423.726622Z#000000#000#000000 
modifiersName: gidNumber = 0+uidNumber = 0,cn=peercred,cn=external,cn=auth
modifyTimestamp: 20170215204423Z
[root@centos]#
如您所见,我们的 LDAP 企业修改成功。
接下来,我们要为 OpenLDAP 创建一个自签名 ssl 证书。这将确保企业服务器和客户端之间的通信安全。
第 2 步-为 OpenLDAP 创建自签名证书。
我们将使用 openssl 创建自签名 ssl 证书。转到下一章, 使用 openssl 创建 LDAP SSL 证书,了解如何保护与 OpenLDAP 的通信。然后配置ssl证书后,我们就完成了我们的OpenLDAP企业配置。
第 3 步-配置 OpenLDAP 以使用带证书的安全通信。
使用以下信息在 vim 中创建一个 certs.ldif 文件-
dn: cn=config
changetype: modify
replace: olcTLSCertificateFile
olcTLSCertificateFile: /etc/openldap/certs/yourGeneratedCertFile.pem
dn: cn=config
changetype: modify
replace: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/openldap/certs/youGeneratedKeyFile.pem
接下来,再次使用 ldapmodify 命令将更改合并到 OpenLDAP 配置中。
[root@centos rdc]# ldapmodify-Y EXTERNAL -H ldapi:///-f certs.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber = 0+uidNumber = 0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "cn=config"
[root@centos]#
最后,让我们测试我们的 OpenLADP 配置。
[root@centos]# slaptest-u 
config file testing succeeded 
[root@centos]#
第 4 步-设置 slapd 数据库。
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG && 
chown ldap:ldap /var/lib/ldap/*
更新 OpenLDAP 架构。
添加余弦和 nis 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
最后,创建企业架构并将其添加到当前的 OpenLDAP 配置中。
以下是一个名为 vmnet. local 的域和一个名为 ldapadm 的 LDAP 管理员。
dn: dc=vmnet,dc=local
dc: vmnet
objectClass: top
objectClass: domain
dn: cn=ldapadm ,dc=vmnet,dc=local
objectClass: organizationalRole
cn: ldapadm
description: LDAP Manager
dn: ou = People,dc=vmnet,dc=local
objectClass: organizationalUnit
ou: People
dn: ou = Group,dc=vmnet,dc=local 
objectClass: organizationalUnit 
ou: Group
最后,将其导入到当前的 OpenLDAP 架构中。
[root@centos]# ldapadd-x-W-D "cn=ldapadm,dc=vmnet,dc=local"-f ./base.ldif
 Enter LDAP Password:
adding new entry "dc=vmnet,dc=local"
adding new entry "cn=ldapadm ,dc=vmnet,dc=local"
adding new entry "ou=People,dc=vmnet,dc=local"
adding new entry "ou=Group,dc=vmnet,dc=local"
[root@centos]#
第 5 步-设置 OpenLDAP 企业用户。
打开 vim 或您喜欢的文本编辑器并复制以下格式。这是为"vmnet.local"LDAP 域上名为"entacct"的用户设置的。
dn: uid=entacct,ou=People,dc=vmnet,dc=local 
objectClass: top
objectClass: account 
objectClass: posixAccount 
objectClass: shadowAccount 
cn: entacct 
uid: entacct 
uidNumber: 9999 
gidNumber: 100 
homeDirectory: /home/enyacct 
loginShell: /bin/bash 
gecos: Enterprise User Account 001 
userPassword: {crypt}x 
shadowLastChange: 17058 
shadowMin: 0 
shadowMax: 99999 
shadowWarning: 7
现在将保存的上述文件导入到 OpenLdap 架构中。
[root@centos]# ldapadd-x-W-D "cn=ldapadm,dc=vmnet,dc=local"-f entuser.ldif 
 Enter LDAP Password:
adding new entry "uid=entacct,ou=People,dc=vmnet,dc=local" 
[root@centos]#
在用户可以访问 LDAP Enterprise 之前,我们需要按如下方式分配密码-
ldappasswd-s password123-W-D "cn=ldapadm,dc=entacct,dc=local"-x "uid=entacct 
,ou=People,dc=vmnet,dc=local"
-s 指定用户密码
-x 是应用更新密码的用户名
-D 是针对 LDAP 架构进行身份验证的*专有名称。
最后,在登录企业帐户之前,让我们检查一下我们的 OpenLDAP 条目。
[root@centos rdc]# ldapsearch-x cn=entacct-b dc=vmnet,dc=local
 # extended LDIF
 #
 # LDAPv3
 # base <dc=vmnet,dc=local> with scope subtree
 # filter: cn=entacct
 # requesting: ALL 
 # 
 # entacct, People, vmnet.local 
dn: uid=entacct,ou=People,dc=vmnet,dc=local 
objectClass: top 
objectClass: account 
objectClass: posixAccount 
objectClass: shadowAccount 
cn: entacct 
uid: entacct 
uidNumber: 9999 
gidNumber: 100 
homeDirectory: /home/enyacct 
loginShell: /bin/bash 
gecos: Enterprise User Account 001 
userPassword:: e2NyeXB0fXg= 
shadowLastChange: 17058 
shadowMin: 0 
shadowMax: 99999 
shadowWarning: 7
/etc/passwd/etc/groups 之类的内容转换为OpenLDAP 身份验证需要使用迁移工具。这些都包含在 migrationtools 包中。然后,安装到 /usr/share/migrationtools
[root@centos openldap-servers]# ls-l /usr/share/migrationtools/
total 128
-rwxr-xr-x. 1 root root  2652 Jun  9  2014 migrate_aliases.pl
-rwxr-xr-x. 1 root root  2950 Jun  9  2014 migrate_all_netinfo_offline.sh
-rwxr-xr-x. 1 root root  2946 Jun  9  2014 migrate_all_netinfo_online.sh
-rwxr-xr-x. 1 root root  3011 Jun  9  2014 migrate_all_nis_offline.sh
-rwxr-xr-x. 1 root root  3006 Jun  9  2014 migrate_all_nis_online.sh
-rwxr-xr-x. 1 root root  3164 Jun  9  2014 migrate_all_nisplus_offline.sh
-rwxr-xr-x. 1 root root  3146 Jun  9  2014 migrate_all_nisplus_online.sh
-rwxr-xr-x. 1 root root  5267 Jun  9  2014 migrate_all_offline.sh
-rwxr-xr-x. 1 root root  7468 Jun  9  2014 migrate_all_online.sh
-rwxr-xr-x. 1 root root  3278 Jun  9  2014 migrate_automount.pl
-rwxr-xr-x. 1 root root  2608 Jun  9  2014 migrate_base.pl
第 6 步-最后,我们需要允许访问 slapd 服务,以便它可以为请求提供服务。
firewall-cmd--permanent--add-service=ldap 
firewall-cmd--reload

配置 LDAP 客户端访问

在客户端上配置 LDAP 客户端访问需要以下包:openldap、open-ldap 客户端和 nss_ldap。
为客户端系统配置 LDAP 身份验证要容易一些。
第 1 步-安装依赖包-
# yum install-y openldap-clients nss-pam-ldapd
第 2 步-使用 authconfig 配置 LDAP 身份验证。
authconfig--enableldap--enableldapauth--ldapserver=10.25.0.1--
ldapbasedn="dc=vmnet,dc=local"--enablemkhomedir--update
第 3 步-重新启动 nslcd 服务。
systemctl restart  nslcd
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4