环境准备:关闭selinux和firewall 1.安装LDAP服务器和客户端
[root@localhost ~]# yum install -y openldap-servers openldap-clients migrationtools
2.设置openldap管理员密码,根据提示输入密码,会返回加密的密码字符串,保留好这个字符串
[root@localhost ~]# slappasswd
New password:
Re-enter new password:
{SSHA}RRt+8PBxQxuB5xZKCtA+C+J15p8R+FhW
3.修改openldap配置
[root@localhost ~]# rpm -ql openldap #查看安装文件
[root@localhost ~]# rpm -ql openldap-servers
[root@localhost ~]# vi /etc/openldap/slapd.d/cn\=config\/olcDatabase\={2}hdb.ldif
#找到olcSuffix和olcRootDN进行修改为自己设置的dc,在文件末添加设置好的密码
olcSuffix: dc=xls,dc=com
olcRootDN: cn=Manager,dc=xls,dc=com
{SSHA}RRt+8PBxQxuB5xZKCtA+C+J15p8R+FhW
4.更改监控认证配置
[root@localhost ~]# vi /etc/openldap/slapd.d/cn\=config\/olcDatabase\={1}monitor.ldif
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=extern
al,cn=auth" read by dn.base="cn=Manager,dc=xls,dc=com" read by* none
structuralObjectClass: olcDatabaseConfig
5.设置DB Cache
[root@localhost ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
[root@localhost ~]# chown -R ldap:ldap /var/lib/ldap/
6.测试配置文件,末尾显示configfile testing successed 说明成功
[root@localhost ~]# slaptest -u
7.启动OpenLDAP,并设置为开机启动
[root@localhost ~]# systemctl start slapd.service
[root@localhost ~]# systemctl enable slapd.service
8.导入模板
[root@localhost ~]# ls /etc/openldap/schema/*.ldif | xargs -I {} sudo ldapadd -Y EXTERNAL -H ldapi:///
-f {}
9.安装web管理服务
[root@localhost ~]# yum install httpd -y
10.修改配置文件httpd.conf
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf
<Directory /var/www>
AllowOverride all
Require all granted
</Directory>
11.启动服务,测试
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl enable httpd.service
[root@localhost ~]# curl http://127.0.0.1
12.安装phpldapadmin
[root@localhost ~]# yum install phpldapadmin
13.修改配置文件
[root@localhost ~]# vi /etc/phpldapadmin/config.php
#取消以下几行的注释及设置注释
$servers->setValue(‘server’,’host’,’127.0.0.1’);
$servers->setValue(‘server’,’port’,389);
$servers->setValue(‘server’,’base’,array(‘dc=xls,dc=com’));
$servers->setValue(‘login’,’auth_type’,’session’);
$servers->setValue(‘login’,’attr’,’dn’);
#$servers->setValue(‘login’,’attr’,’uid’);
14.修改访问配置文件,允许任意IP访问
[root@localhost ~]# vi /etc/httpd/conf.d/phpldapadmin.conf
Order Deny,Allow #取消注释
15.创建基础目录,在/etc/openldap目录下添加base.ldif文件
[root@localhost ~]# cd /etc/openldap
[root@localhost ~]# vi base.ldif
#添加以下内容
dn:dc=xls,dc=com
objectclass:dcObject
objectclass:organization
o:Example,Inc.
dc:xls
dn:cn=Manager,dc=xls,dc=com
objectclass:organizationalRole
cn:Manager
15.重启httpd服务
[root@localhost ~]# systemctl restart httpd.service
16.执行命令导入数据库,输入设置好的密码
[root@localhost ~]# ldapadd -f base.ldif -x -D cn=Manager,dc=xls,dc=com -W
17.访问web管理端 http://ip/phpldapadmin
登陆用户名:cn=Manager,dc=mypaas,dc=com