Centos7 安装配置OpenLdap服务及OpenLdap管理工具
我们上一篇文章中介绍了,Centos7+Openvpn使用Windows AD(LDAP)验证登录的配置介绍。说到LDAP服务,我们知道不止windows有,linux下也有,比如openldap,sambaLDAP服务,具体就不多介绍了,我们今天主要介绍一下Centos7 安装配置OpenLdap及Ldap管理工具等操作,为后面的Centos7+Openvpn+openldap验证登录做好基础。
我们首先配置一个指定源,我们源地址指向了阿里云的仓库源
cd /etc/yum.repos.d
vim epel.repo
[epel]
name=aliyun epel
baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
gpgcheck=0
我们开始安装openldap服务及客户端,migrationtools等服务
migrationtools 实现OpenLDAP 用户及用户组的添加,migrationtools 开源工具通过查找/etc/passwd、/etc/shadow、/etc/groups 生成LDIF 文件,并通过ldapadd 命令更新数据库数据,完成用户添加
yum install -y openldap-servers openldap-clients migrationtools
我们首先要设置openldap的管理员密码:
我们需要注意的是:一定要记住及拷贝出执行的后的加密的密码信息。
slappasswd
new password: 123456
re-enter new password:123456
{SSHA}pGybT1cAqDtSA910VC/E7v1CJgd6dnl6
cd /etc/openldap/slapd.d/cn\=config/
vi olcDatabase\=\{2\}hdb.ldif
增加一行
olcRootPW: {SSHA}pGybT1cAqDtSA910VC/E7v1CJgd6dnl6
修改域信息
olcSuffix: dc=ixmsoft,dc=com
olcRootDN: cn=Manager,dc=ixmsoft,dc=com
vi olcDatabase\=\{1\}monitor.ldif
修改域信息
slaptest –u
启动服务
systemctl start slapd
systemctl enable slapd
接下来我们需要创建openldap的数据库文件
vim /root/base.ldif
dn: dc=ixmsoft,dc=com
objectClass: top
objectClass: dcObject
objectclass: organization
o: ixmsoft com
dc: ixmsoft
dn: cn=Manager,dc=ixmsoft,dc=com
objectClass: organizationalRole
cn: Manager
description: Directory Manager
dn: ou=People,dc=ixmsoft,dc=com
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=ixmsoft,dc=com
objectClass: organizationalUnit
ou: Group
cat /root/base.ldif
Creating users and groups
useradd ldapuser01
useradd ldapuser02
passwd ldapuser01
passwd ldapuser02
或者 echo "redhat" | passwd --stdin ldapuser01
分配所有用户和组的信息到指定的文件中
[root@bogon ~]# grep ":10[0-9][0-9]" /etc/passwd > /root/passwd
[root@bogon ~]# grep ":10[0-9][0-9]" /etc/group > /root/group
ls /root
cd /usr/share/migrationtools
vim migrate_common.ph
$DEFAULT_MAIL_DOMAIN = "ixmsoft.com";
$DEFAULT_BASE = "dc=ixmsoft,dc=com";
$EXTENDED_SCHEMA = 1;
保存退出:
现在我们需要将导出的用户文件到LDIF文件中
Now Convert the Individual Users file to LDAP Data Interchange Format (LDIF)
./migrate_passwd.pl /root/password
./migrate_group.pl /root/groups /root/groups.ldif
导入用户到LDAP数据库
ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/base.ldif
ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/users.ldif
ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/groups.ldif
ldapsearch -x cn=ldapuser01 -b dc=ixmsoft,dc=com
ldapsearch -x -b 'dc=ixmsoft,dc=com' '(objectclass=*)'
Allow firewall ports
firewall-cmd --permanent --add-service=ldap
firewall-cmd --permanent --add-service=ldaps
firewall-cmd --reload
Install NFS util packages
yum -y install rpcbind nfs-utils
systemctl enable nfs-server.servic
systemctl start nfs-server.service
systemctl start rpcbind
systemctl enable rpcbind
configure NFS export
vi /etc/exports
/home *(rw,sync)
systemctl restart nfs-server
Enable NFS and it’s supported Firewall ports
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload
showmount -e localhost
systemctl restart slapd.service
systemctl status slapd.service
接下来我们就是测试了,我们准备安装PHPLdapadmin管理工具进行操作
使用该工具可以创建用户及组织,但是使用PHPLdapadmin的前提需要安装httpd,php
所以我们先安装httpd
首先安装yum install -y httpd
vim /etc/httpd/conf/httpd.conf
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
添加默认页面
vim /var/www/html/index.html
systemctl start httpd
systemctl enable httpd
Configure httpd to use PHP scripts
Install PHP.
yum -y install php php-mbstring php-pear
vim +878 /etc/php.ini
# line 878: uncomment and add your timezone
date.timezone = "Asia/Shanghai"
systemctl restart httpd
Create a PHP test page and access to it from client PC with web browser. It's OK if following page is shown.
vim /var/www/html/index.php
<html>
<body>
<div style=" 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php
print Date("Y/m/d");
?>
</div>
</body>
</html>
保存退出后,我们重启httpd服务
systemctl restart httpd
然后访问默认的index.php页面
yum --enablerepo=epel -y install phpldapadmin
vim /etc/phpldapadmin/config.php
# line 397: uncomment, line 398: comment out
$servers->setValue('login','attr','dn');
// $servers->setValue('login','attr','uid');
vim /etc/httpd/conf.d/phpldapadmin.conf
Alias /phpldapadmin /usr/share/phpldapadmin/htdocs
Alias /ldapadmin /usr/share/phpldapadmin/htdocs
<Directory /usr/share/phpldapadmin/htdocs>
<IfModule mod_authz_core.c>
# Apache 2.4
# line 12: add access permission
Require local
Require 192.168.2.0/24 ---- 允许192.168.2.0网段可以访问
systemctl restart httpd
然后我们访问: 192.168.5.20/ldapadmin/
单击登录,然后通过cn的方式进行登录
接下来我们新建一个用户
选择默认模板
选择路劲及创建的用户类型
填写用户已信息
我们使用命令来查看刚才新建的用户
我们通过命令搜索一下
ldapsearch -x -W -D "cn=manager,dc=ixmsoft,dc=com" -b "ou=people,dc=ixmsoft,dc=com" -h 192.168.5.20