Centos7 安裝配置OpenLdap服務及OpenLdap管理工具

Centos7 安裝配置OpenLdap服務及OpenLdap管理工具php

咱們上一篇文章中介紹了,Centos7+Open***使用Windows AD(LDAP)驗證登陸的配置介紹。說到LDAP服務,咱們知道不止windows有,linux下也有,好比openldap,sambaLDAP服務,具體就很少介紹了,咱們今天主要介紹一下Centos7 安裝配置OpenLdap及Ldap管理工具等操做,爲後面的Centos7+Open***+openldap驗證登陸作好基礎。html

咱們首先配置一個指定源,咱們源地址指向了阿里雲的倉庫源linux

cd /etc/yum.repos.d
vim epel.repo
[epel]
name=aliyun epel
baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
gpgcheck=0

Image

咱們開始安裝openldap服務及客戶端,migrationtools等服務web

migrationtools 實現OpenLDAP 用戶及用戶組的添加,migrationtools 開源工具經過查找/etc/passwd、/etc/shadow、/etc/groups 生成LDIF 文件,並經過ldapadd 命令更新數據庫數據,完成用戶添加數據庫

yum install -y openldap-servers openldap-clients migrationtools

Image

Image

咱們首先要設置openldap的管理員密碼:vim

咱們須要注意的是:必定要記住及拷貝出執行的後的加密的密碼信息。windows

slappasswd
new password:  123456
re-enter new password:123456
{SSHA}pGybT1cAqDtSA910VC/E7v1CJgd6dnl6

Image

cd /etc/openldap/slapd.d/cn\=config/

Image

vi olcDatabase\=\{2\}hdb.ldif
增長一行
olcRootPW: {SSHA}pGybT1cAqDtSA910VC/E7v1CJgd6dnl6
修改域信息
olcSuffix: dc=ixmsoft,dc=com
olcRootDN: cn=Manager,dc=ixmsoft,dc=com

Image

vi olcDatabase\=\{1\}monitor.ldif
修改域信息

Image

slaptest –u

Image

啓動服務bash

systemctl start slapd
systemctl enable slapd

Image

接下來咱們須要建立openldap的數據庫文件app

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

Image

cat /root/base.ldif

Image

Creating users and groups
useradd ldapuser01
useradd ldapuser02

Image

passwd ldapuser01
passwd ldapuser02
或者 echo "redhat" | passwd --stdin ldapuser01

Image

分配全部用戶和組的信息到指定的文件中ide

[root@bogon ~]# grep ":10[0-9][0-9]" /etc/passwd > /root/passwd
[root@bogon ~]# grep ":10[0-9][0-9]" /etc/group > /root/group

Image

ls  /root

Image

cd  /usr/share/migrationtools
vim migrate_common.ph
$DEFAULT_MAIL_DOMAIN = "ixmsoft.com";
$DEFAULT_BASE = "dc=ixmsoft,dc=com";
$EXTENDED_SCHEMA = 1;

Image

保存退出:

如今咱們須要將導出的用戶文件到LDIF文件中

Now Convert the Individual Users file to LDAP Data Interchange Format (LDIF)

./migrate_passwd.pl /root/password

Image

./migrate_group.pl /root/groups /root/groups.ldif

Image

導入用戶到LDAP數據庫

ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/base.ldif

Image(5)

ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/users.ldif

Image(6)

ldapadd -x -W -D "cn=Manager,dc=ixmsoft,dc=com" -f /root/groups.ldif

Image(7)

ldapsearch -x cn=ldapuser01 -b dc=ixmsoft,dc=com

Image(8)

ldapsearch -x -b 'dc=ixmsoft,dc=com' '(objectclass=*)'

Image(9)

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

Image(10)

systemctl enable nfs-server.servic
systemctl start nfs-server.service
systemctl start rpcbind
systemctl enable rpcbind

Image(11)

configure NFS export
vi /etc/exports
/home *(rw,sync)

Image(12)

systemctl restart nfs-server

Image(13)

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

Image(14)

systemctl restart slapd.service
systemctl status slapd.service

Image(15)

接下來咱們就是測試了,咱們準備安裝PHPLdapadmin管理工具進行操做

使用該工具能夠建立用戶及組織,可是使用PHPLdapadmin的前提須要安裝httpd,php

因此咱們先安裝httpd

首先安裝yum install -y httpd

Image(16)

vim /etc/httpd/conf/httpd.conf

Image(17)

firewall-cmd --add-service=http --permanent
firewall-cmd --reload
添加默認頁面
vim /var/www/html/index.html

Image(18)

systemctl start httpd
systemctl enable httpd

Image(19)

Configure httpd to use PHP scripts
Install PHP.
yum -y install php php-mbstring php-pear

Image(20)

vim +878 /etc/php.ini
# line 878: uncomment and add your timezone
date.timezone = "Asia/Shanghai"

Image(21)

systemctl restart httpd

Image(22)

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>

Image(23)

保存退出後,咱們重啓httpd服務

systemctl restart httpd

而後訪問默認的index.php頁面

Image(24)

yum --enablerepo=epel -y install phpldapadmin

Image(25)

vim /etc/phpldapadmin/config.php
# line 397: uncomment, line 398: comment out
$servers->setValue('login','attr','dn');
// $servers->setValue('login','attr','uid');

Image(26)

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網段能夠訪問

Image(27)

systemctl restart httpd

而後咱們訪問:  192.168.5.20/ldapadmin/

Image(28)

單擊登陸,而後經過cn的方式進行登陸

Image(29)

Image(30)

接下來咱們新建一個用戶

Image(31)

選擇默認模板

Image(32)

選擇路勁及建立的用戶類型

Image(33)

填寫用戶已信息

Image(34)

咱們使用命令來查看剛纔新建的用戶

Image(35)

Image(36)

咱們經過命令搜索一下

ldapsearch -x -W -D "cn=manager,dc=ixmsoft,dc=com" -b "ou=people,dc=ixmsoft,dc=com" -h 192.168.5.20

Image(37)

Image(38)

相關文章
相關標籤/搜索