Centos 7 集成安裝Apache+PHP+Kerberos+LDAP+phpLDAPadmin

1、安裝Apache

1.一、安裝Apache

Apache程序是目前擁有很高市場佔有率的Web服務程序之一,其跨平臺和安全性普遍被承認且擁有快速、可靠、簡單的API擴展。 它的名字取自美國印第安人土著語,寓意着擁有高超的做戰策略和無窮的耐性,在紅帽RHEL五、六、7系統中一直做爲着默認的Web服務程序而使用,而且也一直是紅帽RHCSA和紅帽RHCE的考試重點內容。Apache服務程序能夠運行在Linux系統、Unix系統甚至是Windows系統中,支持基於IP、域名及端口號的虛擬主機功能、支持多種HTTP認證方式、集成有代理服務器模塊、安全Socket層(SSL)、可以實時監視服務狀態與定製日誌消息,並有着各種豐富的模塊支持。php

Centos7 在安裝部署過程當中,若是選擇了web服務器,是會自動安裝Apache的,若是沒有選擇安裝web服務器模式,則須要手動安裝。html

查看Apache軟件源前端

yum list | grep httpd

過程以下:java

[root@duke ldap]# yum list | grep httpd
httpd.x86_64 2.4.6-80.el7.centos.1 @updates
httpd-tools.x86_64 2.4.6-80.el7.centos.1 @updates
httpd-devel.x86_64 2.4.6-80.el7.centos.1 updates
httpd-manual.noarch 2.4.6-80.el7.centos.1 updates
keycloak-httpd-client-install.noarch 0.6-3.el7 base
libmicrohttpd.i686 0.9.33-2.el7 base
libmicrohttpd.x86_64 0.9.33-2.el7 base
libmicrohttpd-devel.i686 0.9.33-2.el7 base
libmicrohttpd-devel.x86_64 0.9.33-2.el7 base
libmicrohttpd-doc.noarch 0.9.33-2.el7 base
python2-keycloak-httpd-client-install.noarchpython

安裝Apachemysql

yum install httpd -y

過程以下:linux

[root@duke ldap]# yum install httpd -y
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
base                                                                  | 3.6 kB  00:00:00     
extras                                                                | 3.4 kB  00:00:00     
updates                                                               | 3.4 kB  00:00:00     
updates/7/x86_64/primary_db                                           | 6.0 MB  00:00:00     
軟件包 httpd-2.4.6-80.el7.centos.1.x86_64 已安裝而且是最新版本
無須任何處理

啓動Apacheweb

systemctl start httpd

開啓啓動Apachesql

systemctl enable httpd

過程以下:數據庫

[root@duke ldap]# systemctl start httpd
[root@duke ldap]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

1.二、Apache安裝目錄信息

說明
目錄
服務目錄 /etc/httpd
主配置文件 /etc/httpd/conf/httpd.conf
網站數據目錄 /var/www/html
訪問日誌 /var/log/httpd/access_log
錯誤日誌 /var/log/httpd/error_log

1.三、配置Apache

在httpd服務程序主配置文件中最爲經常使用的參數包括有:

參數
說明
ServerRoot 服務目錄
ServerAdmin 管理員郵箱
User 運行服務的用戶
Group 運行服務的用戶組
ServerName 網站服務器的域名
DocumentRoot 網站數據目錄
Listen 監聽的IP地址與端口號
DirectoryIndex 默認的索引頁頁面
ErrorLog 錯誤日誌文件
CustomLog 訪問日誌文件
Timeout 網頁超時時間,默認爲300秒.
Include 須要加載的其餘文件

1.3.一、將「全局服務器名稱」設置爲「禁止語法警告」

1.3.二、調整防火牆以容許Web流量

  1. 打開HTTP和HTTPS端口80和443

    firewall-cmd --permanent --zone=public --add-service=http
    firewall-cmd --permanent --zone=public --add-service=https
    

    過程以下:

    [root@duke ldap]# ufirewall-cmd --permanent --zone=public --add-service=http
    FirewallD is not running
    [root@duke ldap]# ufirewall-cmd --permanent --zone=public --add-service=https
    FirewallD is not running

  2. 關閉防火牆(選擇使用)

    systemctl disable firewall
    systemctl stop firewall
    
  3. 暫時關閉selinux(選擇使用)
    setenforce 0
    
  4. 訪問Apache
    開放防火牆後就能夠嘗試登錄Apache服務器
    登錄 http://192.168.0.2/
    
    界面以下:

1.四、Apache命令

重載配置

systemctl reload httpd

啓動命令

/etc/init.d/httpd start
或
systemctl start httpd

中止命令

/etc/init.d/httpd stop
或
systemctl stop httpd

重啓命令

/etc/init.d/httpd restart
或
systemctl restart httpd

查看版本

httpd -v

2、安裝PHP開發環境

2.一、安裝PHP

yum -y install php php-peer

過程以下:

root@yita-211:/# yum -y install php php-peer
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
軟件包 php-5.4.16-45.el7.x86_64 已安裝而且是最新版本
沒有可用軟件包 php-peer。
無須任何處理

2.二、配置PHP

2.2.一、配置index.html

修改Apache在請求目錄時提供文件的方式。Apache將首先從尋找一個名爲index.html文件改成尋找index.php文件。

vim /etc/httpd/conf/httpd.conf

過程以下:

<IfModule dir_module>
    DirectoryIndex index.html index.php index.html.var
</IfModule>

修改成

<IfModule dir_module>
    DirectoryIndex index.php index.html index.html.var
</IfModule>

重啓Apache

[root@duke ~]# systemctl restart httpd

2.三、安裝PHP加強模塊

2.3.一、查看PHP功能加強列表

 yum search php- | less

過程以下:

[root@duke ~]# yum search php- | less
Loading mirror speeds from cached hostfile
============================== N/S matched: php- ===============================
emacs-php-mode.noarch : Major GNU Emacs mode for editing PHP code
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Enchant spelling extension for PHP applications
php-fpm.x86_64 : PHP FastCGI Process Manager
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-intl.x86_64 : Internationalization extension for PHP applications
php-ldap.x86_64 : A module for PHP applications that use LDAP
php-mbstring.x86_64 : A module for PHP applications which need multi-byte string
: handling
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php-odbc.x86_64 : A module for PHP applications that use ODBC databases
php-pdo.x86_64 : A database access abstraction module for PHP applications
php-pear.noarch : PHP Extension and Application Repository framework
php-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemon
php-pgsql.x86_64 : A PostgreSQL database module for PHP
php-process.x86_64 : Modules for PHP script using system process interfaces
php-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php-recode.x86_64 : A module for PHP applications for using the recode library
php-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php-xml.x86_64 : A module for PHP applications which use XML
php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol

2.3.二、安裝加強功能

通過篩選,選擇安裝php-ldap、php-mbstring

yum install php-ldap php-mbstring

過程以下:

[root@duke ~]# yum install php-ldap php-mbstring
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
軟件包 php-ldap-5.4.16-45.el7.x86_64 已安裝而且是最新版本
軟件包 php-mbstring-5.4.16-45.el7.x86_64 已安裝而且是最新版本
無須任何處理

2.3.三、編輯PHP配置

編輯PHP主配置文件,配置時間區域,命令以下

vim /etc/php.ini

php配置文件使用";" 註釋,在全文搜索 date.timezone字符串,進行以下修改,並將「;」號去掉便可,過程以下:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone = ""

修改成

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Shanghai"

保存,並重啓httpd服務

service httpd restart

2.四、測試PHP服務

2.4.一、添加測試文件

/var/www/html下新建一個info.php文件,用於測試PHP是否配置成功
過程以下:

[root@duke ~]# vi /var/www/html/info.php
<h2>PHP test page:
<html>
<body>
<div style="width: 65%; font-size: 30px; font-weight: bold; text-align: center;">
<?php
  print Date("Y/m/d");
?>
</div>
</body>
</html>
<?php
phpinfo();
?>

2.4.二、測試服務狀態

在瀏覽器中輸入服務器IP便可,以下圖:

3、安裝Kerberos

3.一、清理環境

0.1 中止服務

service krb5kdc stop
service kadmin stop

0.2 卸載程序

yum remove -y krb5-devel, krb5-workstation, krb5-server, krb5-server-ldap

yum install krb5-server-ldap -y

3.二、 安裝kerberos

yum install krb5-server-ldap -y

經過安裝krb5-server-ldap能夠把其餘依賴的軟件包安裝完成

過程以下:

[root@duke yum.repos.d]# yum install krb5-server-ldap -y                                               
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 krb5-server-ldap.x86_64.0.1.15.1-19.el7 將被 安裝
--> 正在處理依賴關係 libkadm5(x86-64) = 1.15.1-19.el7,它被軟件包 krb5-server-ldap-1.15.1-19.el7.x86_64 須要
--> 正在處理依賴關係 krb5-server(x86-64) = 1.15.1-19.el7,它被軟件包 krb5-server-ldap-1.15.1-19.el7.x86_64 須要
--> 正在處理依賴關係 krb5-libs(x86-64) = 1.15.1-19.el7,它被軟件包 krb5-server-ldap-1.15.1-19.el7.x86_64 須要
--> 正在檢查事務
---> 軟件包 krb5-libs.x86_64.0.1.15.1-8.el7 將被 升級
--> 正在處理依賴關係 krb5-libs(x86-64) = 1.15.1-8.el7,它被軟件包 krb5-devel-1.15.1-8.el7.x86_64 須要
--> 正在處理依賴關係 krb5-libs(x86-64) = 1.15.1-8.el7,它被軟件包 krb5-workstation-1.15.1-8.el7.x86_64 須要
---> 軟件包 krb5-libs.x86_64.0.1.15.1-19.el7 將被 更新
---> 軟件包 krb5-server.x86_64.0.1.15.1-19.el7 將被 安裝
---> 軟件包 libkadm5.x86_64.0.1.15.1-8.el7 將被 升級
---> 軟件包 libkadm5.x86_64.0.1.15.1-19.el7 將被 更新
--> 正在檢查事務
---> 軟件包 krb5-devel.x86_64.0.1.15.1-8.el7 將被 升級
---> 軟件包 krb5-devel.x86_64.0.1.15.1-19.el7 將被 更新
---> 軟件包 krb5-workstation.x86_64.0.1.15.1-8.el7 將被 升級
---> 軟件包 krb5-workstation.x86_64.0.1.15.1-19.el7 將被 更新
--> 解決依賴關係完成

依賴關係解決

==================================================================================================================================================================================================================
 Package                                                 架構                                          版本                                                  源                                              大小
==================================================================================================================================================================================================================
正在安裝:
 krb5-server-ldap                                        x86_64                                        1.15.1-19.el7                                         updates                                        191 k
爲依賴而安裝:
 krb5-server                                             x86_64                                        1.15.1-19.el7                                         updates                                        1.0 M
爲依賴而更新:
 krb5-devel                                              x86_64                                        1.15.1-19.el7                                         updates                                        269 k
 krb5-libs                                               x86_64                                        1.15.1-19.el7                                         updates                                        747 k
 krb5-workstation                                        x86_64                                        1.15.1-19.el7                                         updates                                        814 k
 libkadm5                                                x86_64                                        1.15.1-19.el7                                         updates                                        175 k

事務概要
==================================================================================================================================================================================================================
安裝  1 軟件包 (+1 依賴軟件包)
升級           ( 4 依賴軟件包)

總下載量:3.2 M
Downloading packages:
Delta RPMs reduced 2.0 M of updates to 728 k (63% saved)
(1/6): krb5-devel-1.15.1-8.el7_1.15.1-19.el7.x86_64.drpm                                                                                                                                   | 153 kB  00:00:00     
(2/6): krb5-libs-1.15.1-8.el7_1.15.1-19.el7.x86_64.drpm                                                                                                                                    | 214 kB  00:00:00     
(3/6): krb5-workstation-1.15.1-8.el7_1.15.1-19.el7.x86_64.drpm                                                                                                                             | 236 kB  00:00:00     
(4/6): libkadm5-1.15.1-8.el7_1.15.1-19.el7.x86_64.drpm                                                                                                                                     | 126 kB  00:00:00     
(5/6): krb5-server-ldap-1.15.1-19.el7.x86_64.rpm                                                                                                                                           | 191 kB  00:00:00     
(6/6): krb5-server-1.15.1-19.el7.x86_64.rpm                                                                                                                                                | 1.0 MB  00:00:00     
Finishing delta rebuilds of 2 package(s) (989 k)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計                                                                                                                                                                              1.8 MB/s | 1.9 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : krb5-libs-1.15.1-19.el7.x86_64                                                                                                                                                               1/10 
  正在更新    : libkadm5-1.15.1-19.el7.x86_64                                                                                                                                                                2/10 
  正在安裝    : krb5-server-1.15.1-19.el7.x86_64                                                                                                                                                             3/10 
  正在安裝    : krb5-server-ldap-1.15.1-19.el7.x86_64                                                                                                                                                        4/10 
  正在更新    : krb5-devel-1.15.1-19.el7.x86_64                                                                                                                                                              5/10 
  正在更新    : krb5-workstation-1.15.1-19.el7.x86_64                                                                                                                                                        6/10 
  清理        : krb5-workstation-1.15.1-8.el7.x86_64                                                                                                                                                         7/10 
  清理        : krb5-devel-1.15.1-8.el7.x86_64                                                                                                                                                               8/10 
  清理        : libkadm5-1.15.1-8.el7.x86_64                                                                                                                                                                 9/10 
  清理        : krb5-libs-1.15.1-8.el7.x86_64                                                                                                                                                               10/10 
  驗證中      : krb5-devel-1.15.1-19.el7.x86_64                                                                                                                                                              1/10 
  驗證中      : krb5-server-1.15.1-19.el7.x86_64                                                                                                                                                             2/10 
  驗證中      : krb5-workstation-1.15.1-19.el7.x86_64                                                                                                                                                        3/10 
  驗證中      : libkadm5-1.15.1-19.el7.x86_64                                                                                                                                                                4/10 
  驗證中      : krb5-libs-1.15.1-19.el7.x86_64                                                                                                                                                               5/10 
  驗證中      : krb5-server-ldap-1.15.1-19.el7.x86_64                                                                                                                                                        6/10 
  驗證中      : krb5-devel-1.15.1-8.el7.x86_64                                                                                                                                                               7/10 
  驗證中      : krb5-workstation-1.15.1-8.el7.x86_64                                                                                                                                                         8/10 
  驗證中      : krb5-libs-1.15.1-8.el7.x86_64                                                                                                                                                                9/10 
  驗證中      : libkadm5-1.15.1-8.el7.x86_64                                                                                                                                                                10/10 

已安裝:
  krb5-server-ldap.x86_64 0:1.15.1-19.el7                                                                                                                                                                         

做爲依賴被安裝:
  krb5-server.x86_64 0:1.15.1-19.el7                                                                                                                                                                              

做爲依賴被升級:
  krb5-devel.x86_64 0:1.15.1-19.el7                  krb5-libs.x86_64 0:1.15.1-19.el7                  krb5-workstation.x86_64 0:1.15.1-19.el7                  libkadm5.x86_64 0:1.15.1-19.el7                 

完畢!

【注意】:安裝好kerberos後不要急於配置,先安裝配置LDAP後在配置kerberos會比較好

3.三、安裝cyrus-sasl

執行命令:

yum install cyrus-sasl-gssapi cyrus-sasl-plain cyrus-sasl cyrus-sasl-scram cyrus-sasl-lib cyrus-sasl-md5

【注意】:不要安裝cyrus-sasl-ldap,不然ldap啓動會出錯

執行過程:

[root@duke yum.repos.d]# yum install cyrus-sasl-gssapi cyrus-sasl-plain cyrus-sasl cyrus-sasl-scram cyrus-sasl-lib cyrus-sasl-md5
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 cyrus-sasl.x86_64.0.2.1.26-21.el7 將被 升級
---> 軟件包 cyrus-sasl.x86_64.0.2.1.26-23.el7 將被 更新
---> 軟件包 cyrus-sasl-gssapi.x86_64.0.2.1.26-21.el7 將被 升級
---> 軟件包 cyrus-sasl-gssapi.x86_64.0.2.1.26-23.el7 將被 更新
---> 軟件包 cyrus-sasl-lib.x86_64.0.2.1.26-21.el7 將被 升級
---> 軟件包 cyrus-sasl-lib.x86_64.0.2.1.26-23.el7 將被 更新
---> 軟件包 cyrus-sasl-md5.x86_64.0.2.1.26-21.el7 將被 升級
---> 軟件包 cyrus-sasl-md5.x86_64.0.2.1.26-23.el7 將被 更新
---> 軟件包 cyrus-sasl-plain.x86_64.0.2.1.26-21.el7 將被 升級
---> 軟件包 cyrus-sasl-plain.x86_64.0.2.1.26-23.el7 將被 更新
---> 軟件包 cyrus-sasl-scram.x86_64.0.2.1.26-21.el7 將被 升級
---> 軟件包 cyrus-sasl-scram.x86_64.0.2.1.26-23.el7 將被 更新
--> 解決依賴關係完成

依賴關係解決

==================================================================================================================================================================================================================
 Package                                                  架構                                          版本                                                    源                                           大小
==================================================================================================================================================================================================================
正在更新:
 cyrus-sasl                                               x86_64                                        2.1.26-23.el7                                           base                                         88 k
 cyrus-sasl-gssapi                                        x86_64                                        2.1.26-23.el7                                           base                                         41 k
 cyrus-sasl-lib                                           x86_64                                        2.1.26-23.el7                                           base                                        155 k
 cyrus-sasl-md5                                           x86_64                                        2.1.26-23.el7                                           base                                         57 k
 cyrus-sasl-plain                                         x86_64                                        2.1.26-23.el7                                           base                                         39 k
 cyrus-sasl-scram                                         x86_64                                        2.1.26-23.el7                                           base                                         43 k

事務概要
==================================================================================================================================================================================================================
升級  6 軟件包

總下載量:423 k
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for base
(1/6): cyrus-sasl-2.1.26-23.el7.x86_64.rpm                                                                                                                                                 |  88 kB  00:00:00     
(2/6): cyrus-sasl-gssapi-2.1.26-23.el7.x86_64.rpm                                                                                                                                          |  41 kB  00:00:00     
(3/6): cyrus-sasl-md5-2.1.26-23.el7.x86_64.rpm                                                                                                                                             |  57 kB  00:00:00     
(4/6): cyrus-sasl-lib-2.1.26-23.el7.x86_64.rpm                                                                                                                                             | 155 kB  00:00:00     
(5/6): cyrus-sasl-plain-2.1.26-23.el7.x86_64.rpm                                                                                                                                           |  39 kB  00:00:00     
(6/6): cyrus-sasl-scram-2.1.26-23.el7.x86_64.rpm                                                                                                                                           |  43 kB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計                                                                                                                                                                              1.5 MB/s | 423 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : cyrus-sasl-lib-2.1.26-23.el7.x86_64                                                                                                                                                          1/12 
  正在更新    : cyrus-sasl-md5-2.1.26-23.el7.x86_64                                                                                                                                                          2/12 
  正在更新    : cyrus-sasl-plain-2.1.26-23.el7.x86_64                                                                                                                                                        3/12 
  正在更新    : cyrus-sasl-2.1.26-23.el7.x86_64                                                                                                                                                              4/12 
  正在更新    : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64                                                                                                                                                       5/12 
  正在更新    : cyrus-sasl-scram-2.1.26-23.el7.x86_64                                                                                                                                                        6/12 
  清理        : cyrus-sasl-scram-2.1.26-21.el7.x86_64                                                                                                                                                        7/12 
  清理        : cyrus-sasl-gssapi-2.1.26-21.el7.x86_64                                                                                                                                                       8/12 
  清理        : cyrus-sasl-2.1.26-21.el7.x86_64                                                                                                                                                              9/12 
  清理        : cyrus-sasl-plain-2.1.26-21.el7.x86_64                                                                                                                                                       10/12 
  清理        : cyrus-sasl-md5-2.1.26-21.el7.x86_64                                                                                                                                                         11/12 
  清理        : cyrus-sasl-lib-2.1.26-21.el7.x86_64                                                                                                                                                         12/12 
  驗證中      : cyrus-sasl-md5-2.1.26-23.el7.x86_64                                                                                                                                                          1/12 
  驗證中      : cyrus-sasl-plain-2.1.26-23.el7.x86_64                                                                                                                                                        2/12 
  驗證中      : cyrus-sasl-2.1.26-23.el7.x86_64                                                                                                                                                              3/12 
  驗證中      : cyrus-sasl-lib-2.1.26-23.el7.x86_64                                                                                                                                                          4/12 
  驗證中      : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64                                                                                                                                                       5/12 
  驗證中      : cyrus-sasl-scram-2.1.26-23.el7.x86_64                                                                                                                                                        6/12 
  驗證中      : cyrus-sasl-scram-2.1.26-21.el7.x86_64                                                                                                                                                        7/12 
  驗證中      : cyrus-sasl-gssapi-2.1.26-21.el7.x86_64                                                                                                                                                       8/12 
  驗證中      : cyrus-sasl-md5-2.1.26-21.el7.x86_64                                                                                                                                                          9/12 
  驗證中      : cyrus-sasl-plain-2.1.26-21.el7.x86_64                                                                                                                                                       10/12 
  驗證中      : cyrus-sasl-lib-2.1.26-21.el7.x86_64                                                                                                                                                         11/12 
  驗證中      : cyrus-sasl-2.1.26-21.el7.x86_64                                                                                                                                                             12/12 

更新完畢:
  cyrus-sasl.x86_64 0:2.1.26-23.el7         cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7   cyrus-sasl-lib.x86_64 0:2.1.26-23.el7   cyrus-sasl-md5.x86_64 0:2.1.26-23.el7   cyrus-sasl-plain.x86_64 0:2.1.26-23.el7  
  cyrus-sasl-scram.x86_64 0:2.1.26-23.el7  

完畢!

4、安裝openLDAP

4.一、卸載OpenLDAP

0.1 中止服務

service slapd stop

0.2 卸載程序

yum remove -y openldap-servers openldap-devel openldap-clients compat-openldap

0.3 備份文件
若是不是第一次安裝,有部分文件是須要備份的,不然在第二次安裝時,將不會被安裝,第二次安裝時,須要將下面備份文件進行恢復

mkdir -p /etc/openldap_bak
cp -r /etc/openldap/certs/ /etc/openldap_bak
cp /etc/openldap/ldap.conf /etc/openldap_bak

0.4 刪除文件

rm -rf /etc/openldap

4.1.安裝openLDAP

執行命令:

yum install openldap-clients openldap-servers openldap-devel compat-openldap -y

過程以下:

[root@duke yum.repos.d]# yum install openldap-clients openldap-servers openldap-devel compat-openldap -y  
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
軟件包 1:compat-openldap-2.3.43-5.el7.x86_64 已安裝而且是最新版本
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 openldap-clients.x86_64.0.2.4.44-15.el7_5 將被 安裝
--> 正在處理依賴關係 openldap(x86-64) = 2.4.44-15.el7_5,它被軟件包 openldap-clients-2.4.44-15.el7_5.x86_64 須要
---> 軟件包 openldap-devel.x86_64.0.2.4.44-15.el7_5 將被 安裝
--> 正在處理依賴關係 cyrus-sasl-devel(x86-64),它被軟件包 openldap-devel-2.4.44-15.el7_5.x86_64 須要
---> 軟件包 openldap-servers.x86_64.0.2.4.44-15.el7_5 將被 安裝
--> 正在檢查事務
---> 軟件包 cyrus-sasl-devel.x86_64.0.2.1.26-23.el7 將被 安裝
---> 軟件包 openldap.x86_64.0.2.4.44-5.el7 將被 升級
---> 軟件包 openldap.x86_64.0.2.4.44-15.el7_5 將被 更新
--> 解決依賴關係完成

依賴關係解決

==================================================================================================================================================================================================================
 Package                                                架構                                         版本                                                     源                                             大小
==================================================================================================================================================================================================================
正在安裝:
 openldap-clients                                       x86_64                                       2.4.44-15.el7_5                                          updates                                       190 k
 openldap-devel                                         x86_64                                       2.4.44-15.el7_5                                          updates                                       803 k
 openldap-servers                                       x86_64                                       2.4.44-15.el7_5                                          updates                                       2.2 M
爲依賴而安裝:
 cyrus-sasl-devel                                       x86_64                                       2.1.26-23.el7                                            base                                          310 k
爲依賴而更新:
 openldap                                               x86_64                                       2.4.44-15.el7_5                                          updates                                       355 k

事務概要
==================================================================================================================================================================================================================
安裝  3 軟件包 (+1 依賴軟件包)
升級           ( 1 依賴軟件包)

總下載量:3.8 M
Downloading packages:
Delta RPMs reduced 355 k of updates to 175 k (50% saved)
(1/5): openldap-2.4.44-5.el7_2.4.44-15.el7_5.x86_64.drpm                                                                                                                                   | 175 kB  00:00:00     
(2/5): openldap-clients-2.4.44-15.el7_5.x86_64.rpm                                                                                                                                         | 190 kB  00:00:00     
(3/5): cyrus-sasl-devel-2.1.26-23.el7.x86_64.rpm                                                                                                                                           | 310 kB  00:00:00     
(4/5): openldap-devel-2.4.44-15.el7_5.x86_64.rpm                                                                                                                                           | 803 kB  00:00:00     
(5/5): openldap-servers-2.4.44-15.el7_5.x86_64.rpm                                                                                                                                         | 2.2 MB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計                                                                                                                                                                              8.1 MB/s | 3.6 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : openldap-2.4.44-15.el7_5.x86_64                                                                                                                                                               1/6 
  正在安裝    : cyrus-sasl-devel-2.1.26-23.el7.x86_64                                                                                                                                                         2/6 
  正在安裝    : openldap-devel-2.4.44-15.el7_5.x86_64                                                                                                                                                         3/6 
  正在安裝    : openldap-servers-2.4.44-15.el7_5.x86_64                                                                                                                                                       4/6 
  正在安裝    : openldap-clients-2.4.44-15.el7_5.x86_64                                                                                                                                                       5/6 
  清理        : openldap-2.4.44-5.el7.x86_64                                                                                                                                                                  6/6 
  驗證中      : openldap-servers-2.4.44-15.el7_5.x86_64                                                                                                                                                       1/6 
  驗證中      : openldap-clients-2.4.44-15.el7_5.x86_64                                                                                                                                                       2/6 
  驗證中      : openldap-devel-2.4.44-15.el7_5.x86_64                                                                                                                                                         3/6 
  驗證中      : cyrus-sasl-devel-2.1.26-23.el7.x86_64                                                                                                                                                         4/6 
  驗證中      : openldap-2.4.44-15.el7_5.x86_64                                                                                                                                                               5/6 
  驗證中      : openldap-2.4.44-5.el7.x86_64                                                                                                                                                                  6/6 

已安裝:
  openldap-clients.x86_64 0:2.4.44-15.el7_5                             openldap-devel.x86_64 0:2.4.44-15.el7_5                             openldap-servers.x86_64 0:2.4.44-15.el7_5                            

做爲依賴被安裝:
  cyrus-sasl-devel.x86_64 0:2.1.26-23.el7                                                                                                                                                                         

做爲依賴被升級:
  openldap.x86_64 0:2.4.44-15.el7_5                                                                                                                                                                               

完畢!

4.二、查看安裝的版本

4.2.一、查看kerberos

rpm -qa krb5-server-ldap

執行過程以下:

[root@hzw ~]# rpm -qa krb5-server-ldap
krb5-server-ldap-1.15.1-19.el7.x86_64

4.2.一、查看OpenLDAP

rpm -qa openldap

執行過程以下:

[root@hzw ~]# rpm -qa openldap
openldap-2.4.44-15.el7_5.x86_64

4.三、打開防火牆上的LDAP端口

LDAP服務器已配置並運行。 打開防火牆上的LDAP端口,以便外部客戶端能夠鏈接:

systemctl disable firewall
systemctl stop firewall

4.四、測試LDAP鏈接

測試與ldapwhoami的LDAP鏈接,該鏈接應該返回咱們鏈接的用戶名:

ldapwhoami -H ldap:// -x

[root@duke ~]# ldapwhoami -H ldap:// -x
anonymous

4.五、檢查安裝狀態

ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config dn

過程以下:

[root@duke ~]# ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config dn
dn: cn=config

dn: cn=module{0},cn=config

dn: cn=schema,cn=config

dn: cn={0}core,cn=schema,cn=config

dn: cn={1}cosine,cn=schema,cn=config

dn: cn={2}nis,cn=schema,cn=config

dn: cn={3}inetorgperson,cn=schema,cn=config

dn: olcBackend={0}mdb,cn=config

dn: olcDatabase={-1}frontend,cn=config

dn: olcDatabase={0}config,cn=config

dn: olcDatabase={1}mdb,cn=config

內容說明:

配置項
說明
cn=config 全局配置
cn=module{0},cn=config 一個動態加載的模塊
cn=schema,cn=config 包含硬編碼的系統級模式
cn={0}core,cn=schema,cn=config 硬編碼內核模式
cn={1}cosine,cn=schema,cn=config cosine 模式
cn={2}nis,cn=schema,cn=config nis 模式
cn={3}inetorgperson,cn=schema,cn=config inetorgperson模式
olcBackend={0}mdb,cn=config 後端,mdb存儲數據庫
olcDatabase={-1}frontend,cn=config 前端數據庫,默認設置爲其餘數據庫
olcDatabase={0}config,cn=config slapd配置數據庫(cn = config)
olcDatabase={1}mdb,cn=config 你的數據庫實例 (dc=example,dc=com)

4.六、LDAP操做(知識點,非環境搭建內容)

此時LDAP只有cn=admin,dc=example,dc=com這個用戶存在(第五章節會說明),此時LDAP尚未真正可以進行使用,只是一個空的平臺。因此須要進行節點、用戶存儲、組存儲、用戶等信息的建立。
該章節會針對這些進行相關說明,該內容是知識點,不是部署重要環節,若是隻是部署環境,能夠跳過該章節,在「第六章」會作部署整合相關的內容說明。

4.6.一、變動數據庫

爲了LDAP可以真正使用,還須要建立如下內容:

序列 分類 名稱
說明
1 用戶節點 People 一個存儲用戶信息的節點,用戶信息都會存儲在該節點,例如:han
2 組節點 Groups 一個存儲組信息的節點,組信息都會存儲在該節點,例如:LDAPGroup
3 LDAPGroup 建立一個LDAP的用戶組
4 用戶 han 建立一個屬於LDAPGroup組的用戶

操做過程以下:

  • 建立一個LDIF文件,該文件用於建立上面表單中的內容,文件能夠叫ldap_init.ldif

    root@yita-211:~# cd /home/
    root@yita-211:/home# mkdir ldap
    root@yita-211:/home# cd ldap
    root@yita-211:/home# vi ldap_init.ldif

  • ldap_init.ldif文件中添加如下內容

    dn: ou=people,dc=example,dc=com
    objectClass: organizationalUnit
    ou: people
    
    dn: ou=Groups,dc=example,dc=com
    objectClass: organizationalUnit
    ou: Groups
    
    dn: cn=LDAPGroup,ou=Groups,dc=example,dc=com
    objectClass: posixGroup
    cn: LDAPGroup
    gidNumber: 5000
    
    dn: uid=han,ou=people,dc=example,dc=com
    objectClass: inetOrgPerson
    objectClass: posixAccount
    objectClass: shadowAccount
    uid: han
    sn: zhiwei
    givenName: Han
    cn: Han ZhiWei
    displayName: Han ZhiWei
    uidNumber: 10000
    gidNumber: 5000
    userPassword: hanzhiwei
    gecos: Han ZhiWei
    loginShell: /bin/bash
    homeDirectory: /home/ldap/han
    
    【注意】:文件中的 uidNumbergidNumber這2個值不能和系統中的已經存在的值衝突,因此最好採用高數值來進行區分。
    相關的值能夠在 /etc/passwd/etc/group文件中進行查詢
  • 將用戶信息加入到LDAP中
    ldapadd -x -D cn=admin,dc=example,dc=com -W -f ldap_init.ldif
    
    過程以下:

    root@yita-211:/home/ldap# ls
    ldap_init.ldif
    root@yita-211:/home/ldap# ldapadd -x -D cn=admin,dc=example,dc=com -W -f ldap_init.ldif
    Enter LDAP Password:
    adding new entry "ou=people,dc=example,dc=com"

    adding new entry "ou=Groups,dc=example,dc=com"

    adding new entry "cn=LDAPGroup,ou=Groups,dc=example,dc=com"

    adding new entry "uid=han,ou=people,dc=example,dc=com"

4.6.二、檢查節點、組、用戶是否添加正確

ldapsearch -x -LLL -b dc=example,dc=com 'uid=han' cn gidNumber

過程以下:

root@yita-211:/home/ldap# ldapsearch -x -LLL -b dc=example,dc=com 'uid=han' cn gidNumber
dn: uid=han,ou=people,dc=example,dc=com
cn: Han ZhiWei
gidNumber: 5000

指令說明:

參數
說明
-x 「簡單」綁定; 不會使用默認的SASL方法
-LLL 禁用打印無關信息
uid=han 用於查找han用戶的「過濾器」
cn gidNumber 請求顯示某些屬性(默認爲顯示全部屬性)

4.6.三、增長支持的模式(add schema)

默認狀況下安裝完LDAP是隻支持 cosine、nis、inetorgperson 這3種模式,若是要新增就須要自行添加,例如:本文所要涉及的kerberos。

因爲後續第6章節,須要講述kerberos和LDAP的整合,其中會涉及到在LDAP中增長kerberos模式,因此此處就再也不贅述。相關知識點,請直接查看6.一、LDAP增長kerberos模式(schema)章節

5、安裝和配置phpLDAPadmin Web界面

5.一、下載安裝phpLDAPadmin

5.1.一、下載phpLDAPadmin

http://sourceforge.net/projects/phpldapadmin/files/phpldapadmin-php5/1.2.3/phpldapadmin-1.2.3.zip/download

5.1.二、安裝phpLDAPadmin

將下載的phpldapadmin-1.2.3.zip上傳到服務器,執行如下命令

unzip phpldapadmin-1.2.3.zip 
mv phpldapadmin-1.2.3 /var/www/html/phpldapadmin

5.二、配置phpLDAPadmin

安裝phpLDAPadmin應用程序,啓用必要的Apache配置,並從新加載Apache。
Web服務器配置爲提供應用程序,須要進行一些更改。 須要將phpLDAPadmin配置爲使用的域,而不是自動填充LDAP登陸信息。
須要修改/etc/phpldapadmin/config.php配置文件

cd /var/www/html/phpldapadmin
cp config.php.example config.php.example.bak
mv config.php.example config.php
vim /var/www/html/phpldapadmin/config/config.php
  1. 配置LDAP服務器--標識

    找到 $servers->setValue('server','name','My LDAP Server'); 這一行,修改第三個參數,以下:
    $servers->setValue('server','name','YITA LDAP Server');

  2. 配置LDAP服務器--IP

    找到 $servers->setValue('server','host','127.0.0.1'); 這一行,修改第三個參數,以下:
    $servers->setValue('server','host','192.168.0.2');

  3. 配置LDAP服務器--域名
    【注意】:
    該配置告訴phpLDAPadmin LDAP層次結構的根目錄,這是基於從新配置slapd包時輸入的值。
    前面slapd配置是example,所以在這裏配置example.com
    須要將每一個域組件(不是一個點)放入dc= notation中將其轉換爲LDAP語法

    找到 $servers->setValue('server','base',array('dc=example,dc=com')); 這一行,修改第三個參數,以下:
    $servers->setValue('server','base',array('dc=example,dc=com'));

  4. 配置LDAP服務器--端口
    默認是不配置的,只需將去掉註釋便可

    找到 //$servers->setValue('server','port',389); 這一行,去掉註釋,以下:
    $servers->setValue('server','port',389);

  5. 配置LDAP服務器--其餘服務器
    【注意】:
    若是隻是本機使用LDAP,不使用其餘服務器的話,請註釋下面配置。
    到文件最後部分,找到下面內容,其後的全部參數均註釋掉。

     **************************************************************************
     * If you want to configure additional LDAP servers, do so below.         *
     * Remove the commented lines and use this section as a template for all  *
     * your other LDAP servers.                                               *
     **************************************************************************
    

    註釋內容以下:

    /*
    $servers->newServer('ldap_pla');
    $servers->setValue('server','name','LDAP Server');
    $servers->setValue('server','host','192.168.0.2');
    $servers->setValue('server','port',389);
    $servers->setValue('server','base',array('dc=example,dc=com'));
    $servers->setValue('login','auth_type','cookie');
    $servers->setValue('login','bind_id','');
    $servers->setValue('login','bind_pass','');
    $servers->setValue('server','tls',false);
    
    # SASL auth
    $servers->setValue('login','auth_type','sasl');
    $servers->setValue('sasl','mech','GSSAPI');
    $servers->setValue('sasl','realm','EXAMPLE.COM');
    $servers->setValue('sasl','authz_id',null);
    $servers->setValue('sasl','authz_id_regex','/^uid=([^,]+)(.+)/i');
    $servers->setValue('sasl','authz_id_replacement','$1');
    $servers->setValue('sasl','props',null);
    
    $servers->setValue('appearance','password_hash','md5');
    $servers->setValue('login','attr','dn');
    $servers->setValue('login','fallback_dn',false);
    $servers->setValue('login','class',null);
    $servers->setValue('server','read_only',false);
    $servers->setValue('appearance','show_create',true);
    
    $servers->setValue('auto_number','enable',true);
    $servers->setValue('auto_number','mechanism','search');
    $servers->setValue('auto_number','search_base',null);
    $servers->setValue('auto_number','min',array('uidNumber'=>1000,'gidNumber'=>500));
    $servers->setValue('auto_number','dn',null);
    $servers->setValue('auto_number','pass',null);
    
    $servers->setValue('login','anon_bind',true);
    $servers->setValue('custom','pages_prefix','custom_');
    $servers->setValue('unique','attrs',array('mail','uid','uidNumber'));
    $servers->setValue('unique','dn',null);
    $servers->setValue('unique','pass',null);
    
    $servers->setValue('server','visible',true);
    $servers->setValue('login','timeout',30);
    $servers->setValue('server','branch_rename',false);
    $servers->setValue('server','custom_sys_attrs',array('passwordExpirationTime','passwordAllowChangeTime'));
    $servers->setValue('server','custom_attrs',array('nsRoleDN','nsRole','nsAccountLock'));
    $servers->setValue('server','force_may',array('uidNumber','gidNumber','sambaSID'));
    */
    

5.三、登錄phpLDAPadmin

此時phpldapadmin能夠訪問但可能不能登陸,這個和系統SELinux有關,若是SELinux關閉的話登陸時候會有一個錯誤:

error Unable to connect to LDAP server Cloud-Lab.Com
error: Can't contact LDAP server (-1) for user
error Failed to Authenticate to server

Invalid Username or Password.

打開下面配置便可,操做過程以下:

[root@localhost ~]# getsebool httpd_can_connect_ldap
httpd_can_connect_ldap --> off
[root@localhost ~]# setsebool -P httpd_can_connect_ldap on
[root@localhost ~]# getsebool httpd_can_connect_ldap
httpd_can_connect_ldap --> on

在登陸前,必須保證用戶電腦和LDAP服務器同屬於一個域當中,並配置hosts文件。
例子:以中興環境爲例

說明 IP地址
LDAP服務器 192.168.0.2
用戶電腦 10.47.101.24
網關 10.47.101.1

登錄地址以下:

http://duke.com/phpldapadmin

若是沒有配置hosts文件,也能夠直接使用IP地址進行登陸:

http://192.168.0.2/phpldapadmin

登錄頁面以下:

用戶登陸:
點擊頁面左側登陸按鈕後,頁面以下:

 

登陸DN是您將要使用的用戶名。
包含:賬戶名稱做爲cn=部分,服務器選擇的域名分爲dc=部分,在安裝過程當中設置的默認管理員賬戶稱爲admin ,所以在咱們的示例中,咱們將鍵入如下內容:

cn=admin,dc=example,dc=com

設置頁面以下:

登陸成功後頁面以下:

6、kerberos和LDAP整合配置

6.一、配置LDAP的HDB庫

rm -rf /var/lib/ldap/*
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown -R ldap.ldap /var/lib/ldap
【注意】:
一、在2.4之前的版本中,OpenLDAP 使用 slapd.conf 配置文件來進行服務器的配置
二、2.4開始則使用 slapd.d 目錄保存細分後的各類配置,其數據存儲位置即目錄 /etc/openldap/slapd.d
三、儘管數據文件是透明格式的,仍是建議使用 ldapadd, ldapdelete, ldapmodify 等命令來修改,而不是直接編輯。

6.二、LDAP增長kerberos模式(schema)

存在2中添加方式

6.2.一、LDAP增長kerberos schema文件

解壓kerberos.schema.gz,添加到LDAP的schema存儲目錄

gzip -d /usr/share/doc/krb5-kdc-ldap/kerberos.schema.gz
cp /usr/share/doc/krb5-kdc-ldap/kerberos.schema /etc/ldap/schema/

6.2.二、LDAP增長kerberos模式一(該模式是2.4版本後官方推薦方法)

  • 新建一個schema轉換文件:kerberos_schema_convert.conf
    vim kerberos_schema_convert.conf
    
  • kerberos_schema_convert.conf文件中添加如下內容:
    include /etc/openldap/schema/core.schema
    include /etc/openldap/schema/collective.schema
    include /etc/openldap/schema/corba.schema
    include /etc/openldap/schema/cosine.schema
    include /etc/openldap/schema/duaconf.schema
    include /etc/openldap/schema/dyngroup.schema
    include /etc/openldap/schema/inetorgperson.schema
    include /etc/openldap/schema/java.schema
    include /etc/openldap/schema/misc.schema
    include /etc/openldap/schema/nis.schema
    include /etc/openldap/schema/openldap.schema
    include /etc/openldap/schema/ppolicy.schema
    include /etc/openldap/schema/kerberos.schema
    
  • 建立一個臨時目錄來存放LDIF文件
    mkdir -p /home/ldap/tmp
    
  • 使用slapcat來轉換schema文件
    slapcat -f kerberos_schema_convert.conf -F /home/ldap/tmp -n0 -s "cn={12}kerberos,cn=schema,cn=config" > /home/ldap/tmp/cn=kerberos.ldif
    
    【注意】:cn={12}kerberos中的{12}
    指的是kerberos_schema_convert.conf文件中「include /etc/openldap/schema/kerberos.schema」信息位置的序號
    而且須要(序號-1),序號是以0爲起始位

    過程以下:

    [root@duke ldap]# slapcat -f kerberos_schema_convert.conf -F /home/ldap/tmp -n0 -s "cn={12}kerberos,cn=schema,cn=config" > /home/ldap/tmp/cn=kerberos.ldif
    [root@duke ldap]# cd tmp
    [root@duke tmp]# ls
    cn=config cn=config.ldif cn=kerberos.ldif
    [root@duke ldap]# cat cn\=kerberos.ldif

    dn: cn={12}kerberos,cn=schema,cn=config
    objectClass: olcSchemaConfig
    cn: {12}kerberos
    olcAttributeTypes: {0}( 2.16.840.1.113719.1.301.4.1.1 NAME 'krbPrincipalName
    ' EQUALITY caseExactIA5Match SUBSTR caseExactSubstringsMatch SYNTAX 1.3.6.1
    .4.1.1466.115.121.1.26 )
    olcAttributeTypes: {1}( 1.2.840.113554.1.4.1.6.1 NAME 'krbCanonicalName' EQU
    ALITY caseExactIA5Match SUBSTR caseExactSubstringsMatch SYNTAX 1.3.6.1.4.1.
    1466.115.121.1.26 SINGLE-VALUE )
    ......
    olcObjectClasses: {11}( 2.16.840.1.113719.1.301.6.17.1 NAME 'krbTicketPolicy
    ' SUP top STRUCTURAL MUST cn )
    structuralObjectClass: olcSchemaConfig
    entryUUID: 84374308-66be-1038-8430-576d5315da4e
    creatorsName: cn=config
    createTimestamp: 20181018011141Z
    entryCSN: 20181018011141.878509Z#000000#000#000000
    modifiersName: cn=config
    modifyTimestamp: 20181018011141Z

  • 編輯生成的/home/ldap/tmp/cn=kerberos.ldif文件,修改其中屬性,刪除如下不須要的部分,這部分屬性可能不會同樣,每次生成的value是確定不同,根據狀況刪除
    structuralObjectClass: olcSchemaConfig
    entryUUID: 84374308-66be-1038-8430-576d5315da4e
    creatorsName: cn=config
    createTimestamp: 20181018011141Z
    entryCSN: 20181018011141.878509Z#000000#000#000000
    modifiersName: cn=config
    modifyTimestamp: 20181018011141Z
    
  • 用ldapadd加載新的schema
    ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /home/ldap/tmp/cn=kerberos.ldif
    
  • 查看是否加載成功
    ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config dn
    
    過程以下:

    [root@duke ldap]# ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config dn
    dn: cn=schema,cn=config
    dn: cn={0}core,cn=schema,cn=config
    dn: cn={1}cosine,cn=schema,cn=config
    dn: cn={2}nis,cn=schema,cn=config
    dn: cn={3}inetorgperson,cn=schema,cn=config
    dn: cn={4}kerberos,cn=schema 新增長成功的keberos模式

6.2.二、LDAP增長kerberos模式二(該模式是2.4版本前方法,2.4以後版本也能夠用)推薦

【注意】:
一、openldap在第一次安裝完成後,/etc/openldap/目錄會有如下文件

certs check_password.conf ldap.conf schema slapd.d

二、若是卸載openLDAP,並刪除/etc/openldap/目錄下全部內容,在第二次安裝時,會少如下內容

certs ldap.conf

三、須要備份certs和ldap.conf的內容,不然會致使openLDAP沒法正常啓動

6.2.2.一、備份相關文件

mkdir /etc/openldap/bak
cp -r /etc/openldap/certs/ /etc/openldap/bak
cp /etc/openldap/ldap.conf /etc/openldap/bak
cp -rf /etc/openldap/slapd.d /etc/openldap/slapd.d.bak

6.2.2.二、配置增長kerberos.schema

一、增長kerberos.schema配置文件到openLDAP

cp /usr/share/doc/krb5-server-ldap-1.15.1/kerberos.schema /etc/openldap/schema/

二、配置openLDAP的配置文件

touch /etc/openldap/slapd.conf

cat >> /etc/openldap/slapd.conf <<EOF 
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/corba.schema
include /etc/openldap/schema/duaconf.schema
include /etc/openldap/schema/dyngroup.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/java.schema
include /etc/openldap/schema/misc.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/openldap.schema
include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/collective.schema
include /etc/openldap/schema/kerberos.schema

pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args

EOF

三、更新配置

slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
chown -R ldap:ldap /etc/openldap/slapd.d && chmod -R 700 /etc/openldap/slapd.d

過程以下:

[root@duke openldap]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
config file testing succeeded
[root@duke openldap]# chown -R ldap:ldap /etc/openldap/slapd.d && chmod -R 700 /etc/openldap/slapd.d

四、修改默認配置
須要註釋ldap.conf中的TLS_CACERTDIR /etc/openldap/certs內容

vim /etc/openldap/lapd.conf

過程以下:

#
# LDAP Defaults
#

# See ldap.conf(5) for details
# This file should be world readable but not world writable.

#BASE   dc=example,dc=com
#URI    ldap://ldap.example.com ldap://ldap-master.example.com:666

#SIZELIMIT      12
#TIMELIMIT      15
#DEREF          never

TLS_CACERTDIR  /etc/openldap/certs

# Turning this off breaks GSSAPI used with krb5 when rdns = false
SASL_NOCANON    on

修改成

#
# LDAP Defaults
#

# See ldap.conf(5) for details
# This file should be world readable but not world writable.

#BASE   dc=example,dc=com
#URI    ldap://ldap.example.com ldap://ldap-master.example.com:666

#SIZELIMIT      12
#TIMELIMIT      15
#DEREF          never

#TLS_CACERTDIR  /etc/openldap/certs

# Turning this off breaks GSSAPI used with krb5 when rdns = false
SASL_NOCANON    on

五、啓動openLDAP

service slapd start

六、檢查啓動狀態

ps aux | grep slapd | grep -v grep
netstat -tunlp  | grep :389

執行過程以下:

[root@duke openldap]# ps aux | grep slapd | grep -v grep
ldap 18081 0.0 1.7 517348 32988 ? Ssl 17:06 0:00 /usr/sbin/slapd -u ldap -h ldapi:/// ldap:///
[root@duke openldap]# netstat -tunlp | grep :389
tcp 0 0 0.0.0.0:389 0.0.0.0: LISTEN 18081/slapd
tcp6 0 0 :::389 :::
LISTEN 18081/slapd

6.2.三、啓動失敗解決方案

一、啓動失敗問題1
執行過程:

[root@duke openldap]# service slapd start
Redirecting to /bin/systemctl start slapd.service
Job for slapd.service failed because the control process exited with error code. See "systemctl status slapd.service" and "journalctl -xe" for details.
[root@duke openldap]# journalctl -xe
10月 26 16:59:47 test216 slaptest[17907]: _sasl_plugin_load failed on sasl_auxprop_plug_init for plugin: sql
10月 26 16:59:47 test216 runuser[17906]: pam_unix(runuser:session): session closed for user ldap
10月 26 16:59:47 test216 check-config.sh[17903]: Checking configuration file failed:
10月 26 16:59:47 test216 check-config.sh[17903]: 5bd2d783 ldif_read_file: Permission denied for "/etc/openldap/slapd.d/cn=config/cn=schema/cn={1}cosine.ldif"
10月 26 16:59:47 test216 check-config.sh[17903]: slaptest: bad configuration file!
10月 26 16:59:47 test216 slapcat[17911]: auxpropfunc error invalid parameter supplied
10月 26 16:59:47 test216 slapcat[17911]: _sasl_plugin_load failed on sasl_auxprop_plug_init for plugin: ldapdb
10月 26 16:59:47 test216 slapcat[17911]: ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin(): invalid parameter supplied
10月 26 16:59:47 test216 slapcat[17911]: _sasl_plugin_load failed on sasl_canonuser_init for plugin: ldapdb
10月 26 16:59:47 test216 slapcat[17911]: sql_select option missing
10月 26 16:59:47 test216 slapcat[17911]: auxpropfunc error no mechanism available
10月 26 16:59:47 test216 slapcat[17911]: _sasl_plugin_load failed on sasl_auxprop_plug_init for plugin: sql
10月 26 16:59:47 test216 slapcat[17911]: DIGEST-MD5 common mech free
10月 26 16:59:47 test216 slapd[17918]: @(#) $OpenLDAP: slapd 2.4.44 (May 16 2018 09:55:53) $
                                            mockbuild@c1bm.rdu2.centos.org:/builddir/build/BUILD/openldap-2.4.44/openldap-2.4.44/servers/slapd
10月 26 16:59:47 test216 slapd[17918]: auxpropfunc error invalid parameter supplied
10月 26 16:59:47 test216 slapd[17918]: _sasl_plugin_load failed on sasl_auxprop_plug_init for plugin: ldapdb
10月 26 16:59:47 test216 slapd[17918]: ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin(): invalid parameter supplied
10月 26 16:59:47 test216 slapd[17918]: _sasl_plugin_load failed on sasl_canonuser_init for plugin: ldapdb
10月 26 16:59:47 test216 slapd[17918]: sql_select option missing
10月 26 16:59:47 test216 slapd[17918]: auxpropfunc error no mechanism available
10月 26 16:59:47 test216 slapd[17918]: _sasl_plugin_load failed on sasl_auxprop_plug_init for plugin: sql
10月 26 16:59:47 test216 slapd[17918]: ldif_read_file: Permission denied for "/etc/openldap/slapd.d/cn=config/cn=schema/cn={1}cosine.ldif"
10月 26 16:59:47 test216 slapd[17918]: DIGEST-MD5 common mech free
10月 26 16:59:47 test216 slapd[17918]: slapd stopped.
10月 26 16:59:47 test216 slapd[17918]: connections_destroy: nothing to destroy.
10月 26 16:59:47 test216 systemd[1]: slapd.service: control process exited, code=exited status=1
10月 26 16:59:47 test216 systemd[1]: Failed to start OpenLDAP Server Daemon.
-- Subject: Unit slapd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit slapd.service has failed.
-- 
-- The result is failed.
10月 26 16:59:47 test216 systemd[1]: Unit slapd.service entered failed state.
10月 26 16:59:47 test216 systemd[1]: slapd.service failed.
10月 26 16:59:47 test216 polkitd[663]: Unregistered Authentication Agent for unix-process:17887:646403 (system bus name :1.65, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, local

問題在於下面2個關鍵處

_sasl_plugin_load failed on sasl_canonuser_init for plugin: ldapdb
ldapdb_canonuser_plug_init() failed in sasl_canonuser_add_plugin(): invalid parameter supplied

是因爲安裝了cyrus-sasl-ldap包,致使,實際過程當中是不須要該包的,刪除該包便可,命令以下:

rpm -e cyrus-sasl-ldap-2.1.26-23.el7.x86_64

二、啓動失敗問題2
若是經過journalctl -xe查看到有不少如下內容,則表示權限不對:

tlsmc_get_pin: INFO: Please note the extracted key file will not be protected with a PIN any more, however it will be still protected at least by file per

執行如下操做:

chown -R ldap:ldap /etc/openldap
chown -R ldap:ldap /var/run/openldap
chown -R ldap:ldap /var/lib/ldap

三、啓動失敗問題3
若是經過slapd -h ldap://127.0.0.1 -d 481查看到有下內容,則表示缺乏/etc/openldap/certs目錄中的文件,須要將以前備份的certsldap.conf恢復:

TLSMC: MozNSS compatibility interception begins.
tlsmc_intercept_initialization: INFO: entry options follow:
tlsmc_intercept_initialization: INFO: cacertdir = `/etc/openldap/certs'
tlsmc_intercept_initialization: INFO: certfile = `OpenLDAP Server'
tlsmc_intercept_initialization: INFO: keyfile = `/etc/openldap/certs/password'
tlsmc_convert: INFO: trying to open NSS DB with CACertDir = `/etc/openldap/certs'.
tlsmc_open_nssdb: INFO: trying to initialize moznss using security dir `/etc/openldap` prefix `certs`.
tlsmc_open_nssdb: WARN: could not initialize MozNSS context - error -8015.
tlsmc_convert: INFO: cannot open the NSS DB, expecting PEM configuration is present.
tlsmc_intercept_initialization: INFO: altered options follow:
tlsmc_intercept_initialization: INFO: cacertdir = `/etc/openldap'
tlsmc_intercept_initialization: INFO: certfile = `OpenLDAP Server'
tlsmc_intercept_initialization: INFO: keyfile = `/etc/openldap/certs/password'
tlsmc_intercept_initialization: INFO: successfully intercepted TLS initialization. Continuing with OpenSSL only.
TLSMC: MozNSS compatibility interception ends.
TLS: could not use certificate `OpenLDAP Server'.
TLS: error:02001002:system library:fopen:No such file or directory bss_file.c:402
TLS: error:20074002:BIO routines:FILE_CTRL:system lib bss_file.c:404
TLS: error:140AD002:SSL routines:SSL_CTX_use_certificate_file:system lib ssl_rsa.c:468
5bd16a2e main: TLS init def ctx failed: -1
5bd16a2e slapd destroy: freeing system resources.
5bd16a2e slapd stopped.
5bd16a2e connections_destroy: nothing to destroy.

6.三、配置kerberos

6.3.一、設置/etc/krb5.conf文件

vim /etc/krb5.conf

一、設置libdefaults屬性
找到[libdefaults]行,進行如下修改

[libdefaults]
        default_realm = EXAMPLE.COM

# The following krb5.conf variables are only for MIT Kerberos.
        krb4_config = /etc/krb.conf
        krb4_realms = /etc/krb.realms
        kdc_timesync = 1
        ccache_type = 4
        forwardable = true
        proxiable = true

修改成

[libdefaults]
        renew_lifetime = 7d
              forwardable = true
              default_realm = EXAMPLE.COM
              ticket_lifetime = 24h
              dns_lookup_realm = false
              dns_lookup_kdc = false
              default_ccache_name = /tmp/krb5cc_%{uid}

二、設置realms屬性
找到[realms]行,進行如下修改

[realms]        
        EXAMPLE.COM = {
                kdc = 192.168.0.2
                admin_server = 192.168.0.2
        }  

修改成

[realms]        
        EXAMPLE.COM = {
                admin_server = 192.168.0.2
                kdc = 192.168.0.2
                max_renewable_life = 30m
                            database_module = openldap_ldapconf
                            supported_enctypes = aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
        }  

三、設置domain_realm屬性
找到[domain_realm]行,進行如下修改

[domain_realm]
        .mit.edu = ATHENA.MIT.EDU
        mit.edu = ATHENA.MIT.EDU
        .media.mit.edu = MEDIA-LAB.MIT.EDU
        media.mit.edu = MEDIA-LAB.MIT.EDU
        .csail.mit.edu = CSAIL.MIT.EDU
        csail.mit.edu = CSAIL.MIT.EDU
        .whoi.edu = ATHENA.MIT.EDU
        whoi.edu = ATHENA.MIT.EDU
        .stanford.edu = stanford.edu
        .slac.stanford.edu = SLAC.STANFORD.EDU
        .toronto.edu = UTORONTO.CA
        .utoronto.ca = UTORONTO.CA

修改成

[domain_realm]
        .example.com = EXAMPLE.COM
              example.com = EXAMPLE.COM
              kdc.example.com = EXAMPLE.COM
              client.example.com = EXAMPLE.COM

四、添加如下屬性

[logging]
  default = FILE:/home/ldap/log/krb5libs.log
  kdc = FILE:/home/ldap/log/krb5kdc.log
  admin_server = FILE:/home/ldap/log/kadmind.log

[dbdefaults]
  ldap_kerberos_container_dn = cn=kerberos,dc=example,dc=com

[dbmodules]
    openldap_ldapconf = {
        db_library = kldap
        ldap_servers = ldapi://
        ldap_kerberos_container_dn = cn=kerberos,dc=example,dc=com
        ldap_kdc_dn = cn=root,dc=example,dc=com
        ldap_kadmind_dn = cn=root,dc=example,dc=com
        ldap_service_password_file = /etc/krb5.ldap
        ldap_conns_per_server = 5
    }
【注意】
一、 ldap_kdc_dn 對應 Kerberos 訪問 LDAP 數據庫時的 服務賬號,須要有 讀權限
二、 ldap_kadmind_dn 對應 Kerberos 訪問 LDAP 數據庫時的 管理賬號,須要有 讀寫權限
三、此處爲了簡單方便,統一用 cn=root,dc=example,dc=com一個進行管理
四、 ldap_kerberos_container_dn 必須以 ' cn'開頭

6.2.一、設置/var/kerberos/krb5kdc/kdc.conf文件

在默認狀況下supported_enctypes默認使用aes256-cts。因爲,JAVA使用aes256-cts驗證方式須要安裝額外的jar包推薦不使用。因此須要針對aes256-cts進行修改。

vim /var/kerberos/krb5kdc/kdc.conf

將下面內:

[kdcdefaults]
 kdc_ports = 88
 kdc_tcp_ports = 88

[realms]
 EXAMPLE.COM = {
master_key_type = aes256-cts
  master_key_type = des-hmac-sha1
  default_principal_flags = +preauth
  acl_file = /var/kerberos/krb5kdc/kadm5.acl
  dict_file = /usr/share/dict/words
  admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
  supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
 }

註釋:master_key_type = aes256-cts
刪除:aes256-cts:normal

[kdcdefaults]
 kdc_ports = 88
 kdc_tcp_ports = 88

[realms]
 EXAMPLE.COM = {
#master_key_type = aes256-cts
  master_key_type = des-hmac-sha1
  default_principal_flags = +preauth
  acl_file = /var/kerberos/krb5kdc/kadm5.acl
  dict_file = /usr/share/dict/words
  admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
  supported_enctypes = aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
 }

6.三、LDAP增長kerberos用戶

6.3.一、建立LDAP數據庫(用於後續整合)

一、查看相關默認配置
因爲安裝LDAP時,使用的是HDB數據庫,因此在/etc/openldap/slapd.d/cn=config目錄查看olcDatabase={2}hdb.ldif文件中的一些相關默認配置

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

未執行4.6.一、變動數據庫)內容以下:

# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 e34ca519
dn: olcDatabase={2}hdb
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb
olcDbDirectory: /var/lib/ldap
olcSuffix: dc=my-domain,dc=com
olcRootDN: cn=Manager,dc=my-domain,dc=com
olcDbIndex: objectClass eq,pres
olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
structuralObjectClass: olcHdbConfig
entryUUID: 9d13466a-6c7c-1038-94b9-edef98ed6f69
creatorsName: cn=config
createTimestamp: 20181025083503Z
entryCSN: 20181025083503.782735Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20181025083503Z

未執行4.6.一、變動數據庫)其中如下內容是下面步驟所須要的關鍵:

olcSuffix: dc=my-domain,dc=com
olcRootDN: cn=Manager,dc=my-domain,dc=com

執行4.6.一、變動數據庫是如下內容)其中如下內容是下面步驟所須要的關鍵:

olcSuffix: dc=example,dc=com
olcRootDN: uid=admin,ou=people,dc=example,dc=com

須要改成,可是不能直接改此處文件,根據後續步驟進行修改

olcSuffix: dc=example,dc=com
olcRootDN: uid=ldapadmin,ou=people,dc=example,dc=com

olcSuffix: dc=example,dc=com
olcRootDN: uid=admin,ou=people,dc=example,dc=com

二、建立數據庫信息
建立數據庫信息文件modify.ldif

vim /home/ldap/modify.ldif

文件內容以下:

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=example,dc=com

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
# Temporary lines to allow initial setup
olcRootDN: uid=ldapadmin,ou=people,dc=example,dc=com

dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: 12345678

dn: cn=config
changetype: modify
add: olcAuthzRegexp
olcAuthzRegexp: uid=([^,]*),cn=GSSAPI,cn=auth uid=$1,ou=people,dc=example,dc=com

dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
# Everyone can read everything
olcAccess: {0}to dn.base="" by * read
# The ldapadm dn has full write access
olcAccess: {1}to * by dn="uid=ldapadmin,ou=people,dc=example,dc=com" by dn="cn=root,dc=example,dc=com" write by * read

三、載入數據庫配置信息

ldapmodify -Y EXTERNAL -H ldapi:/// -f /home/ldap/modify.ldif

過程以下:

[root@duke ldap]# ldapmodify -Y EXTERNAL -H ldapi:/// -f /home/ldap/modify.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={1}mdb,cn=config"
modifying entry "olcDatabase={1}mdb,cn=config"
modifying entry "olcDatabase={1}mdb,cn=config"
ldap_modify: Inappropriate matching (18)
additional info: modify/add: olcRootPW: no equality matching rule

在執行過程當中報錯,密碼不可以被配置,配置文件編寫不對。修改方法以下:
將modify.ldif文件中的下面內容:

dn: olcDatabase={1}mdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: 12345678

修改成

dn: olcDatabase={1}mdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: 12345678

再次執行,過程以下:

[root@duke ldap]# ldapmodify -Y EXTERNAL -H ldapi:/// -f /home/ldap/modify.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={1}mdb,cn=config"
modifying entry "olcDatabase={1}mdb,cn=config"
modifying entry "olcDatabase={1}mdb,cn=config"
modifying entry "cn=config"
modifying entry "olcDatabase={1}mdb,cn=config"

註明:cn=root,dc=example,dc=com受權,以便整合Kerberos使用

6.3.二、建立數據庫數據

數據庫配置完成,可是沒有數據,須要添加數據。
能夠手動編寫 ldif 文件來導入一些用戶和組。
也可使用 migrationtools 工具來生成 ldif 模板。
此處採用ldif文件配置方法來新增數據。
一、setup.ldif文件

vim /home/ldap/setup.ldif

添加內容以下:

dn: dc=example,dc=com
objectClass: top
objectClass: dcObject
objectclass: organization
o: example com
dc: example

dn: ou=people,dc=example,dc=com
objectclass: organizationalUnit
ou: people
description: Users

dn: ou=Groups,dc=example,dc=com
objectClass: organizationalUnit
ou: Groups

dn: uid=ldapadmin,ou=people,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: LDAP admin account
uid: ldapadmin
sn: ldapadmin
uidNumber: 10001
gidNumber: 5000
homeDirectory: /home/ldap/ldapadmin
loginShell: /bin/bash

二、載入數據

ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/setup.ldif

若是執行過程當中報如下錯誤,是由於在按文檔操做過程當中,已經按照4.6.1章節建立了數據庫數據信息,致使部分數據已經存在,因此沒法建立成功。沒有按照4.6.1章節操做,直接按照本章節操做是能夠成功的。

[root@duke ldap]# ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/setup.ldif
adding new entry "dc=example,dc=com"
ldap_add: Already exists (68)

爲了解決上面問題,setup.ldif文件修改成如下內容:

dn: ou=people,dc=example,dc=com
objectclass: organizationalUnit
ou: people
description: Users

dn: ou=Groups,dc=example,dc=com
objectClass: organizationalUnit
ou: Groups

dn: uid=ldapadmin,ou=people,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: LDAP admin account
uid: ldapadmin
sn: ldapadmin
uidNumber: 10001
gidNumber: 5000
homeDirectory: /home/ldap/ldapadmin
loginShell: /bin/bash

再次執行過程以下:

[root@duke ldap]# ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/setup.ldif
adding new entry "uid=ldapadmin,ou=people,dc=example,dc=com"
【注意】: -w 12345678 表示的是設置密碼爲 12345678,此處的密碼沒有在配置文件中設置,用的是命令輸入方式,這樣能夠避免密碼泄露

三、驗證數據
http://192.168.0.2/phpldapadmin頁面使用uid=ldapadmin,ou=people,dc=example,dc=com用戶進行登陸,若是登陸成功即表示數據庫數據添加成功。以下頁面:



6.3.三、導入linux系統用戶

若要將 /etc/passwd, /etc/shadow, /etc/groups 中生成 ldif 更新 ldap 數據庫,就須要用到 migrationtools 工具。
一、安裝migrationtools

apt-get install migrationtools

過程以下:

[root@duke ldap]# yum install migrationtools -y
已加載插件:fastestmirror, langpacks
base                                                                                                                                                                                       | 3.6 kB  00:00:00     
extras                                                                                                                                                                                     | 3.4 kB  00:00:00     
updates                                                                                                                                                                                    | 3.4 kB  00:00:00     
updates/7/x86_64/primary_db                                                                                                                                                                | 6.0 MB  00:00:00     
Loading mirror speeds from cached hostfile
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 migrationtools.noarch.0.47-15.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

==================================================================================================================================================================================================================
 Package                                                 架構                                            版本                                                 源                                             大小
==================================================================================================================================================================================================================
正在安裝:
 migrationtools                                          noarch                                          47-15.el7                                            base                                           26 k

事務概要
==================================================================================================================================================================================================================
安裝  1 軟件包

總下載量:26 k
安裝大小:106 k
Downloading packages:
migrationtools-47-15.el7.noarch.rpm                                                                                                                                                        |  26 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : migrationtools-47-15.el7.noarch                                                                                                                                                               1/1 
  驗證中      : migrationtools-47-15.el7.noarch                                                                                                                                                               1/1 

已安裝:
  migrationtools.noarch 0:47-15.el7                                                                                                                                                                               

完畢!

二、修改默認配置
利用遷移工具生成模板,可是須要先修改默認的配置:

vim /usr/share/migrationtools/migrate_common.ph

將下面內容

\# Default DNS domain
$DEFAULT_MAIL_DOMAIN =  "padl.com";

\# Default base 
$DEFAULT_BASE =  "dc=padl,dc=com";

修改成

\# Default DNS domain
$DEFAULT_MAIL_DOMAIN =  "example.com";

\# Default base 
$DEFAULT_BASE =  "dc=example,dc=com";

三、生成文件模板

/usr/share/migrationtools/migrate_base.pl > /home/ldap/base.ldif

四、導入命令
根據需求更改上面文件內容,而後執行下面語句,便可把linux用戶導入到LDAP中

ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/base.ldif

固然你可能會遇到下面錯誤,這是由於生成的base.ldif文件中,有已經存在於LDAP的用戶信息,因此導沒法加載成功。

[root@duke ldap]# ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/base.ldif
adding new entry "dc=example,dc=com"
ldap_add: Already exists (68)

修改方法以下,刪除已經存在的用戶信息便可,原始內容以下:

dn: dc=example,dc=com
dc: example
objectClass: top
objectClass: domain

dn: ou=Services,dc=example,dc=com
ou: Services
objectClass: top
objectClass: organizationalUnit

dn: ou=Rpc,dc=example,dc=com
ou: Rpc
objectClass: top
objectClass: organizationalUnit

dn: ou=people,dc=example,dc=com
ou: people
objectClass: top
objectClass: organizationalUnit

dn: ou=Networks,dc=example,dc=com
ou: Networks
objectClass: top
objectClass: organizationalUnit

dn: nisMapName=netgroup.byuser,dc=example,dc=com
nismapname: netgroup.byuser
objectClass: top
objectClass: nisMap

dn: ou=Aliases,dc=example,dc=com
ou: Aliases
objectClass: top
objectClass: organizationalUnit

dn: ou=Protocols,dc=example,dc=com
ou: Protocols
objectClass: top
objectClass: organizationalUnit

dn: ou=Netgroup,dc=example,dc=com
ou: Netgroup
objectClass: top
objectClass: organizationalUnit

dn: ou=Group,dc=example,dc=com
ou: Group
objectClass: top
objectClass: organizationalUnit

dn: ou=Mounts,dc=example,dc=com
ou: Mounts
objectClass: top
objectClass: organizationalUnit

dn: ou=Hosts,dc=example,dc=com
ou: Hosts
objectClass: top
objectClass: organizationalUnit

dn: nisMapName=netgroup.byhost,dc=example,dc=com
nismapname: netgroup.byhost
objectClass: top
objectClass: nisMap

修改成

dn: ou=Services,dc=example,dc=com
ou: Services
objectClass: top
objectClass: organizationalUnit

dn: ou=Rpc,dc=example,dc=com
ou: Rpc
objectClass: top
objectClass: organizationalUnit

dn: ou=Networks,dc=example,dc=com
ou: Networks
objectClass: top
objectClass: organizationalUnit

dn: nisMapName=netgroup.byuser,dc=example,dc=com
nismapname: netgroup.byuser
objectClass: top
objectClass: nisMap

dn: ou=Aliases,dc=example,dc=com
ou: Aliases
objectClass: top
objectClass: organizationalUnit

dn: ou=Protocols,dc=example,dc=com
ou: Protocols
objectClass: top
objectClass: organizationalUnit

dn: ou=Netgroup,dc=example,dc=com
ou: Netgroup
objectClass: top
objectClass: organizationalUnit

dn: ou=Group,dc=example,dc=com
ou: Group
objectClass: top
objectClass: organizationalUnit

dn: ou=Mounts,dc=example,dc=com
ou: Mounts
objectClass: top
objectClass: organizationalUnit

dn: ou=Hosts,dc=example,dc=com
ou: Hosts
objectClass: top
objectClass: organizationalUnit

dn: nisMapName=netgroup.byhost,dc=example,dc=com
nismapname: netgroup.byhost
objectClass: top
objectClass: nisMap

執行過程以下:

[root@duke ldap]# ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/base.ldif
adding new entry "ou=Services,dc=example,dc=com"
adding new entry "ou=Rpc,dc=example,dc=com"
adding new entry "ou=Networks,dc=example,dc=com"
adding new entry "nisMapName=netgroup.byuser,dc=example,dc=com"
adding new entry "ou=Aliases,dc=example,dc=com"
adding new entry "ou=Protocols,dc=example,dc=com"
adding new entry "ou=Netgroup,dc=example,dc=com"
adding new entry "ou=Group,dc=example,dc=com"
adding new entry "ou=Mounts,dc=example,dc=com"
adding new entry "ou=Hosts,dc=example,dc=com"
adding new entry "nisMapName=netgroup.byhost,dc=example,dc=com"

導入後頁面展現結果以下:

五、導入指定的用戶
能夠進行批量導入用戶,也能夠指定導入用戶,操做以下:
①、建立系統用戶test並設置密碼爲test

useradd test

②、查看用戶是否建立成功,並導入到指定文件

grep -E "test" /etc/passwd >/home/ldap/test_userinfo.txt

③、轉換test信息爲ldif文件

/usr/share/migrationtools/migrate_passwd.pl /home/ldap/test_userinfo.txt /home/ldap/test_userinfo.ldif

④、導入系統

ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/test_userinfo.ldif

過程以下:

[root@duke ldap]# ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/test_userinfo.ldif
adding new entry "uid=test,ou=people,dc=example,dc=com"

⑤、將用戶組導入到指定文件

grep -E "test" /etc/group >/home/ldap/test_groupinfo.txt

⑥、轉換組信息爲ldif文件

/usr/share/migrationtools/migrate_group.pl /home/ldap/test_groupinfo.txt /home/ldap/test_groupinfo.ldif

⑦、導入到系統

ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/test_groupinfo.ldif

過程以下:

[root@duke ldap]# ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/test_groupinfo.ldif
adding new entry "cn=test,ou=Group,dc=example,dc=com"

6.3.四、LDAP操做指令(知識點,配合6.3.2章節新建的test用戶操做

一、查詢
查詢新添加的 test 用戶:

ldapsearch -LLL -x -D 'uid=ldapadmin,ou=people,dc=example,dc=com' -w 12345678 -b 'dc=example,dc=com' 'uid=test'

過程以下:

[root@duke ldap]# ldapsearch -LLL -x -D 'uid=ldapadmin,ou=people,dc=example,dc=com' -w 12345678 -b 'dc=example,dc=com' 'uid=test'
dn: uid=test,ou=people,dc=example,dc=com
uid: test
cn: test
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword:: e2NyeXB0fSQ2JC56ZzI4a0JtJFNaeFlJV3Q1TjlBT2hlaHpOQThJN1RZYWFiVlZ
4Y1oxcUNjb2xncmN2cUg4dmpCRXlGUjJObkJmckVsb29DSmxIaGkwZURZMjZvYnphL2dXM0hEVXQv
shadowLastChange: 17823
shadowMax: 99999
shadowWarning: 7
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/test

二、修改
用戶添加好之後,須要給其設定初始密碼,運行命令以下:

ldappasswd -x -D 'uid=ldapadmin,ou=people,dc=example,dc=com' -w 12345678 "uid=test,ou=people,dc=example,dc=com" -S

過程以下:

[root@duke ldap]# ldappasswd -x -D 'uid=ldapadmin,ou=people,dc=example,dc=com' -w 12345678 "uid=test,ou=people,dc=example,dc=com" -S
New password: 12345678
Re-enter new password:12345678

頁面查看以下:



使用test用戶登陸頁面查看以下:
登陸密碼是12345678

三、刪除知識點
不要執行刪除test用戶,第7章節會用到
刪除用戶:

ldapdelete -x -w 12345678 -D'uid=ldapadmin,ou=people,dc=example,dc=com' "uid=test,ou=people,dc=example,dc=com"

刪除用戶組:

ldapdelete -x -w 12345678 -D'uid=ldapadmin,ou=people,dc=example,dc=com' "cn=test,ou=group,dc=example,dc=com"

6.3.五、建立kerberos用戶

一、新建user.ldif文件

vim /home/ldap/user.ldif

該文件用戶ldap配置kerberos所要用到的用戶信息,文件內容以下:

dn: cn=kerberos,dc=example,dc=com
cn: kerberos
objectClass: organizationalRole

dn: cn=root,dc=example,dc=com
cn: root
userPassword:: e1NTSEF9dnJmZXBqQ0lmUHowL1ppL0ZRU2s2RlI3R3VyTWRZeFUK
objectClass: simpleSecurityObject
objectClass: organizationalRole
【注意】:
上面 userPassword:: e1NTSEF9dnJmZXBqQ0lmUHowL1ppL0ZRU2s2RlI3R3VyTWRZeFUK 中的密碼生成是經過下面指令得到
一、 -s後面的是 密碼
二、 | base64後面的是 密碼編碼格式
三、不一樣機器上的密碼必須從新生成一次
四、每次加密密碼只能使用一次
slappasswd -s 12345678 | base64

執行過程以下

[root@duke ldap]# slappasswd -s 12345678 | base64
e1NTSEF9dnJmZXBqQ0lmUHowL1ppL0ZRU2s2RlI3R3VyTWRZeFUK

二、載入用戶信息

ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/user.ldif

執行過程以下:

[root@duke ldap]# ldapadd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 -f /home/ldap/user.ldif
adding new entry "cn=kerberos,dc=example,dc=com"
adding new entry "cn=root,dc=example,dc=com"

三、管理員修改普通用戶的密碼
cn=root,dc=example,dc=com用戶密碼修改成:root

ldappasswd -x -D "uid=ldapadmin,ou=people,dc=example,dc=com" -w 12345678 "cn=root,dc=example,dc=com" -s root

6.3.五、生成kerberos訪問ldap的服務密碼文件

由於Kerberos 須要有 ldap_kdc_dnldap_kadmind_dn密碼才能訪問 LDAP數據庫,執行如下命令:

kdb5_ldap_util -D uid=ldapadmin,ou=people,dc=example,dc=com -w 12345678 stashsrvpw -f /etc/krb5.ldap cn=root,dc=example,dc=com
cat /etc/krb5.ldap

過程以下:

[root@duke ldap]# kdb5_ldap_util -D uid=ldapadmin,ou=people,dc=example,dc=com -w 12345678 stashsrvpw -f /etc/krb5kdc/service.keyfile cn=root,dc=example,dc=com
Password for "cn=root,dc=example,dc=com": 輸入密碼:12345678
Re-enter password for "cn=root,dc=example,dc=com": 確認密碼:12345678
[root@duke ldap]# cat /etc/krb5.ldap
cn=root,dc=example,dc=com#{HEX}3132333435363738

6.3.六、建立kerberos數據庫

 kdb5_ldap_util -D uid=ldapadmin,ou=people,dc=example,dc=com -w 12345678 -H ldapi:// create -r EXAMPLE.COM -s

過程以下

[root@duke ldap]# kdb5_ldap_util -D uid=ldapadmin,ou=people,dc=example,dc=com -w 12345678 -H ldapi:// create -r EXAMPLE.COM -s
Initializing database for realm 'EXAMPLE.COM' 初始化'EXAMPLE.COM'域的數據庫
You will be prompted for the database Master Password.輸入數據庫主密碼
It is important that you NOT FORGET this password.請勿忘記此密碼,這一點很重要
Enter KDC database master key: 輸入密碼:12345678
Re-enter KDC database master key to verify:輸入確認密碼:12345678

6.3.七、重啓Kerberos

service krb5-kdc restart
service krb5-admin-server restart

6.3.八、測試kerberos和ldap是否整合成功(非必要操做,能夠不作

一、添加用戶

kadmin.local

添加一個test用戶
過程以下:

[root@duke ldap]# kadmin.local
Authenticating as principal root/admin@EXAMPLE.COM with password.
kadmin.local: addprinc test 若是要添加test用戶,必須在test前輸入 addprinc 關鍵字
WARNING: no policy specified for test@EXAMPLE.COM; defaulting to no policy
Enter password for principal "test@EXAMPLE.COM": 輸入test用戶密碼:test
Re-enter password for principal "test@EXAMPLE.COM": >確認test用戶密碼:test
Principal "test@EXAMPLE.COM" created.

二、檢查是否添加成功

slapcat |grep "test"

過程以下:

[root@duke ldap]# slapcat |grep "test"
dn: krbPrincipalName=test@EXAMPLE.COM,cn=EXAMPLE.COM,cn=kerberos,dc=example,
krbPrincipalName: test@EXAMPLE.COM

三、檢查ldap頁面是否添加成功

四、刪除用戶
此處不刪除,會影響後面章節操做
過程以下:

root@yita-211:/etc# kadmin.local
Authenticating as principal root/admin@EXAMPLE.COM with password.
kadmin.local: delete_principal test 若是要刪除test用戶,必須在test前輸入 delete_principal 關鍵字

七、Kerberos+LDAP認證整合

確保Kerberos和LDAP已經配置,即完成前6章的內容

7.一、採用該 LDAP做爲用戶認證。

一、先按照6.3.3章節第5小點進行操做,添加test用戶

二、只須要對用戶 uid=test,ou=people,dc=example,dc=com 添加 userPassword成員便可。
若是經過 命令行添加,須要先準備test.ldif文件(userPassword對應的密碼爲12345678),內容以下:

dn: uid=test,ou=people,dc=example,dc=com
changetype: modify
replace: userPassword
userPassword:: e1NTSEF9ZmtrZzNrOUUrY08rTS9CejFza0FhVk9TV3dZVlZ6akkK

而後執行命令

ldapmodify -x -D 'cn=root,dc=example,dc=com' -w root -h 192.168.0.2 -f /home/ldap/test.ldif

執行過程以下:

[root@duke ldap]# vi test.ldif
dn: uid=test,ou=people,dc=example,dc=com
changetype: modify
replace: userPassword
userPassword:: e1NTSEF9ZmtrZzNrOUUrY08rTS9CejFza0FhVk9TV3dZVlZ6akkK

"test.ldif" 4L, 146C 已寫入
[root@duke ldap]# ldapmodify -x -D 'cn=root,dc=example,dc=com' -w root -h 192.168.0.2 -f /home/ldap/test.ldif
modifying entry "uid=test,ou=people,dc=example,dc=com"

三、確認是否成功

ldapsearch -x -D 'uid=test,ou=people,dc=example,dc=com' -w 123456 192.168.0.2 -b 'ou=people,dc=example,dc=com'

執行過程以下

[root@duke ldap]# ldapsearch -x -D 'uid=test,ou=people,dc=example,dc=com' -w 12345678 192.168.0.2 -b 'ou=people,dc=example,dc=com'
# extended LDIF
#
# LDAPv3
# base <ou=people,dc=example,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: 127.0.0.1 
#
# people, example.com
dn: ou=people,dc=example,dc=com
# test, people, example.com
dn: uid=test,ou=people,dc=example,dc=com
# ldapadmin, people, example.com
dn: uid=ldapadmin,ou=people,dc=example,dc=com
# search result
search: 2
result: 0 Success
# numResponses: 4
# numEntries: 3

7.二、使用 Kerberos 認證。

須要將用戶的密碼域作以下修改:

一、userPassword 對應的密碼生成:

echo -n "{SASL}test@EXAMPLE.COM" | base64

過程以下:

[root@duke ldap]# echo -n "{SASL}test@EXAMPLE.COM" | base64
e1NBU0x9dGVzdEBFWEFNUExFLkNPTQ==

二、編寫修改test用戶的密碼的test2.ldif文件

dn: uid=test,ou=people,dc=example,dc=com
changetype: modify
replace: userPassword
userPassword:: e1NBU0x9dGVzdEBFWEFNUExFLkNPTQ==

過程以下:

[root@duke ldap]# vi test2.ldif
dn: uid=test,ou=people,dc=example,dc=com
changetype: modify
replace: userPassword
userPassword:: e1NBU0x9dGVzdEBFWEFNUExFLkNPTQ==

"test2.ldif" 4L, 130C 已寫入

三、執行應用該修改

ldapmodify -x -D 'cn=root,dc=example,dc=com' -w root -h 192.168.0.2 -f /home/ldap/test2.ldif

過程以下:

[root@duke ldap]# ldapmodify -x -D 'cn=root,dc=example,dc=com' -w root -h 192.168.0.2 -f /home/ldap/test2.ldif
modifying entry "uid=test,ou=people,dc=example,dc=com"

7.三、修改saslauthd配置

一、修改配置文件

vim /etc/sysconfig/saslauthd

\# Directory in which to place saslauthd's listening socket, pid file, and so
\# on.  This directory must already exist.
SOCKETDIR=/run/saslauthd

\# Mechanism to use when checking passwords.  Run "saslauthd -v" to get a list
\# of which mechanism your installation was compiled with the ablity to use.
MECH=pam

\# Additional flags to pass to saslauthd on the command line.  See saslauthd(8)
\# for the list of accepted flags.
FLAGS=

修改成

\# Directory in which to place saslauthd's listening socket, pid file, and so
\# on.  This directory must already exist.
SOCKETDIR=/run/saslauthd

\# Mechanism to use when checking passwords.  Run "saslauthd -v" to get a list
\# of which mechanism your installation was compiled with the ablity to use.
MECH=kerberos5

\# Additional flags to pass to saslauthd on the command line.  See saslauthd(8)
\# for the list of accepted flags.
FLAGS=

二、重啓saslauthd

service saslauthd restart

三、建立ldap配置文件

vim /etc/sasl2/slapd.conf文件

內容:

pwcheck_method: saslauthd

過程以下

[root@duke ldap]# vim /etc/sasl2/slapd.conf
pwcheck_method: saslauthd
"/etc/sasl2/slapd.conf" 1L, 26C 已寫入

四、重啓ldap

service slapd restart

五、查看saslauthd是否報錯

service saslauthd status -l

執行過程以下:

[root@duke ldap]# service saslauthd status -l
Redirecting to /bin/systemctl status  -l saslauthd.service
● saslauthd.service - SASL authentication daemon.
   Loaded: loaded (/usr/lib/systemd/system/saslauthd.service; disabled; vendor preset: disabled)
   Active: active (running) since 四 2018-10-25 19:54:47 CST; 4 days ago
 Main PID: 14333 (saslauthd)
   CGroup: /system.slice/saslauthd.service
           ├─14333 /usr/sbin/saslauthd -m /run/saslauthd -a kerberos5
           ├─14334 /usr/sbin/saslauthd -m /run/saslauthd -a kerberos5
           ├─14335 /usr/sbin/saslauthd -m /run/saslauthd -a kerberos5
           ├─14336 /usr/sbin/saslauthd -m /run/saslauthd -a kerberos5
           └─14337 /usr/sbin/saslauthd -m /run/saslauthd -a kerberos5

10月 25 19:54:47 test216 systemd[1]: Starting SASL authentication daemon....
10月 25 19:54:47 test216 saslauthd[14333]: detach_tty      : master pid is: 14333
10月 25 19:54:47 test216 saslauthd[14333]: ipc_init        : listening on socket: /run/saslauthd/mux
10月 25 19:54:47 test216 systemd[1]: Started SASL authentication daemon..
10月 25 19:55:21 test216 saslauthd[14334]: auth_krb5: krb5_get_init_creds_password: -1765328353
10月 25 19:55:21 test216 saslauthd[14334]: do_auth         : auth failure: [user=test] [service=imap] [realm=] [mech=kerberos5] [reason=saslauthd internal error]
10月 25 19:55:36 test216 saslauthd[14333]: auth_krb5: krb5_get_init_creds_password: -1765328353
10月 25 19:55:36 test216 saslauthd[14333]: do_auth         : auth failure: [user=test] [service=ldap] [realm=EXAMPLE.COM] [mech=kerberos5] [reason=saslauthd internal error]

7.四、增長kerberos的用戶配置

執行以下操做:

kadmin.local -q "ank -clearpolicy -randkey host/test216"
kadmin.local -q "ktadd host/test216"
service saslauthd restart
ps -aux | grep saslauthd
kadmin.local -q 'ank -pw 12345678 test'
【注意】
一、 host/test216中的 test216,是 服務器名稱,不能寫成 IP
二、 ankadd_principal簡寫,表示 增長
三、 -q表示 靜默,不進入 kadmin.local的對話模式
四、 -pw 表示設置 test密碼爲 12345678

7.五、測試Kerberos+OpenLDAP整合認證是否成功

一、測試kerberos認證

testsaslauthd -u test -p 12345678

執行過程以下:

[root@duke ldap]# testsaslauthd -u test -p 12345678
0: OK "Success."

至此, Kerberos 認證測試成功。

二、測試OpenLDAP認證

ldapsearch -x -D 'uid=test,ou=people,dc=example,dc=com' -w 12345678 -h 192.168.0.2 -b 'ou=people,dc=example,dc=com'

執行過程以下:

[root@duke ldap]# ldapsearch -x -D 'uid=test,ou=people,dc=example,dc=com' -w 12345678 -h 192.168.0.2 -b 'ou=people,dc=example,dc=com'
# extended LDIF
#
# LDAPv3
# base <ou=people,dc=example,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# people, example.com
dn: ou=people,dc=example,dc=com
objectClass: organizationalUnit
ou: people
description: Users

# ldapadmin, people, example.com
dn: uid=ldapadmin,ou=people,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: LDAP admin account
uid: ldapadmin
sn: ldapadmin
uidNumber: 1001
gidNumber: 100
homeDirectory: /home/ldap
loginShell: /bin/bash

# test, people, example.com
dn: uid=test,ou=people,dc=example,dc=com
uid: test
cn: test
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowLastChange: 17829
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/test
userPassword:: e1NBU0x9dGVzdEBFWEFNUExFLkNPTQ==

# search result
search: 2
result: 0 Success

# numResponses: 4
# numEntries: 3

使用 test的密碼12345678phpLDAPadmin進行登陸認證

至此, OpenLDAP 認證測試成功。

三、測試Kerveros+OpenLDAP互通

  • 修改test密碼
    過程以下:

    [root@duke ldap]# kpasswd test
    Password for test@EXAMPLE.COM: 輸入test原始密碼:12345678
    Enter new password: 輸入test新密碼:123456
    Enter it again: 確認test新密碼:123456
    Password changed.

  • Kerveros認證
    過程以下:

    [root@duke ldap]# testsaslauthd -u test -p 123456
    0: OK "Success."

  • OpenLDAP認證

    [root@duke ldap]# ldapsearch -x -D 'uid=test,ou=people,dc=example,dc=com' -w 123456 -h 192.168.0.2 -b 'ou=people,dc=example,dc=com'
    # extended LDIF
    #
    # LDAPv3
    # base <ou=people,dc=example,dc=com> with scope subtree
    # filter: (objectclass=*)
    # requesting: ALL
    #
    # people, example.com
    dn: ou=people,dc=example,dc=com
    objectClass: organizationalUnit
    ou: people
    description: Users
    # ldapadmin, people, example.com
    dn: uid=ldapadmin,ou=people,dc=example,dc=com
    objectClass: inetOrgPerson
    objectClass: posixAccount
    objectClass: shadowAccount
    cn: LDAP admin account
    uid: ldapadmin
    sn: ldapadmin
    uidNumber: 1001
    gidNumber: 100
    homeDirectory: /home/ldap
    loginShell: /bin/bash
    # test, people, example.com
    dn: uid=test,ou=people,dc=example,dc=com
    uid: test
    cn: test
    objectClass: account
    objectClass: posixAccount
    objectClass: top
    objectClass: shadowAccount
    shadowLastChange: 17829
    shadowMin: 0
    shadowMax: 99999
    shadowWarning: 7
    loginShell: /bin/bash
    uidNumber: 1001
    gidNumber: 1001
    homeDirectory: /home/test
    userPassword:: e1NBU0x9dGVzdEBFWEFNUExFLkNPTQ==
    # search result
    search: 2
    result: 0 Success
    # numResponses: 4
    # numEntries: 3
    
  • 使用 test的密碼12345678phpLDAPadmin進行登陸認證

至此, Apache+PHP+Kerberos+LDAP+phpLDAPadmin整合互通認證測試成功。

參考

[kadmin用法]
http://manpages.ubuntu.com/manpages/xenial/en/man1/kadmin.1.html

[openldap搭建說明]
https://help.ubuntu.com/community/OpenLDAPServer

[sldap配置文件說明]
http://manpages.ubuntu.com/manpages/xenial/en/man5/slapd-config.5.html

相關文章
相關標籤/搜索