服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

手把手教你:安装opldap历险记


  安装环境:
  redhat linux9.0 内核版本2.40.2-8
  
  一、准备工作:
  按照http://www.openldap.org/faq/data/cache/196.html所列的软件准备:
  
  1.安装的先决条件为:c开发环境,支持posix标准的正规表达式,支持berkeley标准的网络协议。
  
  openldap 2.x is designed to "configure" and "build" on unix (and unix-like) systems.
  
  the prerequisites depending upon the which features you desire.
  
  general prerequisites include:
  
   c development environment
  
   posix regex routines
  
   berkeley networking (socket/select) routines
  
  2.安装slapd即为openldap的守护程序所需的软件:berkeley数据库和gbdm数据库可以两者选择其一。我选择了前者。
  
  berkeley数据库4.2和相关的patches文件:源代码和补丁文件可从http://www.sleepycat.com/下载。打补丁要使用patch命令运行,主要功能为在编译前更新源代码中的bug。关于patch的详细用法请参考www-900.ibm.com/developerworks/ cn/linux/l-diffp/index.shtml。
  
  slapd (with bdb database) prerequisites includes:
  
   berkeley database 4.2 from sleepycat (http://www.sleepycat.com/)
  
  latest version with patches is recommended.
  
  slapd (with ldbm database) prerequisites include suitable database support. one of following packages can fulfill the prerequisite.
  
   berkeley database from sleepycat (http://www.sleepycat.com/)
  
   gnu database manager (gdbm) from fsf (http://www.gnu.org/)
  
  for openldap 2.1 (or later), berkeley db 4.1 is recommended.
  
  slurpd prerequisites include:
  
   thread support (posix threads and others)
  
  3.选装软件:ssl/tls和sasl。ssl/tls提供信息加密功能,可以从http://www.openssl.org下载,但是在安装前需要打补丁详情见http://www.openldap.org/faq/index.cgi?file=185。cyrus-sasl主要提供给一些安全认证的功能,可以从http://asg.web.cmu.edu/sasl/下载源代码。由于这两个都是选装软件,所以按照计算机的负载方面来选择了后者。
  
  ssl/tls prerequisites(选装):
  
   openssl 0.9.6 from http://www.openssl.org
  
  the openssl library usually needs to be patched before it will work correctly. see this faq article for details: http://www.openldap.org/faq/index.cgi?file=185 (note about openssl and crypt())
  
  sasl prerequisites(选装):
  
   cyrus-sasl from http://asg.web.cmu.edu/sasl/
  
  二、开始安装:
  1.安装berkeley数据库(berkeley database 4.2.52):
  
  tar -zxvf db-4.2.52.nc.tar.gz或者gzip ?cd db-4.2.52.nc.tar.gz再tar ?cxf db-4.2.52.nc.tar。
  解完压后,会生成一个db-4.2.52.nc目录,进行该目录下的build_unix目录,我们将在这个目录中配置和安装berkeley4.2.52。执行以下命令进行配置安装。
  # ../dist/configure
  # make
  # make install
  也是按linux源码安装的三步曲完成,没有什么好说的了。该软件默认是安装在/usr/local/berkeleydb.4.2目录下。安装完成后,要把/usr/local/berkeleydb.4.2/lib的库路径加到/etc/ld.so.conf文件内,这个文件就是系统动态链接库的配置文件。此文件内,存放着可被linux共享的动态链接库所在目录的名字(系统目录 /lib,/usr/lib除外),各个目录名间以空白字符(空格,换行等)或冒号或逗号分隔。一般的linux发行版中,此文件均含一个共享目录 /usr/x11r6/lib,为x window窗口系统的动态链接库所在的目录。添加完成后执行一次 ldconfig ?cv,使用配置文件生效。这样编译openldap时才能找到相应的库文件。
  
  2.安装cyrus-sasl(cyrus-sasl-2.1.20):
  
  tar ?czxvf cyrus-sasl-2.1.20.tar.gz或者gzip ?cd cyrus-sasl-2.1.20.tar.gz再tar ?cxf cyrus-sasl-2.1.20.tar。
  
  解完压缩,会生成cyrus-sasl-2.1.20目录,进入该目录,按照linux源码安装的三步曲完成配置和安装:
  
  # ./configure
  
  # make
  
  # make install
  
  由于cyrus-sasl需要一些库支持,如果在编译时遇到问题,请访问http://asg.web.cmu.edu/sasl/。我比较幸运:-)。安装完成后,要把/usr/local/lib/sasl2和/usr/local/lib的库路径加到/etc/ld.so.conf文件内,添加完成后执行一次 ldconfig ?cv,使用配置文件生效。这样编译openldap时才能找到相应的库文件。
  
  运行结果:
  
  ldconfig -v
  
  ...
  
  /usr/local/lib:
  
      libldap_r-2.2.so.7 -> libldap_r-2.2.so.7.0.13
  
      libldap-2.2.so.7 -> libldap-2.2.so.7.0.13
  
      liblber-2.2.so.7 -> liblber-2.2.so.7.0.13
  
      libsasl2.so.2 -> libsasl2.so.2.0.20
  
  /usr/local/lib/sasl2:
  
      libanonymous.so.2 -> libanonymous.so.2.0.20
  
      libplain.so.2 -> libplain.so.2.0.20
  
      libotp.so.2 -> libotp.so.2.0.20
  
      libdigestmd5.so.2 -> libdigestmd5.so.2.0.20
  
      libcrammd5.so.2 -> libcrammd5.so.2.0.20
  
      libsasldb.so.2 -> libsasldb.so.2.0.20
  
  ...
  
  可以看见sasl的一些软链接信息。linux中的命令ldd也可以查看执行文件或者库文件的库链接信息,详细用法可以用ldd --help查到。
  
  3.安装openldap(openldap-stable2.2.20(20050103)):
  
  同上cyrus-sasl的安装一样,解压缩后进入生成的openldap-2.2.20目录,按照linux源代码安装的三部曲+测试(make test):
  
  # ./configure
  
  a.首尝失败:问题来了,刚刚运行./configure就出现了下面的错误1:
  
  checking berkeley db version for bdb backend... no
  
  configure: error: bdb: berkeleydb version incompatible
  
  这个错误说明berkeley数据库的版本与openldap需要的不兼容??奇怪,我安装的4.2.52可是openldap官方文档明确说明支持的!仔细一查才发现原来我的rh9上已经默认安装了berkeley(版本较低)。
  
  于是我在执行configure之前,首先设置了环境变量:
  
  export cppflags="-i/usr/local/berkeleydb.4.2/include"
  
  export ldflags="-l/usr/local/berkeleydb.4.2/lib"
  
  configure所用的环境变量列表:
  
  cc=...
  c编译器的名称
  cppflags=...
  各种c预处理和编译器参数
  cflags=...
  c编译器的调试和优化参数
  ldflags=...
  各种连接器参数
  libs=...
  连接器的库位置信息("-l" and "-l"参数)
  includes=...
  头文件的搜索目录("-idir").
  target=... [default: apache]
  目标执行文件名
  notest_cppflags=...
  notest_cflags=...
  notest_ldflags=...
  notest_libs=...
  
  这两个环境变量指定了预处理编译参数、连接器参数,它们将在执行configure时被configure所读取,并且在以后的make时使用。果然执行configure该处没有问题了。
  
  b.再次受打击:刚刚解决一个问题,还没喘过气,configure又出问题了,错误2:
  
  checking cyrus sasl library version... no
  
  configure: error: cyrus sasl library located but is incompatible
  
  与berkeley数据库一样,cycrus sasl的版本也不兼容??原来还是一样的原因:系统中装有个版本低的cycrus sasl。。。l。。。麻烦!只好在丰富一下环境变量了:
  
  export cppflags="-i/usr/local/berkeleydb.4.2/include"
  
  export ldflags="-l/usr/local/lib/ -l/usr/local/berkeleydb.4.2/lib -l/usr/local/lib/sasl2"
  
  将刚刚安装的cycrus sasl的库路径放到了连接器参数ldflags中。接着重新configure,通过了。
  
  # make
  
  这个阶段基本上我的工作就是等着,喝点水。。。等make结束后。。
  
  # make test
  
  c.一波三折:出大问题了(如果配置不正确,这个错误在make install后运行slapd ?cd 9时也会出现)。。错误3:
  
  cd tests; make test
  
  make[1]: entering directory `/home/liudan/openldap-2.2.20/tests'
  
  make[2]: entering directory `/home/liudan/openldap-2.2.20/tests'
  
  initiating ldap tests for bdb...
  
  running ./scripts/all...
  
  >>>>> executing all ldap tests for bdb
  
  >>>>> starting test000-rootdse ...
  
  running defines.sh
  
  starting slapd on tcp/ip port 9011...
  
  …
  
  slapd init: initiated server.
  
  slap_sasl_init: sasl library ver

扫描关注微信公众号