CentOS 7 部署OpenLDAP服务

OpenLDAP 是一款轻量级目录访问协议(Lightweight Directory Access Protocol,LDAP),属于开源集中账号管理架构的实现,且支持众多系统版本,被广大互联网公司所采用。

安装ldap服务

[root@ldap ~]# yum install -y openldap-servers openldap-clients
[root@ldap ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
[root@ldap ~]# chown ldap. /var/lib/ldap/DB_CONFIG
[root@ldap ~]# systemctl start slapd
[root@ldap ~]# systemctl enable slapd

配置ldap服务

# 生成管理员密码

[root@ldap ~]# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[root@ldap ~]# vim chrootpw.ldif# specify the password generated above for "olcRootPW" section
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[root@ldap ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={0}config,cn=config"

导入基本模式

[root@ldap ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=cosine,cn=schema,cn=config"
[root@ldap ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=nis,cn=schema,cn=config"
[root@ldap ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=inetorgperson,cn=schema,cn=config"

在ldap的DB中设置域名

# 生成目录管理员密码

[root@ldap ~]# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[root@ldap ~]# vim chdomain.ldif# replace to your own domain name for "dc=***,dc=***" section# specify the password generated above for "olcRootPW" section
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=jumpserver,dc=tk" read by * none
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=jumpserver,dc=tk
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=jumpserver,dc=tk
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
dn="cn=Manager,dc=jumpserver,dc=tk" write by anonymous auth by self write by *
none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=jumpserver,dc=tk" write by * read


[root@ldap ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={1}monitor,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"


[root@ldap ~]# vim basedomain.ldif# replace to your own domain name for "dc=***,dc=***" section
dn: dc=jumpserver,dc=tk
objectClass: top
objectClass: dcObject
objectclass: organization
o: Server tk
dc: jumpserver
dn: cn=Manager,dc=jumpserver,dc=tk
objectClass: organizationalRole
cn: Manager
description: Directory Manager
dn: ou=People,dc=jumpserver,dc=tk
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=jumpserver,dc=tk
objectClass: organizationalUnit
ou: Group


[root@ldap ~]# ldapadd -x -D cn=Manager,dc=jumpserver,dc=tk -W -f basedomain.ldif
Enter LDAP Password: # 输入目录管理员密码
adding new entry "dc=jumpserver,dc=tk"
adding new entry "cn=Manager,dc=jumpserver,dc=tk"
adding new entry "ou=People,dc=jumpserver,dc=tk"
adding new entry "ou=Group,dc=jumpserver,dc=tk"

开放端口

# firewall-cmd --add-service=ldap --permanent
success
# firewall-cmd --reload
success

添加一个用户

# 生成用户密码

[root@ldap ~]# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxx
[root@ldap ~]# vi ldapuser.ldif# create new# replace to your own domain name for "dc=***,dc=***" section
dn: uid=test,ou=People,dc=jumpserver,dc=tk
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: test
sn: Linux
userPassword: {SSHA}xxxxxxxxxxxxxxxxx
loginShell: /bin/bash
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/test
dn: cn=test,ou=Group,dc=jumpserver,dc=tk
objectClass: posixGroup
cn: test
gidNumber: 1000
memberUid: test


[root@ldap ~]# ldapadd -x -D cn=Manager,dc=jumpserver,dc=tk -W -f ldapuser.ldif
Enter LDAP Password:
adding new entry "uid=test,ou=People,dc=jumpserver,dc=tk"
adding new entry "cn=test,ou=Group,dc=jumpserver,dc=tk"
[root@ldap ~]# ldapsearch -x -D "cn=Manager,dc=jumpserver,dc=tk" -W -b ""dc=jumpserver,dc=tk"

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/220378.html<

(0)
管理的头像管理
上一篇2025-04-14 13:18
下一篇 2025-04-14 13:20

相关推荐

  • GEO友好的服务器标准有哪些,如何判断?

    SEO友好的服务器,核心标准是速度、稳定性、IP纯净度、安全合规以及服务商资质,缺一不可, 选择服务器不能只看配置,更要关注机房基础设施、网络质量、IP信誉以及服务商是否持牌经营,符合这些条件的服务器,才能让百度爬虫顺利抓取、用户获得良好体验,从而稳定提升排名,速度:服务器响应时间与硬件配置百度最新的核心算法中……

    2026-07-26
    0
  • 机房T3等级是什么意思?,T3机房等级标准有哪些?

    机房T3等级,代表数据中心具备并行维护能力和N+1冗余架构,可用性达到99.982%级别,是当前企业托管业务的主流选择,什么是机房T3等级?核心定义与行业标准机房T3等级源自Uptime Institute的数据中心分级标准,也对应TIA-942的Rating 3等级,这个等级的核心特征就是可并行维护——在任意……

    2026-07-26
    0
  • 服务器SLA服务协议是什么有什么用,有哪些注意事项?

    服务器SLA服务协议是服务商与用户之间关于服务可用性、性能等方面的正式承诺,它直接决定了业务稳定性和运维成本,什么是服务器SLA服务协议服务器SLA(Service Level Agreement)是服务等级协议的缩写,在IDC和云服务领域,它是一份具有法律效力的合同附件,明确服务商必须提供的服务水平基准,这份……

    2026-07-26
    0
  • 站群服务器泛站和泛目录有什么区别?,怎么选

    泛站基于多个独立域名构建独立站点,泛目录则在同一域名下通过目录结构构建内容,这直接影响SEO权重分配和资源管理,什么是泛站和泛目录泛站模式泛站模式使用多个独立域名,每个域名部署独立网站,内容互不关联,这种结构下,每个站点各自积累SEO权重,适合需要大量外链或分散风险的场景,推广不同产品时,泛站能避免单一站点被处……

    2026-07-26
    0
  • 服务器防火墙硬件和软件哪个效果更好,怎么选

    在服务器防火墙的选型中,硬件防火墙与软件防火墙并非非此即彼,而是互补关系,对于追求高安全等级与稳定性的生产环境,采用硬件防火墙做网络层隔离,配合软件防火墙做主机层加固,是当前公认效果最好的组合方案,硬件防火墙与软件防火墙的核心差异性能与资源占用硬件防火墙依托专用ASIC芯片或FPGA处理数据包,转发延迟通常在微……

    2026-07-26
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注