写完这个文章有一阵了,合计下个月可以轮到这个文章记录发上来了,后来被群里(56479030)的童鞋们要看,只能提前发了。

原文地址http://kinggoo.com/openldapinstallconf.htm

微博@吐气喝水

系统信息

[root@kinggoo ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)
[root@kinggoo ~]# uname -a
Linux kinggoo.com 2.6.32-358.23.2.el6.i686 #1 SMP Wed Oct 16 17:21:31 UTC 2013 i686 i686 i386 GNU/Linux

安装openldap(2.4.23-32)

yum -y install openldap openldap-*

确认/etc/sysconfig/ldap的内容如下面默认一般不需要修改

[root@kinggoo openldap]# cat  /etc/sysconfig/ldap |grep -v -E "^$|^#"
SLAPD_LDAP=yes
SLAPD_LDAPI=yes
#未开启ssl
SLAPD_LDAPS=no

配置文件的操作

[root@kinggoo openldap]# cp -rf /etc/openldap/slapd.d /etc/openldap/slapd.d_`date +%Y%m%d`.bak
[root@kinggoo openldap]# rm -rf /etc/openldap/slapd.d/*
[root@kinggoo openldap]# touch /etc/openldap/slapd.conf
[root@kinggoo openldap]# echo -e "pidfile /var/run/openldap/slapd.pid\nargsfile /var/run/openldap/slapd.args" > /etc/openldap/slapd.conf
[root@kinggoo openldap]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
返回信息:config file testing succeeded

修改两个文件

[root@kinggoo openldap]# cd /etc/openldap/slapd.d/cn=config/
[root@kinggoo cn=config]# vim  olcDatabase\=\{0\}config.ldif
#注意需要修改第四行内的olcAccess: {0}to *  by * none改为如下信息(在星号后面的by前面应该是两个英文半角的空格)
olcAccess: {0}to *  by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break

新建一个ldif文件

[root@kinggoo cn=config]# touch /etc/openldap/slapd.d/cn=config/olcDatabase\=\{1\}monitor.ldif
#向其内添加如下信息,注意后面和前面不要有空格
[root@kinggoo cn=config]# cat olcDatabase\=\{1\}monitor.ldif
dn: olcDatabase={1}monitor
objectClass: olcDatabaseConfig
olcDatabase: {1}monitor
olcAccess: {1}to *  by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break
olcAddContentAcl: FALSE
olcLastMod: TRUE
olcMaxDerefDepth: 15
olcReadOnly: FALSE
olcMonitoring: FALSE
structuralObjectClass: olcDatabaseConfig
creatorsName: cn=config
modifiersName: cn=config

修改slapd.d目录的属主和权限,并启动ldap:

[root@kinggoo cn=config]# chown -R ldap.ldap /etc/openldap/slapd.d
[root@kinggoo cn=config]# chown -R ldap.ldap /var/lib/ldap
[root@kinggoo cn=config]# chmod -R 700 /etc/openldap/slapd.d
[root@kinggoo cn=config]# chkconfig --add slapd
[root@kinggoo cn=config]# chkconfig --level 345 slapd on
[root@kinggoo cn=config]# service slapd start
不报错就没什么问题,有问题的话估计就是你哪个地方执行错误了,重头看看

执行如下几条命令

依次会返回

ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/core.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=core,cn=schema,cn=config"
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=cosine,cn=schema,cn=config"
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=nis,cn=schema,cn=config"
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=inetorgperson,cn=schema,cn=config"

创建Openldap的管理员密码,使用slappasswd命令,会提示你输入密码的,记得把密码记住啊!!!!如我加密后的是
{SSHA}zr6Ixzs64yHpz0xHTq4PoSO1Wc6Qy9uA

好现在编辑backend.ldif文件,先是主配置的 就等于slapd.conf文件内容
你需要修改olcSuffix,olcRootDN,olcRootPW,olcAccess几个标签的地方

[root@kinggoo cn=config]# cat backend.ldif
# create new
# replace the section "dc=***,dc=***" to your own suffix
# replace the section "olcRootPW: ***" to your own password generated by slappasswd above
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib64/openldap
olcModuleload: back_hdb
dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb
olcSuffix: dc=kinggoo,dc=com
olcDbDirectory: /var/lib/ldap
olcRootDN: cn=admin,dc=kinggoo,dc=com
olcRootPW: {SSHA}zr6Ixzs64yHpz0xHTq4PoSO1Wc6Qy9uA
olcDbConfig: set_cachesize 0 2097152 0
olcDbConfig: set_lk_max_objects 1500
olcDbConfig: set_lk_max_locks 1500
olcDbConfig: set_lk_max_lockers 1500
olcDbIndex: objectClass eq
olcLastMod: TRUE
olcMonitoring: TRUE
olcDbCheckpoint: 512 30
olcAccess: to attrs=userPassword by dn="cn=admin,dc=kinggoo,dc=com" write by anonymous auth by self write by * none
olcAccess: to attrs=shadowLastChange by self write by * read
olcAccess: to dn.base="" by * read
olcAccess: to * by dn="cn=admin,dc=kinggoo,dc=com" write by * read

然后执行,并有返回

[root@kinggoo cn=config]# ldapadd -Y EXTERNAL -H ldapi:/// -f ./backend.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=module,cn=config"
adding new entry "olcDatabase=hdb,cn=config"

重启服务,然后看有没有警告,如果有那你最好是重新来过

然后在编辑文件

[root@kinggoo cn=config]# cat frontend.ldif
# 你需要修改dn:,userPassword几个标签的地方
# create new
# replace the section "dc=***,dc=***" to your own suffix
# replace the section "userPassword: ***" to your own password generated by slappasswd above
dn: dc=kinggoo,dc=com
objectClass: top
objectClass: dcObject
objectclass: organization
o: KingGoo com
dc: KingGoo
dn: cn=admin,dc=kinggoo,dc=com
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
userPassword: {SSHA}zr6Ixzs64yHpz0xHTq4PoSO1Wc6Qy9uA
dn: ou=people,dc=kinggoo,dc=com
objectClass: organizationalUnit
ou: people
dn: ou=groups,dc=kinggoo,dc=com
objectClass: organizationalUnit
ou: groups

然后执行

[root@kinggoo cn=config]# ldapadd -x -D cn=admin,dc=kinggoo,dc=com -W -f ./frontend.ldif
Enter LDAP Password:        #这里输入你的明文密码
adding new entry "dc=kinggoo,dc=com"
adding new entry "cn=admin,dc=kinggoo,dc=com"
adding new entry "ou=people,dc=kinggoo,dc=com"
adding new entry "ou=groups,dc=kinggoo,dc=com"

重启服务,然后看有没有警告,如果有那你最好是重新来过。如果没问题,那恭喜你!

[root@kinggoo ~]# service  slapd  restart
Stopping slapd:[  OK  ]
Starting slapd:[  OK  ]

删除用户或组条目
[root@kinggoo ~]# ldapdelete -x -W -D ‘cn=admin,dc=kinggoo,dc=com’ “uid=cent,ou=people,dc=kinggoo,dc=com”
Enter LDAP Password:
[root@kinggoo ~]# ldapdelete -x -W -D ‘cn=admin,dc=kinggoo,dc=com’ “cn=cent,ou=groups,dc=kinggoo,dc=com”
Enter LDAP Password:
如果忘记管理员密码,或者想修改该密码:
ldappasswd -x -v -S -W -D cn=admin,dc=kinggoo,dc=com

大概已经结束了:


版权声明:
转载原创文章请注明,文章出处: http://kinggoo.com
原文地址: http://kinggoo.com/openldapinstallconf.htm