86565656 发表于 2019-2-15 17:43:05

openldap+phpldapadmin(Centos7)

本次实验配置文档下载地址:https://www.lanzous.com/i1xmrng


OpenLDAP简介
  LDAP是一款轻量级目录访问协议(Lightweight Directory Access Protocol,简称LDAP),属于开源集中账号管理架构的实现,且支持众多系统版本,被广大互联网公司所采用。LDAP提供并实现目录服务的信息服务,目录服务是一种特殊的数据库系统,对于数据的读取、浏览、搜索有很好的效果。目录服务一般用来包含基于属性的描述性信息并支持精细复杂的过滤功能。
  OpenLDAP目录中的信息是以树状的层次结构来存储数据(这很类同于DNS),最顶层即根部称作“基准DN”,形如“dc=mydomain,dc=org”或者“o=mydomain.org”,前一种方式更为灵活也是WindowsAD中使用的方式。在根目录的下面有很多的文件和目录,为了把这些大量的数据从逻辑上分开,OpenLDAP像其它的目录服务协议一样使用OU(OrganizationUnit,组织单元),可以用来表示公司内部机构,如部门等,也可以用来表示设备、人员等。同时OU还可以有子OU,用来表示更为细致的分类。

  OpenLDAP默认以Berkeley DB作为后端数据库,BerkeleyDB数据库主要以散列的数据类型进行数据存储,如以键值对的方式进行存储。
  注意:尽量不要使用Mysql数据库,会出不知名的错误,本人亲身经历,排了半天错,还是没搞定,最后改用默认的数据库。
实验环境:
  LDAP server:192.168.1.16
  分别有两个组,每组有一个用户:

  组: xinxiqiche
  用户:xinxi1qiche1
  1、同步时间,关闭selinux与防火墙//仅实验环境

  # yum install -y ntp
  #ntpdate -u ntp.api.bz

  #setenforce 0

  #systemctl stop firewalld

  # iptables -F
  2、安装OpenLDAP软件包
  
  # yum -y install openldap compat-openldap openldap-clients openldap-servers openldap-servers-sql openldap-devel migrationtools
  3、查看OpenLDAP版本
  http://s1.运维网.com/images/20180922/1537601315386959.png
  4、配置OpenLDAP
  首先设置密码:

  http://s1.运维网.com/images/20180922/1537609592652613.png

  修改以下两个配置文件:

  # vim /etc/openldap/slapd.d/cn=config/olcDatabase\=\{1\}monitor.ldif
# vim /etc/openldap/slapd.d/cn=config/olcDatabase\=\{2\}hdb.ldif

  http://s1.运维网.com/images/20180922/1537604051893851.png

  http://s1.运维网.com/images/20180922/1537604007233804.png
  检查配置文件并开启OpenLDAP服务:
  http://s1.运维网.com/images/20180922/1537604115593052.png
  http://s1.运维网.com/images/20180922/1537604156347077.png
  5、配置BerkeleyDB数据库
  拷贝配置文件,到默认路径下:
http://s1.运维网.com/images/20180922/1537604198462039.png
  生效LDAP配置模式:

http://s1.运维网.com/images/20180922/1537604337572856.png
  migrate_common.ph文件主要用来生成ldif文件,修改migrate_common.ph配置文件:
http://s1.运维网.com/images/20180922/1537604443727422.png
  创建本地组和用户:

http://s1.运维网.com/images/20180922/1537604571794243.png

http://s1.运维网.com/images/20180922/1537604577834661.png
http://s1.运维网.com/images/20180922/1537604617273121.png
  生成的用户和用户组配置文件,使用migrate_passwd.pl文件生成要用户和用户组的ldif数据库数据:
http://s1.运维网.com/images/20180922/1537604687986494.png

http://s1.运维网.com/images/20180922/1537604741324019.png
http://s1.运维网.com/images/20180922/1537605976669420.png
六、导入用户和用户组数据到OpenLDAP数据库
http://s1.运维网.com/images/20180922/1537605913680256.png
http://s1.运维网.com/images/20180922/1537606036667757.png
  查询OpenLDAP全部信息:
http://s1.运维网.com/images/20180922/1537606116595062.png
  查询OpenLDAP用户的信息:

http://s1.运维网.com/images/20180922/1537606232616807.png
  查询OpenLDAP的组信息:
http://s1.运维网.com/images/20180922/1537607093304499.png
  关联LDAP与本地的用户和组:

  LDAP中的组和用户实际上是和本地的用户和用户组之间是没有任何关联的。所以需要关联他们。
  #vim add_user_to_groups.ldif

  dn: cn=ldapgroup1,ou=Group,dc=domain,dc=com
changetype: modify
add: memberuid
memberuid: ldapuser1

dn: cn=ldapgroup2,ou=Group,dc=domain,dc=com
changetype: modify
add: memberuid
memberuid: ldapuser2
  生效关联配置文件:

http://s1.运维网.com/images/20180922/1537607622269721.png
  查询ldap中的组,发现已经绑定成功:

http://s1.运维网.com/images/20180922/1537607644219059.png

  安装部署PHPldapAdmin
  安装PHP和Apache:
  
  # yum -y install httpd php php-ldap php-gd php-mbstring php-pear php-bcmath php-xml
  添加下载源:

  ~]# yum -y install epel-release
  安装phpldapadmin:
  # yum --enablerepo=epel -y install phpldapadmin
  修改phpldapadmin配置文件,397行取消注释,398行添加注释:
  # vim /etc/phpldapadmin/config.php
$servers->setValue('login','attr','dn');
// $servers->setValue('login','attr','uid');
http://s1.运维网.com/images/20180922/1537608119253409.png
  修改phpldapadmin权限配置文件:
  # vim /etc/httpd/conf.d/phpldapadmin.conf


# Apache 2.4
Require local
Require ip 192.168.1.0/24


http://s1.运维网.com/images/20180922/1537608286903738.png
  开启Apache服务:

  # systemctl start httpd
  浏览器访问phpldapadmin:
  
  http://(localhost或服务器地址)/phpldapadmin/
    用户名:cn=root,dc=domain,dc=com
    密码:910910
http://s1.运维网.com/images/20180922/1537608264909673.png
http://s1.运维网.com/images/20180922/1537608328896356.png

http://s1.运维网.com/images/20180922/1537608585673784.png
  
  
  总结:domain不能填自己的主机名!我是小白,如有错误还请各位大佬指点!感谢!




页: [1]
查看完整版本: openldap+phpldapadmin(Centos7)