[关闭]
@cdmonkey 2018-06-04T07:16:47.000000Z 字数 4881 阅读 1332

OpenLDAP-new

LDAP


Install

http://www.jianshu.com/p/c73d40122cf1
http://jianshi-dlw.iteye.com/blog/1557846
https://wiki.archlinux.org/index.php/OpenLDAP_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

Install DB

安装必要的工具包:

  1. yum install -y gcc
  1. [root@hidocker tools]# tar xvf db-5.3.28.gz
  2. [root@hidocker tools]# cd db-5.3.28
  3. [root@hidocker db-5.3.28]# cd build_unix # 需要进入该目录下进行编译安装,虽然该目录下面是空的。
  4. [root@hidocker build_unix]# ../dist/configure --prefix=/usr/local/bdb
  5. make
  6. make install

Insatll OpenLDAP

  1. [root@hidocker tools]# tar zxvf openldap-2.4.44.tgz
  2. [root@hidocker tools]# cd openldap-2.4.44
  3. [root@hidocker openldap-2.4.44]# ./configure \
  4. --prefix=/usr/local/openldap \
  5. --enable-syslog \
  6. --enable-modules \
  7. --with-tls=openssl \
  8. CPPFLAGS="-I/usr/local/bdb/include" \
  9. LDFLAGS="-L/usr/local/bdb/lib -Wl,-rpath,/usr/local/bdb/lib"
  10. ------------------
  11. # 可按照提示进行编译前的检测:
  12. [root@hidocker openldap-2.4.44]# make depend
  13. # 可能会出现下面的错误:
  14. plugin.c:33:18: fatal error: ltdl.hNo such file or directory
  15. # 需要安装下面的依赖包:
  16. yum install libtool-ltdl-devel
  17. # 重新进行测试,如果不再显示错误就能够正常的编译安装了。
  18. ------------------
  19. make
  20. make install

检测对于TLS的配置情况:

  1. ./configure --prefix=/usr/local/openldap --enable-syslog --enable-modules --with-tls CPPFLAGS="-I/usr/local/bdb/include" LDFLAGS="-L/usr/local/bdb/lib -Wl,-rpath,/usr/local/bdb/lib"|grep openssl
  2. checking openssl/ssl.h usability... yes
  3. checking openssl/ssl.h presence... yes
  4. checking for openssl/ssl.h... yes
  5. configure: WARNING: ICU not available
  1. ln -s /usr/local/openldap/bin/* /usr/bin/
  2. ln -s /usr/local/openldap/sbin/* /usr/sbin/
  1. [root@hidocker ~]# mkdir -pv /etc/openldap

启动服务:

  1. # 这种启动方式为前台启动,并会显示些启动信息:
  2. [root@hidocker ~]# /usr/local/openldap/libexec/slapd -d 1
  3. # 直接于后台启动:
  4. [root@hidocker ~]# /usr/local/openldap/libexec/slapd

验证服务:

  1. [root@hidocker ~]# ps -ef|grep ldap|grep -v grep
  2. root 44834 1 0 07:35 ? 00:00:00 /usr/local/openldap/libexec/slapd
  3. [root@hidocker ~]# netstat -lntp|grep slapd
  4. tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 44834/slapd

Configure

http://smileyouth.blog.51cto.com/7273768/1746929

需要配置最为重要的配置文件:

  1. [root@hidocker ~]# vim /usr/local/openldap/etc/openldap/slapd.conf
  2. # Add schema:
  3. include /usr/local/openldap/etc/openldap/schema/cosine.schema
  4. include /usr/local/openldap/etc/openldap/schema/nis.schema
  5. include /usr/local/openldap/etc/openldap/schema/inetorgperson.schema
  6. include /usr/local/openldap/etc/openldap/schema/openldap.schema
  7. include /usr/local/openldap/etc/openldap/schema/dyngroup.schema
  8. database mdb # 定义使用的后端数据存储。其后可跟的值有bdb、ldbm、passwd、shell
  9. maxsize 1073741824
  10. suffix "dc=sxpay,dc=com" # 设置目录后缀。该部分可改为实际使用的域名中相关的部分。
  11. rootdn "cn=Manager,dc=sxpay,dc=com" # 设置目录超级管理员账号。类同于系统中的根用户。由于访问控制对此用户是不生效的,因而有很大的安全隐患,建议安装配置及调试完成后移除该帐号。
  12. rootpw secret # 定义超级管理员的密码,这里使用的是明文,secret就是其密码,这是极不安全的。
  13. directory /usr/local/openldap/var/openldap-data # 数据导入后的存储路径。该目录最好只能由运行目录服务进程的用户所有,推荐权限为700
  14. index objectClass eq # 指定索引时的匹配规则。

导入数据

  1. [root@hidocker ~]# cat ldif/sxpay.ldif
  2. dn: dc=sxpay,dc=com
  3. dc: sxpay
  4. objectClass: domain
  5. dn: ou=member,dc=sxpay,dc=com
  6. ou: member
  7. objectClass: organizationalUnit
  8. dn: cn=user1,ou=member,dc=sxpay,dc=com
  9. cn: user1
  10. sn: USER1
  11. uid: user1
  12. userPassword: user1
  13. objectClass: inetOrgPerson
  14. dn: cn=user2,ou=member,dc=sxpay,dc=com
  15. cn: user2
  16. sn: USER2
  17. uid: user2
  18. userPassword: user2
  19. objectClass: inetOrgPerson
  20. dn: cn=user3,ou=member,dc=sxpay,dc=com
  21. cn: user3
  22. sn: USER3
  23. uid: user3
  24. userPassword: user3
  25. objectClass: inetOrgPerson
  1. [root@hidocker ~]# slapadd -v -l /root/ldif/sxpay.ldif
  2. 591d8d2a mdb_monitor_db_open: monitoring disabled; configure monitor database to enable
  3. added: "dc=sxpay,dc=com" (00000001)
  4. added: "ou=member,dc=sxpay,dc=com" (00000002)
  5. added: "cn=user1,ou=member,dc=sxpay,dc=com" (00000003)
  6. added: "cn=user2,ou=member,dc=sxpay,dc=com" (00000004)
  7. added: "cn=user3,ou=member,dc=sxpay,dc=com" (00000005)
  8. _#################### 100.00% eta none elapsed none fast!
  9. Closing DB...

base.ldif

  1. [root@hidocker openldap]# ldapadd -x -D "cn=Manager,dc=sxpay,dc=com" -W -f ./base.ldif
  2. Enter LDAP Password:
  3. adding new entry "dc=sxpay,dc=com"
  4. adding new entry "ou=Yunweibu,dc=sxpay,dc=com"

查看已经导入的数据

  1. ldapsearch -x -D "cn=Manager,dc=sxpay,dc=com" -w secret -b "dc=sxpay,dc=com"

移除数据

其实就是移除指定的DN项。

  1. ldapdelete -x -D "cn=Manager,dc=sxpay,dc=com" -w secret "cn=user1,ou=member,dc=sxpay,dc=com"

ldaps

如果于编译安装时没有使用--with-tls参数,而启动时又指定了ldaps:///协议,就会报错。

  1. [root@hidocker ~]# /usr/local/openldap/libexec/slapd -h "ldap:/// ldaps:///" -d 1
  2. ...
  3. 591ea503 daemon_init: listen on ldap:///
  4. 591ea503 daemon_init: listen on ldaps:///
  5. 591ea503 daemon_init: 2 listeners to open...
  6. ldap_url_parse_ext(ldap:///)
  7. 591ea503 daemon: listener initialized ldap:///
  8. ldap_url_parse_ext(ldaps:///)
  9. 591ea503 daemon: TLS not supported (ldaps:///) # 显示为不支持。
  10. 591ea503 slapd stopped.
  11. 591ea503 connections_destroy: nothing to destroy.

配置证书

https://www.ibm.com/developerworks/cn/linux/l-openldap
https://www.ibm.com/developerworks/cn/linux/1312_zhangchao_opensslldap

  1. [root@hidocker ~]# vim /usr/local/openldap/etc/openldap/slapd.conf
  2. # TLS
  3. TLSCertificateFile /root/key/_.suixingpay.com_bundle.crt
  4. TLSCertificateKeyFile /root/key/_.suixingpay.com.key

启动服务:

  1. [root@hidocker ~]# /usr/local/openldap/libexec/slapd -h "ldap:/// ldaps:///"
  2. # Check port:
  3. [root@hidocker ~]# netstat -lntp|grep slapd
  4. tcp 0 0 0.0.0.0:636 0.0.0.0:* LISTEN 33704/slapd
  5. tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 33704/slapd

Support SASL

  1. [root@hidocker ~]# yum install cyrus-sasl
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注