CentOS6.4 安装配置LDAP

1.关闭防火墙、selinux, 安装之前查一下

service iptables stop

find / -name openldap*

  1. centos6.4默认安装了LDAP,但没有装ldap-server和ldap-client,于是root模式下yum安装

    yum install -y openldap openldap-servers openldap-clients

  2. 不建议编译源码包,有依赖比较麻烦,接下来配置

cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
mv /etc/openldap/slapd.d{,.bak}
cd /etc/openldap/
vim slapd.conf
  1. 设置管理员密码
slappasswd -s weyee    #weyee是由你自己设置的密码
slappasswd -s weyee |sed -e "s#{SSHA}#rootpw\t{SSHA}#g" >>/etc/openldap/slapd.conf   #注意修改weyee
  1. 添加权限
chown ldap.ldap /etc/openldap/*
chown ldap.ldap /var/lib/ldap/*
  1. 修改dc配置
[root@dev openldap]# vim /etc/openldap/slapd.conf
#以下参数大概在114行
database        bdb                                #使用bdb数据库
suffix          "dc=dev,dc=com"                    #定义dc,指定搜索的域
rootdn          "cn=admin,dc=dev,dc=com"           #定义管理员的dn,使用这个dn能登陆openldap

优化ldap配置参数
[root@dev openldap]# vim /etc/openldap/slapd.conf
loglevel 296                    #定义日志级别
cachesize 1000                  #换成条目数
checkpoint 2048 10              #表示内存中达到2048k或者10分钟,执行一次checkpoint,即写入数据文件的操作

配置相关权限
[root@dev openldap]# vim /etc/openldap/slapd.conf
#删除默认权限,将下面的内容都删除
database config
access to *
        by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
        by * none

# enable server status monitoring (cn=monitor)
database monitor
access to *
        by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
        by dn.exact="cn=Manager,dc=my-domain,dc=com" read
        by * none

#添加新的权限(这是2.3的权限设置方式)
access to *
        by self write
        by anonymous auth
        by * read

配置syslog记录ldap的服务日志
[root@dev openldap]# cp /etc/rsyslog.conf /etc/rsyslog.conf_`date +%Y%m%d`.bak

#往配置文件中增加如下内容
[root@dev openldap]# tail -1 /etc/rsyslog.conf
local4.*                    /var/log/ldap.log

#重启rsyslog服务
[root@dev openldap]# /etc/init.d/rsyslog restart
Shutting down system logger:                               [  OK  ]
Starting system logger:                                    [  OK  ]

配置ldap数据库路径
#创建数据文件
[root@dev openldap]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
[root@dev openldap]# chown ldap.ldap /var/lib/ldap/DB_CONFIG 
[root@dev openldap]# chmod 700 /var/lib/ldap/
[root@dev openldap]# ll /var/lib/ldap/
total 4
-rw-r--r-- 1 ldap ldap 845 Jul 13 21:05 DB_CONFIG

[root@dev openldap]# egrep -v "\#|^$" /var/lib/ldap/DB_CONFIG 
set_cachesize 0 268435456 1
set_lg_regionmax 262144
set_lg_bsize 2097152
[root@dev openldap]# slaptest -u            #检查配置文件是否正常
config file testing succeeded

启动ldap服务
[root@dev ~]# /etc/init.d/slapd start
Starting slapd:                                            [  OK  ]
[root@dev ~]# ps aux |grep ldap
ldap      2012  0.3  1.9 490532 19656 ?        Ssl  21:13   0:00 /usr/sbin/slapd -h  ldap:/// ldapi:/// -u ldap
root      2018  0.0  0.0 103248   872 pts/0    S+   21:14   0:00 grep ldap
[root@dev ~]# netstat -tunlp |grep slapd
tcp        0      0 0.0.0.0:389                 0.0.0.0:*                   LISTEN      2012/slapd          
tcp        0      0 :::389                      :::*                        LISTEN      2012/slapd        #普通端口389,加密后的是689

#添加到开机自启动
[root@dev ~]# chkconfig slapd on

#查看日志文件
[root@dev ~]# tail /var/log/ldap.log 
Jul 13 21:14:00 dev slapd[2011]: @(#) $OpenLDAP: slapd 2.4.39 (Oct 15 2014 09:51:43) $#012#[email protected]:/builddir/build/BUILD/openldap-2.4.39/openldap-2.4.39/build-servers/servers/slapd
  1. 重启CentOS,重启服务
查询一下ldap的内容
[root@dev ~]# ldapsearch -LLL -W -x -H ldap://dev.com -D "cn=admin,dc=dev,dc=com" -b "dc=dev,dc=com" "(uid=*)"
Enter LDAP Password: 
ldap_bind: Invalid credentials (49)        #这里报错

#解决如下,删除默认2.4的配置文件,重新生成2.3的配置文件
[root@dev ~]# rm -rf /etc/openldap/slapd.d/*
[root@dev ~]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/
55a3bf76 bdb_monitor_db_open: monitoring disabled; configure monitor database to enable
config file testing succeeded                                          [  OK  ]
[root@dev ~]# ll /etc/openldap/slapd.d/
total 8
drwxr-x--- 3 root root 4096 Jul 13 21:39 cn=config
-rw------- 1 root root 1302 Jul 13 21:39 cn=config.ldif

#重启服务
[root@dev ~]# /etc/init.d/slapd restart
Stopping slapd:                                            [  OK  ]
Checking configuration files for slapd:                    [FAILED]
55a3bfd6 ldif_read_file: Permission denied for "/etc/openldap/slapd.d/cn=config.ldif"
slaptest: bad configuration file!
[root@dev ~]# chown -R ldap.ldap /etc/openldap/slapd.d
[root@dev ~]# /etc/init.d/slapd restart
Stopping slapd:                                            [FAILED]
Starting slapd:                                            [  OK  ]

[root@dev ~]# netstat -tunlp |grep slapd
tcp        0      0 0.0.0.0:389                 0.0.0.0:*                   LISTEN      5906/slapd          
tcp        0      0 :::389                      :::*                        LISTEN      5906/slapd

#再重新查询ldap内容
[root@dev ~]# ldapsearch -LLL -W -x -H ldap://dev.com -D "cn=admin,dc=dev,dc=com" -b "dc=dev,dc=com" "(

执行到此处的时候,出现

ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)

等待解决,先记录到这里。

先记录到此

参考文献

  1. http://www.360doc.com/content/14/0518/01/4171006_378650963.shtml
  2. http://blog.csdn.net/odailidong/article/details/49918893

猜你喜欢

转载自blog.csdn.net/lj1404536198/article/details/79166902