安装ldap全流程

备注:若大家只是想直接装完这个,理论部分不需要看,直接走安装步骤123等就可以了,可以装完之后再回过头来理解理解;

 

注意,不同linux操作系统版本之间的差异很大,我用的是centos7;

其实啊,openldap的安装真的是非常简单,直接用yum装一个server端和client端,然后启动服务就OK了。难的是修改它的配置文件以及导入我们需要的shema(这个其实理解了它的概念也就不难了)。

安装步骤1.yum 安装

#!/bin/bash 

echo "install ldap rpm" 

[root@dlp ~]yum install -y openldap-servers openldap-clients

[root@dlp ~]cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

[root@dlp ~]chown ldap. /var/lib/ldap/DB_CONFIG

systemctl start slapd

systemctl enable slapd

安装步骤2.修改原始配置

# generate encrypted password 

[root@dlp ~]# slappasswd

New password:

Re-enter new password: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx

[root@dlp ~]# vi chrootpw.ldif 

# specify the password generated above for "olcRootPW" section dn:

olcDatabase={0}config,cn=config

changetype: modify

add: olcRootPW

olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx

[root@dlp ~]# 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"

 

理论: backend & database

参考:https://segmentfault.com/a/1190000002607140

ldap的后台进程slapd接收、响应请求,但实际存储数据、获取数据的操作是由Backends做的,而数据是存放在database中,所以你可以看到往往你可以看到backenddatabase指令是一样的值如 bdb 。一个 backend 可以有多个 database instance,但每个 database 的 suffix 和 rootdn 不一样。openldap 2.4版本的模块是动态加载的,所以在使用backend时需要moduleload back_bdb指令。

bdb是一个高性能的支持事务和故障恢复的数据库后端,可以满足绝大部分需求。许多旧文档里(包括官方)说建议将bdb作为首选后端服务(primary backend),但2.4版文档明确说hdb才是被首先推荐使用的,这从 2.4.40 版默认安装后的配置文件里也可以看出。hdb是基于bdb的,但是它通过扩展的索引和缓存技术可以加快数据访问,修改entries会更有效率,有兴趣可以访问上的链接或slapd.backends

另外config是特殊的backend,用来在运行时管理slapd的配置,它只能有一个实例,甚至无需显式在slapd.conf中配置。

原始配置都存放在/etc/openldap/slapd.d/cn=config下,

这里面有这么几个文件:cn=schema文件夹、olcDatabase={0}config.ldif、olcDatabase={1}monitor.ldif(监控)、olcDatabase={2}hdb.ldif(数据库)、olcDatabase={-1}frontend.ldif;

前面带个{},应该是约定好的规则;其中cn=schema文件夹中存放的是我们导入的schema;剩下的几个都是配置文件,其中我们可以直接修改olcDatabase={0}config.ldif的密码;我们修改域名时需要修改olcDatabase={1}monitor.ldif、olcDatabase={2}hdb.ldif、文件;

我们有两种方式来修改默认的example配置,一是直接在配置文件中修改(不建议),另一个是调用客户端的命令进行修改;我这儿介绍第二种

修改(要注意空行或者是空格)

安装步骤4.修改域名

# generate directory manager's password 

[root@dlp ~]# slappasswd

New password:

Re-enter new password: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx

[root@dlp ~]# vi 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=srv,dc=world" read by * none

 

dn: olcDatabase={2}hdb,cn=config

changetype: modify

replace: olcSuffix

olcSuffix: dc=srv,dc=world

 

dn: olcDatabase={2}hdb,cn=config

changetype: modify

replace: olcRootDN

olcRootDN: cn=Manager,dc=srv,dc=world

 

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=srv,dc=world" write by anonymous auth by self write by * none olcAccess: {1}to dn.base="" by * read

olcAccess: {2}to * by dn="cn=Manager,dc=srv,dc=world" write by * read

 

[root@dlp ~]# 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" 

理论:同步骤3

 

这些文件或文件夹的命令都有点儿奇怪,但你要是理解ldap本身的规则,就见怪不怪了

安装步骤5.开放端口:

# systemctl stop firewalld

 # systemctl disable firewalld

 # setenforce 0

安装步骤6.添加用户

现在我们就可以添加用户了

# generate encrypted password

 [root@dlp ~]# slappasswd

New password:

Re-enter new password:

{SSHA}xxxxxxxxxxxxxxxxx

 

[root@dlp ~]# vi ldapuser.ldif 

# create new # replace to your own domain name for "dc=***,dc=***" section 

dn:uid=cent,ou=People,dc=srv,dc=world

objectClass: inetOrgPerson

objectClass: posixAccount

objectClass: shadowAccount

cn: Cent

sn: Linux

userPassword: {SSHA}xxxxxxxxxxxxxxxxx

loginShell: /bin/bash

uidNumber: 1000 

gidNumber: 1000 

homeDirectory: /home/cent

 

dn: cn=cent,ou=Group,dc=srv,dc=world

objectClass: posixGroup

cn: Cent

gidNumber: 1000 

memberUid: cent

 

[root@dlp ~]# ldapadd -x -D cn=Manager,dc=srv,dc=world -W -f ldapuser.ldif

Enter LDAP Password:

adding new entry "uid=cent,ou=People,dc=srv,dc=world" 

adding new entry "cn=cent,ou=Group,dc=srv,dc=world"

安装步骤7.客户端连接

配置完我们可以直接用客户端连接,比如:Apache DirectoryldapadministartorldapBrowser等客户端工具,大家可以自己下载

 

 

 

常用命令:ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif 

ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif (注意需要在修改的条目第二行添加changetypemodify

dn: olcDatabase={2}hdb,cn=config

changetype: modify

replace: olcSuffix

olcSuffix: dc=srv,dc=world

 

不管是修改系统文件,亦或是引入模式都可以使用该命令

添加一般用户:ldapadd -x -D cn=Manager,dc=srv,dc=world -W -f ldapuser.ldif

修改应该也是这样

 

路径:ldap//192.168.101.89/dc=srv,dc=world

操作命令:http://blog.csdn.net/lucifer821031/article/details/1920814

参考:http://blog.csdn.net/wenwenxiong/article/details/76855047#comments

https://jingyan.baidu.com/article/1709ad80616d864634c4f0b7.html 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值