
我們在 RHEL6 機器上部署了一個 PHP 應用程序,該應用程式依賴一些 ldap 呼叫來運行。特別是,ldap_connect 和 ldap_bind 用於驗證使用者並尋找其詳細資訊。
這種機制在我們運行於 Ubuntu 伺服器上的開發伺服器上運作得很好。在我們運行 RHEL6 的生產機器上,流程失敗。在這兩種情況下,我們都使用相同的憑證連接到同一 LDAP 伺服器,因此顯然 RHEL6 伺服器上出現了問題。我們使用基本的 LDAP,沒有 SSL 的東西。
我可以確認新伺服器上沒有防火牆或網路問題。 Ping 到 LDAP 伺服器運作得很好。此外,ldap_connect 呼叫也成功。
為了將問題與我們的應用程式隔離,我使用了以下簡單的 PHP 測試腳本:
<?php
// Set the ldap server
$ldapurl = "[snipped]";
$ldapuser = "[snipped]";
$ldappass = "[snipped]";
// Set the debug flag
$debug = true;
// Set debugging
if ($debug) {
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
}
// connect to ldap server
echo "Trying to connect<br/>";
echo "1: " . date('l jS \of F Y h:i:s A') . "<br/>";
$ldapconn = ldap_connect($ldapurl) or die ("Couldn't connect");
echo "2: " . date('l jS \of F Y h:i:s A') . "<br/>";
// binding to ldap server
echo "Trying to bind with $ldapuser - $ldappass<br/>";
echo "3: " . date('l jS \of F Y h:i:s A') . "<br/>";
$ldapbind = @ldap_bind($ldapconn, $ldapuser, $ldappass);
echo "4: " . date('l jS \of F Y h:i:s A') . "<br/>";
if (!$ldapbind) {
echo "Unable to bind to server $ldapurl\n";
echo "OpenLdap error message: " . ldap_error($ldapconn) . "\n";
exit;
}
// Rest of code goes here
?>
我在兩台伺服器上運行上述腳本。在我們的開發伺服器上,一切都很好。在我們的 RHEL6 伺服器上,連線有效,但綁定在一分鐘多的延遲後失敗:
OpenLdap 錯誤訊息:無法聯繫 LDAP 伺服器
我根本不是系統管理員,因此我無法完全理解網路上發現的有關此錯誤的大多數討論。我希望這裡有人能夠幫我解決這個問題。提前謝謝了。
答案1
與 RHEL5、RHEL6 不同需要用於連接到 openldap 的 ssl 憑證(更具體地說是 TLS)。我四處尋找解決方法,最終接受了這樣一個事實:使用 ssl 憑證比找到不使用它的方法更容易、更安全。
此連結可能有幫助: http://www.linuxquestions.org/questions/linux-enterprise-47/rhel-6-ldap-now-requires-tls-843917/
您可以嘗試強制使用舊模式,這可能會起作用,但我發現它並不完全起作用,您可能會在以後看到問題。
authconfig --enableldap --enableldapauth --forcelegacy=yes --ldapserver=myldapserver.com --ldapbasedn="dc=example,dc=com" --update
答案2
對於 centos7/RHEL7,更改您的值:
authconfig --enableforcelegacy --enableshadow --enablemd5 --enableldap --enableldapauth --disableldaptls --ldapserver=127.0.0.1 --ldapbasedn="dc=**ldap,dc=***.uk" --enablemkhomedir --disablesssd --disablesssdauth --update