现在试试安装 LDAP (openLDAP)。

1. 软件安装:

Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. yum -y install openldap openldap-clients openldap-servers nss_ldap samba samba-client openssl mod_ssl php-ldap php-pdo php-cli php-common perl-LDAP smbldap-tools perl-Digest-SHA1 perl-Digest-SHA perl-Unicode-String perl-Unicode-Map8 perl-Unicode-Map perl-Unicode-MapUTF8 perl-Jcode  



这里安装的软件挺多的,把这一行逐个字母敲进去,显然很不合理。我一般的做法是,把这些语句,特别是网上资料有现成的命令,复制粘贴到 Notepad++ 上,保存为 sh 文件,然后用 psftp 上传到 /bin, 再运行。

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_04


CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_05

安装的软件有 38MB大小。

2. 配置 openldap

先备份配置文件:
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # cp /etc/ldap.conf /etc/ldap.conf.orig  

  2. # cp /etc/nsswitch.conf /etc/nsswitch.conf.orig  

  3. # cp -R /etc/openldap /etc/openldap.orig  



(1)修改 slapd.conf

# nano /etc/openldap/slapd.conf

我安装的时候设定 Centos 机器的主机名是: server1.example.com 这里就按照这个域名来配置:

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_09

先保存和退出。

(2)生成 rootpw

输入命令
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. #/usr/sbin/slappasswd  


按提示输入我自己的密码 2次,就会产生一串字符:

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_13

用笔把这串字符记下来吧,呵呵。我是在 putty 操作的,可以简单一点,用鼠标选定这串字符,然后打开 slapd.conf

# nano /etc/openldap/slapd.conf

找到 rootpw 那一行,回车,然后,点一下鼠标右键,刚才那串字符就粘贴上去了。然后,在字符串前加上 rootpw

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_14

保存,退出。

(3)生成 DB_CONFIG

Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG  



然后授予拥有权 ownership
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # chown -R ldap:ldap /var/lib/ldap  

  2. # chmod 700 /var/lib/ldap  



(4)设置开机启动

Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # chkconfig --levels 235 ldap on  



现在启动:
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. /etc/init.d/ldap start  



CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_27


3. 添加记录

(1)初始化记录文件
用 Notepad++ 编辑一个 rootinit.ldif 文件,内容如下:
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. dn: dc=example,dc=com

  2. dc: example  

  3. o: example.com  

  4. description: Root LDAP entry for example.com  

  5. objectClass: top  

  6. objectClass: dcObject  

  7. objectClass: organization  



保存,退出。

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_31

(2)ou 记录文件
用 Notepad++ 编辑一个 ou1.ldif 文件,内容如下:
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. dn: ou=People,dc=example,dc=com

  2. ou: People  

  3. objectClass: organizationalUnit  


  4. dn: ou=Groups,dc=example,dc=com

  5. ou: Groups  

  6. objectClass: organizationalUnit  


  7. dn: ou=Hosts,dc=example,dc=com

  8. ou: Hosts  

  9. description: All hosts in example.com  

  10. objectClass: organizationalUnit  



保存,退出。

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_35


(3)在Centos机器建一个临时文件夹
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # mkdir /home/tmp  



(4)上传 ldif 文件

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_39

(5)导入
使用 ldapadd 导入 ldif 文件:

Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f  /home/tmp/rootinit.ldif  

  2. # ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f  /home/tmp/ou1.ldif  



CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_43

(6)查看已有记录

Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # ldapsearch -x -b 'dc=example,dc=com'  



CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_47

4. 清空(删除)记录

清空已输入的记录是初学者肯定遇到的。我在添加记录过程中,多次出现错误,所以在网上找删除已有记录的办法,呵呵,删除多次添加多次,才大概有点经验。

(1)先停止 ldap
(2)删除 /var/lib/ldap 下的文件,但保留 DB_CONFIG 文件。如果该目录下文件全部删除了,需要在复制一份 DB_CONFIG 到目录。
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG  


(3)该目录授权到 ldap
(4)重启 ldap

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_51


5. 安装配置 phpldapadmin

(1)安装
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # yum -y install phpldapadmin  


(2)配置
其配置文件为 /usr/share/phpldapadmin/config/config.php
我没有修改,保留原来设定。

修改 /etc/httpd/conf.d/phpldapadmin.conf

# nano /etc/httpd/conf.d/phpldapadmin.conf

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_55

保存退出。然后重启 httpd:

Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # /etc/init.d/httpd restart  



(3)登录
现在在浏览器就可以打开 phpldapadmin

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_59


======================================================================

以上是一个配置过程,中间遇到许多问题,但最后也算完成基本配置。到晚上,在百度搜到多篇很好的中文教程,细细阅读,发现自己原来有很多模糊的理解,需要再尝试。

(1)先清空所有的输入
停止 ldap,删除 /var/lib/ldap 下文件仅保留 DB_CONFIG, 授权。
修改 /etc/openldap/slapd.conf 文件, 把 rootdn 改为:
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. rootdn "cn=root,dc=example,dc=com"  


保存后,重启 ldap。

(2)编辑几个 ldif 文件,文件名和内容如下:


CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_63

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_64

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_65

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_66

然后用 psftp 上传到 /home/tmp。

用 ldapadd 逐个导入这些 ldif 文件:

Html代码
  1. # ldapadd -x -D "cn=root,dc=example,dc=com" -W -f /home/tmp/init1.ldif  


Html代码
  1. # ldapadd -x -D "cn=root,dc=example,dc=com" -W -f /homr/tmp/ou1.ldif  


Html代码
  1. # ldapadd -x -D "cn=root,dc=example,dc=com" -W -f /home/tmp/wgroup1.ldif  


Html代码
  1. # ldapadd -x -D "cn=root,dc=example,dc=com" -W -f /home/tmp/user1.ldif  



用 ldapsearch 查看已有的输入:

Html代码
  1. # ldapsearch -x -b "dc=example,dc=com"  



(3)修改 单个用户密码

修改用户 John 的密码:
Html代码
  1. # ldappasswd -x -D "cn=root,dc=example,dc=com" -W "uid=John,ou=People,dc=example,dc=com" -S  

  2. New password:  

  3. Re-enter new password:  

  4. Enter LDAP Password:  


New password 和 Re-enter new password 就是输入2次 John 的新密码,而 Enter LDAP Password 则输入 LDAP 的系统密码,就是我们前面用 slappasswd 所建立的密码。

修改用户 ldapadmin 的密码:
Html代码 CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _CentOS 5.5_02
  1. # ldappasswd -x -D "cn=root,dc=example,dc=com" -W "uid=ldapadmin,ou=People,dc=example,dc=com" -S  

  2. New password:  

  3. Re-enter new password:  

  4. Enter LDAP Password:  



完成后,# ldapsearch -x -b "dc=example,dc=com" 查看一下,就发现 用户的密码已经改变:

CentOS 5.5 安装记录 - (7) LDAP安装和基本配置 _LDAP安装_76





======================================================================

参考资料:

Html代码
  1. http://blog.javachap.com/index.php/installing-openldap-on-centos/  


Html代码
  1. http://www.syntaxtechnology.com/2010/05/openldap-on-centos-5-4-part-4-the-data/  


Html代码
  1. http://www.howtoforge.com/ldap-user-authentication-on-centos-5.x  


Html代码
  1. http://www.productionmonkeys.net/guides/ldap-server/openldap-installation  


Html代码
  1. http://www.syntaxtechnology.com/2010/05/openldap-on-centos-5-4-part-4-the-data/  


Html代码
  1. http://www.server-world.info/en/note?os=CentOS_5&p=ldap



很详细的中文 openLDAP 配置教程
Html代码
  1. http://zhumeng8337797.blog.163.com/blog/#m=0

转载自:http://kingsz1.iteye.com/blog/842406