CentOS部署OpenLDAP認證之 Server

一些基本概念
Server的安裝與配置
Web管理工具phpldapadmin
Clients的安裝與配置
生產環境使用OpenLDAP做認證(主備、Server安全、TLS)
 

一、基本概念
DN、OU、DC、O,這些概念網上都有資料。
一般用來做用戶認證,我是拿來做系統用戶認證,很多人做FTP或Samba用戶認證。
 
二、Server端的安裝與配置
openldap這玩意對細節的要求非常苛刻,稍不注意就會報錯。
參考:http://www.server-world.info/en/note?os=CentOS_6&p=ldap&f=1
         http://www.openldap.org/doc/admin24/
 
SERVER端,操作系統:CentOS 6.2:
I、OpenLDAP的安裝與基本配置
1)Yum安裝
 
  1. yum -y install openldap openldap-servers openldap-clients openldap-devel  //一定要全安裝,否則後面可能會報錯 
2)vi /etc/sysconfig/ldap,確保SLAPD_LDAPI=yes
3)vi /etc/openldap/slapd.conf,添加如下兩行:
  1. pidfile /var/run/openldap/slapd.pid  
  2. argsfile /var/run/openldap/slapd.args 
4)備份/etc/openldap/slapd.d目錄,然後重建該目錄,並生成文件:
  1. cp -a /etc/openldap/slapd.d /etc/openldap/slapd.d.BAK2012-03-26  
  2. rm -rf /etc/openldap/slapd.d/*  
  3. slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d 
5)編輯重新生成後的配置文件:
   a) vi /etc/openldap/slapd.d/cn=config/olcDatabase\=\{0\}config.ldif,修改第4行配置如下:
  1. olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break 
   注意嚴格按照原文件單詞之間的空格數進行修改,by前面有兩個空格
   b) vi /etc/openldap/slapd.d/cn=config/olcDatabase\=\{1\}monitor.ldif,輸入以下行:
  1. dn: olcDatabase={1}monitor  
  2. objectClass: olcDatabaseConfig  
  3. olcDatabase: {1}monitor  
  4. olcAccess: {1}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break  
  5. olcAddContentAcl: FALSE  
  6. olcLastMod: TRUE  
  7. olcMaxDerefDepth: 15  
  8. olcReadOnly: FALSE  
  9. olcMonitoring: FALSE  
  10. structuralObjectClass: olcDatabaseConfig  
  11. creatorsName: cn=config 
  12. modifiersName: cn=config 
注:以上所有輸入行,確保行首無空格。 
6)修改slapd.d目錄的屬主和權限,並啓動ldap:
  1. chown -R ldap. /etc/openldap/slapd.d  
  2. chmod -R 700 /etc/openldap/slapd.d  
  3. /etc/rc.d/init.d/slapd start  
  4. chkconfig slapd on 
 
II、初始化用戶認證信息
1)依次輸入以下命令,並確保無報錯:
  1. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/core.ldif  
  2. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif  
  3. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif  
  4. ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif  
   最有可能出現的錯誤:no permission to create parent directory. 我遇到了幾次,沒辦法解決,最後是嚴格按照上面的步驟,重新安裝了一遍才OK。
2)創建管理員密碼,儘量使用高強度密碼:
slappasswd
注:a) 上述命令會生成一個經過SSHA算法加密的密碼,保存該密文,後面要用到
      b) slappasswd支持的加密算法,可使用man slappasswd查看
 
3)創建backend.ldif文件,輸入以下行:
  1. # replace the section "dc=***,dc=***" to your own suffix  
  2. # replace the section "olcRootPW: ***" to your own password generated by slappasswd above  
  3. dn: cn=module,cn=config 
  4. objectClass: olcModuleList  
  5. cn: module  
  6. olcModulepath: /usr/lib64/openldap  
  7. olcModuleload: back_hdb  
  8. dn: olcDatabase=hdb,cn=config 
  9. objectClass: olcDatabaseConfig  
  10. objectClass: olcHdbConfig  
  11. olcDatabase: {2}hdb  
  12. olcSuffix: dc=abc,dc=com 
  13. olcDbDirectory: /var/lib/ldap  
  14. olcRootDN: cn=root,dc=abc,dc=com 
  15. olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx  
  16. olcDbConfig: set_cachesize 0 2097152 0  
  17. olcDbConfig: set_lk_max_objects 1500  
  18. olcDbConfig: set_lk_max_locks 1500  
  19. olcDbConfig: set_lk_max_lockers 1500  
  20. olcDbIndex: objectClass eq  
  21. olcLastMod: TRUE  
  22. olcMonitoring: TRUE  
  23. olcDbCheckpoint: 512 30  
  24. olcAccess: to attrs=userPassword by dn="cn=root,dc=abc,dc=com" write by anonymous auth by self write by * no  
  25. ne  
  26. olcAccess: to attrs=shadowLastChange by self write by * read  
  27. olcAccess: to dn.base="" by * read  
  28. olcAccess: to * by dn="cn=root,dc=abc,dc=com" write by * read  
  然後執行如下命令:
  1. ldapadd -Y EXTERNAL -H ldapi:/// -f backend.ldif 
4)編輯frontend.ldif,並輸入以下行:
  1. # replace the section "dc=***,dc=***" to your own suffix  
  2. # replace the section "userPassword: ***" to your own password generated by slappasswd above  
  3. dn: dc=abc,dc=com 
  4. objectClass: top  
  5. objectClass: dcObject  
  6. objectclass: organization  
  7. o: abc com  
  8. dc: abc  
  9. dn: cn=root,dc=abc,dc=com 
  10. objectClass: simpleSecurityObject  
  11. objectClass: organizationalRole  
  12. cn: root  
  13. userPassword: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx  
  14. dn: ou=people,dc=abc,dc=com 
  15. objectClass: organizationalUnit  
  16. ou: people  
  17. dn: ou=groups,dc=abc,dc=com 
  18. objectClass: organizationalUnit  
  19. ou: groups 
  然後執行如下命令:
  1. ldapadd -x -D cn=root,dc=abc,dc=com -W -f frontend.ldif //注意替換自己的cn和dc
   最有可能出現的錯誤:ldap_bind: Invalid credentials (49)。檢查兩方面:上述命令中的cn和dc是否輸入正確,以及密碼是否輸入正確。
 
5) 如果忘記管理員密碼,或者想修改該密碼:
  1. ldappasswd -x -v -S -W -D cn=root,dc=abc,dc=com 
然後重啓openLDAP:/etc/init.d/slapd restart
 待續...
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章