Centos 7 安装及配置LDAP

基本概念

Required

  • CentOS 7.2
  • OpenSSL 1.0.1e-fips 11 Feb 2013
LDIF ldap信息交换格式,用于ldap数据输入标准格式

准备工作

关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state

安装LDAP

安装LDAP
yum install openldap openldap-servers openldap-clients -y
启动LDAP

如果启动失败使用journalctl -xe可以看到详细的错误信息,以此来排错

systemctl enable slapd
systemctl start slapd 
systemctl status slapd

配置LDAP

拷贝数据库信息
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap /var/lib/ldap/DB_CONFIG
获取加密密码

slappasswd 命令获取加密密码,将加密后的密码填入olcRootPW中,vim rootpwd.ldif

dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}vXhzPBpWs1voey0ijKyI0Uc39fo4xy1O
修改管理员密码
ldapadd -Y EXTERNAL -H ldapi:/// -f rootpwd.ldif
导入LDAP Schema

导入schema目地是为后要使用的Attribute做准备

ls /etc/openldap/schema/*.ldif | while read f; do ldapadd -Y EXTERNAL -H ldapi:/// -f $f; done
设定默认域

使用ldappasswd生成密码,以备后面olcRootPW使用,这块密码需要与第一次配置密码一致,vim defaultDomain.ldif将下面内容写入ldif文件中;
下面内容中的xxx,xx需要替换成真实的域;
执行ldapmodify -Y EXTERNAL -H ldapi:/// -f defaultDomain.ldif文件;

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=xxx,dc=xx" read by * none

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=xxx,dc=xx

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=xxx,dc=xx


dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}gvWUgKDc395f1uCBStUX3mj78JKTRqrWxxx # 填写上面生成密码


dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
  dn="cn=Manager,dc=xxx,dc=xx" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=xxx,dc=xx" write by * read

添加basedomain.ldif文件,文件中的xxx,xx需要使用真实域进行替换,这块内容需要你花点时间读一下objectClass;
ldapadd -x -D cn=Manager,dc=zhidaoauto,dc=com -W -f basedomain.ldif

dn: dc=xxx,dc=xx
objectClass: top
objectClass: dcObject
objectclass: organization
o: xxx xx
dc: xxx

dn: cn=Manager,dc=xxx,dc=xx
objectClass: organizationalRole
cn: Manager
description: Directory Manager

dn: ou=People,dc=xxx,dc=xx
objectClass: organizationalUnit
ou: People

dn: ou=Group,dc=xxx,dc=xx
objectClass: organizationalUnit
ou: Group
查询dn

执行命令时需要输入密码,这边的密码为上面你生成的管理员密码

ldapsearch -LLL -W -x -D "cn=Manager,dc=xxx,dc=xx" -H ldap://localhost -b "dc=xxx,dc=xx"
添加用户信息

ldapadd -x -D 'cn=Manager,dc=mucang,dc=cn' -f adduser.ldif -H ldap:/// -W
注意objectClass需要添加加inetOrgPerson这样才能添加用户邮箱电话等信息,你可通过上面查询的结果看到ou信息

dn: uid=xxx,ou=People,dc=mucang,dc=cn
ou: People
uid: xxx
sn: xxx
cn: xxxx
givenName: xxx
displayName: 某人
mail: xxx@mucang.cn
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
userpassword: xxx###
LDAP结构图

在这里插入图片描述

问题

执行命令时密码输入正确还提示49信息时,这时你重新安装ldap后就会恢复正常

yum reinstall openldap openldap-servers openldap-clients -y

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值