需要一種直接的方法來存儲地址簿風格的數據和網絡信息以及任何結構化數據嗎? LDAP是一種可以追溯到1993年的技術,它提供了解決方案。雖然缺乏諸如Node.js和Go之類的新技術的“酷”因素,但其功能仍然很重要。
密鑰概念:
1993年在密歇根大學創建的LDAP(輕量級目錄訪問協議)是用於管理目錄服務的Internet協議。 它有效地存儲和管理通訊錄信息,網絡詳細信息和其他有組織的數據。“ LDAP”在技術上是指該協議,通常用於描述客戶端和服務器組件。 將其視為目錄服務器的SQL,即與LDAP啟用服務器進行交互的語言。 流行的LDAP服務器包括Microsoft的Active Directory(自Windows 2000以來集成到Windows)和開源OpenLDAP,我們將在此教程系列中使用。 OpenLDAP的靈活性允許多樣化的架構和數據存儲。
>這第一部分涵蓋:
> OpenLDAP設置基礎知識。
加載數據記錄。
>使用Php。
LDAP Term | Description |
---|---|
dn | Distinguished Name: A record's unique identifier, similar to a primary key in relational databases. |
Directory Schema | Defines the structure and constraints of the directory information. |
entry | A record containing attributes that store data. |
attribute | Similar to an associative array element or database column; specifies the data type, sorting rules, case-sensitivity, and other criteria. |
cn | Common Name (e.g., "John Smith") |
sn | Surname (e.g., "Smith") |
為了深入了解,請諮詢O'Reilly的LDAP指南或LDAP上的Wikipedia條目。
> 設置LDAP服務器:
>> OpenLDAP安裝和配置可能有些複雜。 這些步驟針對基於Debian的服務器進行了優化,目的是為了清晰和簡潔:
<code class="language-bash">sudo apt-get install slapd ldap-utils</code>
<code class="language-bash">dpkg-reconfigure slapd</code>回答提示如下:
homestead.localdomain
>
驗證:>
通過運行:檢查安裝
<code class="language-bash">ldapsearch -x -b dc=homestead,dc=localdomain</code>如果遇到錯誤,請確保運行OpenLDAP:
>
<code class="language-bash">sudo netstat -tlnp | grep slapd</code>您應該看到輸出,表明slapd在端口389上聽
填充數據庫:
create
帶有以下內容:>
users.ldif
<code class="language-ldif">dn: cn=Sheldon Cooper,ou=People,dc=homestead,dc=localdomain cn: Sheldon Cooper objectClass: person objectClass: inetOrgPerson sn: Cooper dn: cn=Leonard Hofstadter,ou=People,dc=homestead,dc=localdomain cn: Leonard Hofstadter objectClass: person objectClass: inetOrgPerson sn: Hofstadter dn: cn=Howard Wolowitz,ou=People,dc=homestead,dc=localdomain cn: Howard Wolowitz objectClass: person objectClass: inetOrgPerson sn: Wolowitz dn: cn=Rajesh Koothrappali,ou=People,dc=homestead,dc=localdomain cn: Rajesh Koothrappali objectClass: person objectClass: inetOrgPerson sn: Koothrappali</code>
(您將提示您輸入管理員密碼。)
<code class="language-bash">ldapadd -x -W -D "cn=admin,dc=homestead,dc=localdomain" -f users.ldif</code>
>使用:
驗證記錄(php互動,連接到服務器,搜索,更新和刪除和刪除,將在隨後的部分中隨後的部分,由於長度限制。)
以上是LDAP與PHP的要點的詳細內容。更多資訊請關注PHP中文網其他相關文章!