OpenLDAP与phpldapadmin的搭建

时间:2023-03-09 18:24:07
OpenLDAP与phpldapadmin的搭建

最近一直在看LDAP的东西,把自己的记录下来,以后可以看看。

1:环境

1):关闭防火墙

service iptables stop

2):setenforce 0

vim /etc/sysconfig/selinux  修改成SELINUX=disabled

2:安装,yum源安装

        yum install -y  openldap-clients.x86_64
        yum -y install openldap-servers.x86_64
3:添加ldap用户
        groupadd ldap
        useradd -g ldap ldap  
        passwd ldap
4:初始化OpenLDAP配置
       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
5:slappasswd创建一个密码,先记着,后面要用
6:修改slapd.conf文件,下面的rootpw就是第5步生成的密码,rootpw必须顶格写,与后面的密码用Tab键分开
     OpenLDAP与phpldapadmin的搭建
7:生成配置数据(若重新修改了配置文件,从这一步开始得重新生成数据)先查看一下:
[root@yunovo openldap]# cat /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}bdb.ldif
# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 408c80ce
dn: olcDatabase={2}bdb
objectClass: olcDatabaseConfig
objectClass: olcBdbConfig
olcDatabase: {2}bdb
olcSuffix: dc=example,dc=com
olcAddContentAcl: FALSE
olcLastMod: TRUE
olcMaxDerefDepth: 15
olcReadOnly: FALSE
olcRootDN: cn=Manager,dc=example,dc=com

删除这些数据:

rm -rf /etc/openldap/slapd.d/*

重新生成新的配置数据:

# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
config file testing succeeded

然后,查看重新生成的数据是否匹配:

cat /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{\}bdb.ldif 

授权:

chown -R ldap.ldap slapd.d/

8:启动服务:

/etc/init.d/slapd restart

9:执行到这一步,必须添加Manager的数据后,才能通过phpldapAdmin登录

导入数据:

vim root.ldif
dn: dc=example,dc=com
objectclass: dcObject
objectclass: organization
o: Example,Inc.
dc: example
dn: cn=Manager,dc=example,dc=com
objectclass: organizationalRole
cn: Manager

用ldapadd命令导入

ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f example.ldif
Enter LDAP Password: 输入slappasswd时候设置的密码
adding new entry "dc=example,dc=com"
adding new entry "cn=Manager,dc=example,dc=com"

二:phpldapAdmin的搭建

1):安装EPEL仓库
rpm -ivh http://mirrors.ukfast.co.uk/sites/dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

2):yum安装phpldapAdmin

yum install -y phpldapadmin

3):修改phpldapAdmin配置文件

Alias /phpldapadmin /usr/share/phpldapadmin/htdocs
Alias /ldapadmin /usr/share/phpldapadmin/htdocs
<Directory /usr/share/phpldapadmin/htdocs>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::
Allow from 10.0.0.170 10.0.0.126 允许哪些IP地址访问phpldapadmin
</Directory>

4):修改php配置文件

$servers->setValue('login','attr','dn');    把这一行的注释去掉
// $servers->setValue('login','attr','uid');

5):重启httpd服务

/etc/init.d/httpd restart

6):在网页段输入访问路径  http://服务端IP/ldapadmin

OpenLDAP与phpldapadmin的搭建