Chinaunix首页 | 论坛 | 博客
  • 博客访问: 24853132
  • 博文数量: 271
  • 博客积分: 10025
  • 博客等级: 上将
  • 技术积分: 3358
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-12 15:28
文章分类

全部博文(271)

文章存档

2010年(71)

2009年(164)

2008年(36)

我的朋友

分类: LINUX

2008-08-23 11:11:44

简介:

  LDAP(轻量级目录服务访问协议,Lightweight Directory Access Protocol)基于X.500标准,支持TCP/IP,使用简单方便。现在越来越多的网络应用系统都支持LDAP。
  目录是一个为查询、浏览和搜索而优化的专业分布式数据库,它成树状结构组织数据,就好象Linux/Unix系统中的文件目录一样。目录数据库和关系 数据库不同,它有优异的读性能,但写性能差,并且没有事务处理、回滚等复杂功能,不适于存储修改频繁的数据。所以目录天生是用来查询的,就好象它的名字一 样。目录服务是由目录数据库和一套访问协议组成的系统。类似以下的信息适合储存在目录中: 企业员工和企业客户之类人员信息;公用证书和安全密钥;邮件地址、网址、IP等电脑信息;电脑配置信息。
  而且在我们的日常生活中,很多的应用都是基于LDAP的,比如Microsoft服务器的AD管理以及IBM的邮件Lotus都是基于LDAP的,并 且Linux下的Postfix也可以设计成支持LDAP的形式,这篇文单权当是入门之用吧.以前有试过做基于Mysql的Postfix邮件系统( http://waringid.blog.51cto.com/65148/58580),也打算用LDAP来实现,我会把我的安装经历整理出来的.

支持软件:

  安装OpenLDAP的相关支持软件是Berkeley DB,有了它就可以进行了,当然,如果你要求Sasl的支持的话那cyrus-sasl这个支持包也是少不了的.不过这个软件包一般系统中会自带,而且OpenLDAP在编译时默认会加入此功能支持.这些软件的下载地址可以参考我以前写过的一篇文章( http://waringid.blog.51cto.com/65148/58144),其中有列出下载地址.而OpenLDAP的下载地址则是: .

系统相关:

  在Linux下不同版本的系统在设置上可能会有很小的差异,所以这里交待一下我的系统:RedHat AS 4,安装时所选的系统组件只有"开发工具",其它的所有软件包都没有选取.如果你是Linux新手,对装系统还有一些困难的话,请参考这篇文章(http://waringid.blog.51cto.com/65148/47655).

下载相关软件:
查询并卸载系统中原有的相关软件:

rpm -qa |grep ldap
rpm -e --nodeps 显示的组件

安装BerkeleyDB:

tar zxvf db-4.5.20.tar.gz
cd db-4.5.20/build_unix
../dist/configure --prefix=/usr/local/BerkeleyDB
make
make install
echo "/usr/local/BerkeleyDB/lib" >> /etc/ld.so.conf
ldconfig -v

安装Cyrus-Sasl:

tar zxvf cyrus-sasl-2.1.21.tar.gz
cd cyrus-sasl-2.1.21
./configure --prefix=/usr/local/sasl --enable-cram --enable-plain \
--enable-digest --disable-anon --enable-krb4 --enable-ntlm
make
make install
echo "/usr/local/sasl/lib/" >> /etc/ld.so.conf
ldconfig -v
ln -sv /usr/local/sasl/include/sasl/* /usr/local/include/
ln -sv /usr/local/sasl/lib/* /usr/local/lib/
ln -sv /usr/local/sasl/lib/sasl2/* /usr/local/lib/

安装OpenLDAP:

gunzip -c openldap-2.4.9.tgz | tar xvfB -
cd openldap-2.4.9
env CPPFLAGS="-I/usr/local/BerkeleyDB/include" LDFLAGS="-L/usr/local/BerkeleyDB/lib" \
./configure --prefix=/usr/local/openldap --sysconfdir=/etc --enable-ldbm \
--enable-lmpasswd --enable-spasswd --enable-bdb --enable-ldap
make depend
make
make install
echo /usr/local/openldap/lib >> /etc/ld.so.conf
ldconfig -v

配置LADP:

  LDAP的配置中,我们要实现的功能如图所示.需要增加一个用户"Ben".

生成LDAP管理密码:
/usr/local/openldap/sbin/slappasswd -h {md5}
{MD5}X03MO1qnZdYdgyfeuILPmQ== ##此密码是LDAP管理密码,和系统密码无关

增加相关查询记录:
echo "127.0.0.1 ldap.test.com" >> /etc/hosts
echo "127.0.0.1 ldap-master.test.com" >> /etc/hosts

设置slapd.conf文件:
vi /etc/openldap/slapd.conf
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
database bdb
suffix "dc=test,dc=com"
rootdn "cn=Manager,dc=test,dc=com"
rootpw {MD5}X03MO1qnZdYdgyfeuILPmQ==
directory /var/lib/ldap

设置ldap.conf文件:
vi /etc/openldap/ldap.conf
HOST 127.0.0.1
BASE dc=test,dc=com
URI
SIZELIMIT 12
TIMELIMIT 15
DEREF nerver

启动LDAP:
/usr/local/openldap/libexec/slapd

增加用户资料:
vi test.ldif
#root node ##建立DN
dn:dc=test,dc=com
dc:test
objectclass:dcObject
objectclass:organizationalUnit
ou:test Dot com

#login top ##建立RDN
dn:ou=login,dc=test,dc=com
ou:login
objectclass:organizationalUnit

#user,uid,password
dn:ou=user,ou=login,dc=test,dc=com
ou:user
objectclass:organizationalUnit

#group
dn:ou=group,ou=login,dc=test,dc=com
ou:group
objectclass:organizationalUnit

#company organization top
dn:ou=company,dc=test,dc=com
ou:company
objectclass:organizationalUnit

#for company organization(unit)
dn:ou=unit,ou=company,dc=test,dc=com
ou:unit
objectclass:organizationalUnit

#human resource(under unit)
dn:ou=hr,ou=unit,ou=company,dc=test,dc=com
ou:hr
objectclass:organizationalUnit

#MIS(under unit)
dn:ou=mis,ou=unit,ou=company,dc=test,dc=com
ou:mis
objectclass:organizationalUnit

#Editorial(under unit)
dn:ou=editorial,ou=unit,ou=company,dc=test,dc=com
ou:editorial
objectclass:organizationalUnit

vi user.ldif ##建立用户数据
#User-Ben Chan
dn:cn=ben,ou=editorial,ou=unit,ou=company,dc=test,dc=com
cn:ben
sn:chan
objectclass:organizationalUnit
givenName:ben
mail:ming@test.com
telephoneNumber:1234678
mobile:98765432
postalAddress:dongguan
postalCode:86
ou:editorial
o:test Corp
labeledURL:http://waringid.blog.51cto.com
title:Editor

postalCode: 区号
ou:部门
o:机构
title:职位


解决中文符号问题:
dos2unix user.ldif
iconv -f gb2312 -t UTF-8 -o user.ldif.utf8 user.ldif
file user.ldif.utf8
ldapmodify -D "cn=Manager,dc=test,dc=com" -w secret -x -a -f user.ldif.utf8

测试:
ldapsearch -x -b "ou=unit,ou=company,dc=test,dc=com"

通过web方式管理LADP:
  以命令的方式来管理LDAP是最快最直接的方法,但是需要用户有一定的Linux管理能力及对LDAP结构深入的理解.还有一种方式就是通过WEB的方式进行管理,这种方式和phpmyadmin管理mysql差不多,用它则是最方便讯速了.下载地址为:.它的配置方法和phpmyadmin的配置方法差不多,这里就不过多描述了,参考以前的文件应可以自行设置( http://waringid.blog.51cto.com/65148/58210),需要注意的是要将配置文件从config目录中copy到它的上一级目录,然后需要设置以下一些地方:
$ldapservers->SetValue($i,'server','auth_type','session');
$ldapservers->SetValue($i,'login','dn','cn=Manager,dc=test.com');
$ldapservers->SetValue($i,'login','pass','');
阅读(819) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~