open LDAP 在线安装和配置-基于centos 7

安装openldap

注意:centos7中用yum安装的已是最新的openldap2.4的版本,默认配置方式是slapd(8) ,没有slapd.conf文件,若采取slapd.conf(5)方式需要新建该文件。

1、检查是否已经安装:rpm -qa openldap-servers

2、需要安装的包

  • 必须
    • openldap-servers
    • openldap-clients(包含LDAP增、删、改、查等命令)
  • 可选
    • openldap-devel

3、安装:yum -y install [包名]

4、启停:systemctl start/stop/status slapd(利用slapd.ldif更改配置后将不再起作用),可以用slapd命令

5、验证:ldapsearch -x -b ' ' -s base '(objectclass=*)',ldapserach --help可查看帮助

6、目录位置(默认安装)

  • 数据保存:/var/lib/ldap
  • 配置文件:/etc/openldap/
  • 守护进程:/usr/sbin/slapd

7、生成密文密码:slappaswd

请复制该密文,配置中使用。当然也可忽略此步。


配置openLDAP

两个主要配置目录

  • 默认配置文件所在目录:/usr/share/openldap-servers/
  • 配置文件目录:/etc/openldap/,其中,主要配置文件在slapd.d目录下

方式一

  • 法1:采用slapd(8)方式,直接编辑/etc/openldap/slapd.d/olcDatabase={2}hdb.ldif(官方未提及,网友倒是乐此不疲),此处亦不作详解。
  • 法2:通过ldif文件生成,详情参考:http://www.openldap.org/doc/admin24/slapdconf2.html
    1. 编辑slapd.ldif
    2. 利用命令:slapadd -v -F /etc/openldap/slapd.d/ -l slapd.ldif -n 0生成配置
    3. 启动:slapd -F slapd.d

方式二

采用slapd.conf(5)方式

1、新建slapd.conf文件,以下示例是一份最简单的配置,详情参考:http://www.openldap.org/doc/admin24/slapdconfig.html

 1 # Schema and objectClass definitions
 2 include         /etc/openldap/schema/core.schema
 3 include         /etc/openldap/schema/cosine.schema
 4 include         /etc/openldap/schema/nis.schema
 5 include         /etc/openldap/schema/inetorgperson.schema
 6 include         /etc/openldap/schema/openldap.schema
 7 
 8 # Where the pid file is put. The init.d script
 9 # will not stop the server if you change this.
10 pidfile         /var/run/openldap/slapd.pid
11 
12 # List of arguments that were passed to the server
13 argsfile        /var/run/openldap/slapd.args
14 
15 # Specific Directives for database #1, of type @BACKEND@:
16 # Database specific directives apply to this databasse until another
17 # 'database' directive occurs
18 database        mdb
19 
20 # The base of your directory in database #1
21 suffix          "dc=test,dc=com"
22 
23 # rootdn directive for specifying a superuser on the database. This is needed
24 # for syncrepl.
25 rootdn          "cn=root,dc=test,dc=com"
26 
27 #此处便是前面的slappasswd生成的,当然你也可以用明文
28 rootpw          {SSHA}kQSPnfgc8Va+IDh2saHfZ1F7rzN8mRvn
29 
30 # Where the database file are physically stored for database #1
31 directory       "/var/lib/ldap"
32 
33 # Indexing options for database #1
34 index            objectClass eq
View Code

2、检查配置:slaptest -u -f slapd.cong,若有错误,请根据提示更改错误

3、启动:slap -f slapd.conf(此处需要在slapd.conf目录下,否则需要加入slapd.conf的绝对位置)

4、初始化根entry

  • 新建文件initRootEntry.ldif
    1 dn: dc=test,dc=com
    2 objectClass: dcObject
    3 objectClass: organization
    4 o: this is test
    5 dc: test
    View Code
  • 利用命令:ldapadd -x -D "cn=root,dc=test,dc=com" -W -f initRootEntry.ldif导入根entry信息

5、大功告成,继续深究

一些LDAP服务的管理软件


 

posted @ 2018-09-26 10:58  刘笙  阅读(2045)  评论(2编辑  收藏  举报