歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> openldap安裝筆記

openldap安裝筆記

日期:2017/2/27 9:22:47   编辑:更多Linux
  openldap安裝筆記 Ver 0.1 2004-4-7 作者:Jims 主頁:http://www.ringkee.com 注:我的安裝方法是以源碼編譯的方式進行的,以root用戶進行安裝。 安裝所需軟件 openldap-2.1.29 http://www.openldap.org Berkeley DB 4.2.52 http://www.sleepycat.com 安裝步驟 1、由於openldap需要Berkeley DB來存放數據,所以需先安裝Berkeley DB 4.2.52,可到它的網站下載,網址見上面。 # tar -zxvf db-4.2.52.tar.gz 解完壓後,會生成一個db-4.2.52目錄,進行該目錄下的build_unix目錄。執行以下命令進行配置安裝。 # ../dist/configure # make # make install 也是按Linux源碼安裝的三步曲完成,沒有什麼好說的了。該軟件默認是安裝在/usr/local/BerkeleyDB.4.2目錄下。安裝完成後,要把/usr/local/BerkeleyDB.4.2/lib的庫路徑加到/etc/ld.so.conf文件內,添加完成後執行一次 ldconfig,使用配置文件生效。這樣編譯openldap時才能找到相應的庫文件。這樣資料庫就安裝完成了,接下來可以安裝openldap了。 ld.so.conf是什麼東西?它就是系統動態鏈接庫的配置文件。此文件內,存放著可被LINUX共享的動態鏈接庫所在目錄的名字(系統目錄 /lib,/usr/lib除外),各個目錄名間以空白字符(空格,換行等)或冒號或逗號分隔。一般的LINUX發行版中,此文件均含一個共享目錄 /usr/X11R6/lib,為X window窗口系統的動態鏈接庫所在的目錄。 ldconfig是它的管理命令,具體操作方法可查詢man手冊,這裡就不細講了。 2、到openldap官方網站下載最新的穩定版源碼,並解壓。查看INSTALLT 和README文檔,這個很重要,因為安裝方法和一些注意事項都在裡面有介紹。認真弄明白文檔內容能節省你不少的安裝調試時間。這也是開源軟件的一個特點,給用戶提供了最大的靈活性和可配置性。但也增加了系統安裝配置的難度,需要有相關的文檔配置說明和指導。在官方網站上還有詳細的幫助文件,在整個系統配置中需要經常查詢。 # tar -zxvf openldap-stable-20040329.tgz 解壓完成後,會生成一個openldap-2.1.29目錄。進行該目錄,執行以下命令進行配置安裝。 # env CPPFLAGS="-I/usr/local/BerkeleyDB.4.2/include" LDFLAGS="-L/usr/local/BerkeleyDB.4.2/lib" ./configure --prefix=/usr/local/openldap --enable-ldbm 注意以上配置語句,要設置資料庫的include和lib路徑,否則在配置到資料庫相關內容時會提示Berkeley DB版本不兼容,並中斷配置。如果沒有--enable-ldbm選項,在make test時會提示ldbm找不到。為了減少出錯,還是加上為好。 #make depens #make #make test 在make test階段要花費較長時間進行測試,好像有16項吧。你可以放松一下,上上網,聊聊天,聽聽歌,呵呵,開玩笑了,這個時間應該是最緊張的了。成不成就看這次的了。 #make install 通過配置命令可以看出,我們把openldap安裝到/usr/local/openldap目錄下。建議以源碼安裝的軟件都放到獨立的目錄下,不要放到軟件默認的目錄。好處是方便管理和控制,所有文件在統一的目錄下,卸載軟件只要刪除整個目錄就可以了。 3、ok,安裝完相關軟件後就可以著手配置了。Berkeley DB資料庫沒什麼好配置的。主要是配置openldap 服務。配置文件在軟件的安裝目錄的etc/openldap下,有四個文件,主要的是slapd.conf and ldap.conf,其它兩個是backup文件。首先,我們先來配置slapd.conf文檔。 系統默認的slapd.conf文件如下: # $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.23.2.8 2003/05/24 23:19:14 kurt EXP $ # # See slapd.conf(5) for details on configuration options. # This file should NOT be world readable. # include /usr/local/openldap/etc/openldap/schema/core.schema 設置schema配置文檔包含 # Define global ACLs to disable default read Access.


# Do not enable referrals until AFTER you have a working Directory # service AND an understanding of referrals. #referral ldap://root.openldap.org pidfile /usr/local/openldap/var/slapd.pid 設置pid和args文檔位置 argsfile /usr/local/openldap/var/slapd.args # Load dynamic backend modules: # modulepath /usr/local/openldap/libexec/openldap # moduleload back_bdb.la # moduleload back_ldap.la # moduleload back_ldbm.la # moduleload back_passwd.la # moduleload back_shell.la # Sample security restrictions # Require integrity protection (prevent hijacking) # Require 112-bit (3DES or better) encryption for updates # Require 63-bit encryption for simple bind # security ssf=1 update_ssf=112 simple_bind=64 # Sample access control policy: # Root DSE: allow anyone to read it # Subschema (sub)entry DSE: allow anyone to read it # Other DSEs: # Subschema (sub)entry DSE: allow anyone to read it # Other DSEs: # Allow self write access # Allow authenticated users read access # Allow anonymous users to authenticate # Directives needed to implement policy: # access to dn.base="" by * read # access to dn.base="cn=Subschema" by * read # access to * # by self write # by users read # by anonymous auth # # if no access controls are present, the default policy is: # Allow read by all # # rootdn can always write! ####################################################################### # ldbm database definitions ####################################################################### database bdb 設置使用的資料庫,也可用lbdm。 suffix "dc=my-domain,dc=com" 設置目錄後綴 rootdn "cn=Manager,dc=my-domain,dc=com" 設置目錄管理員 # Cleartext passWords, especially for the rootdn, should # be avoid. See slappasswd(icon_cool.gif and slapd.conf(5) for details. # Use of strong authentication encouraged. rootpw secret 設置管理密碼,這裡用了明文的secret密碼。 # The database directory MUST exist prior to running slapd AND # should only be accessible by the slapd and slap tools. # Mode 700 recommended. directory /usr/local/openldap/var/openldap-data 設置資料庫路徑 # Indices to maintain index objectClass eq 設置目錄項索引 要服務器正常動作,要修改一些始初參數和設置,修改後的配置文檔如下: # $OpenLDAP: pkg/ldap/servers/slapd/slapd.conf,v 1.23.2.8 2003/05/24 23:19:14 kurt Exp $

# # See slapd.conf(5) for details on configuration options. # This file should NOT be world readable. # include /usr/local/openldap/etc/openldap/schema/core.schema 為了有效使用目錄服務,包含相關的文件。 include /usr/local/openldap/etc/openldap/schema/corba.schema 注意,在包含文件時是要按一定順序的,因為文件 include /usr/local/openldap/etc/openldap/schema/cosine.schema 裡的屬性存在依賴關系。如果順序不對,服務器啟 include /usr/local/openldap/etc/openldap/schema/inetorgperson.schema 動不了,文檔間的依賴關系在文檔中都有說明,請 include /usr/local/openldap/etc/openldap/schema/misc.schema 仔細查看一個。如果懶得看也可以按我的順序。 include /usr/local/openldap/etc/openldap/schema/openldap.schema include /usr/local/openldap/etc/openldap/schema/nis.schema include /usr/local/openldap/etc/openldap/schema/samba.schema # Define global ACLs to disable default read access. # Do not enable referrals until AFTER you have a working directory # service AND an understanding of referrals. #referral ldap://root.openldap.org pidfile /usr/local/openldap/var/slapd.pid argsfile /usr/local/openldap/var/slapd.args loglevel 1 增加了日志功能,需修改syslog配置文件,在文件中增加一項:local4.* /var/log/ldap.log 日志級別定義可查相官方網站的文檔。1級記錄的信息很多。可用於調試。 # Load dynamic backend modules: # modulepath /usr/local/openldap/libexec/openldap # moduleload back_bdb.la # moduleload back_ldap.la # moduleload back_ldbm.la # moduleload back_passwd.la # moduleload back_shell.la # Sample security restrictions # Require integrity protection (prevent hijacking) # Require 112-bit (3DES or better) encryption for updates # Require 63-bit encryption for simple bind # security ssf=1 update_ssf=112 simple_bind=64 # Sample access control policy: # Root DSE: allow anyone to read it # Subschema (sub)entry DSE: allow anyone to read it # Other DSEs: # Allow self write access # Allow authenticated users read access # Allow anonymous users to authenticate # Directives needed to implement policy: # access to dn.base="" by * read # access to dn.base="cn=Subschema" by * read # access to * # by self write # by users read # by anonymous auth # # if no access controls are present, the default policy is: # Allow read by all # # rootdn can always write! ####################################################################### # ldbm database definitions ####################################################################### database bdb suffix "dc=it,dc=com" 改成你自已的目錄後綴, rootdn "cn=root,dc=it,dc=com" 設置root為管理員,與linux的root沒有什麼關系。 # Cleartext passwords, especially for the rootdn, should # be avoid. See slappasswd(icon_cool.gif and slapd.conf(5) for details. # Use of strong authentication encouraged.

rootpw {MD5}mjkiuPt0wXhpxxkdiOOO+0000000AKq0by 設置root密碼,用MD5加密。密碼串用slappasswd -h {MD5}指令 # The database directory MUST exist prior to running slapd AND # should only be accessible by the slapd and slap tools. # Mode 700 recommended. directory /usr/local/openldap/var/openldap-data # Indices to maintain index objectClass eq 這裡可根據你的需要設置相關索引,以加快查詢速度。具體內容可查詢官方網站管理手冊。 #ACL configure 以下內容定義訪問控制 access to attr=userPassword userPassword只能由自已修改,有效驗證用戶查詢。 by self write by anonymous auth access to attr=mail by dn="cn=root,dc=it,dc=tigerhead" write mail只能由自已修改,有效驗證用戶查詢。 by self write by anonymous auth access to dn=".*,dc=it,dc=tigerhead" 允許所有人查詢沒受控制訪問限制的信息。 by self write by * read ok,到現在為止,服務器基本就配置完成了,可以啟動了,服務器程序是位於安裝目錄的libexec下的slapd程序。注意,不是sldap哦。 # ./slapd 如果沒有提示什麼出錯信息,直接返回shell狀態,就說明服務器正常啟動了,你可以查詢日志或用ps -aux查看。或用以下命令查詢服務器。 ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts 如果命令執行成功,返回一些信息,則說明服務器正常運行了。如果啟動不成功,它會提示一些出錯信息,多數是slapd.conf配置出錯。回頭仔細核查一下配置文檔。 4、客戶端配置文檔是ldap.conf。該文檔相當簡單,其實不和配置也能正常操作。 # $OpenLDAP: pkg/ldap/libraries/libldap/ldap.conf,v 1.9 2000/09/04 19:57:01 kurt Exp $ # # LDAP Defaults # # See ldap.conf(5) for details # This file should be world readable but not world writable. BASE dc=it, dc=com 設置目錄起點 #URI ldap://ldap.example.com ldap://ldap-master.example.com:666 #SIZELIMIT 12 #TIMELIMIT 15 #DEREF never 5、ok,服務器正常運作後,就可以錄入信息了。信息的錄入有三種方法,一種是手工錄入,一種是.ldif文件格式錄入,一種是腳本自動錄入。我們先從最基礎的手工錄入方式開始介紹,了解錄入信息的格式。明白了手工錄入的格式,其它兩種方式都很容易明白。信息錄入用到ldapadd這個程序。可在安裝目錄的bin目錄下找到。具體用法如下: 第一步是要建立DN: # ldapadd -x -D 'cn=root,dc=it,dc=com' -W dn: dc=it,dc=com objectClass: dcObject objectClass: organization dc: it o: Corporation description: d Corporation 注意:如果你用復制/粘貼功能把以上內容拷貝過去,一定要注意每行後面不要有空格。 第二步是建立RDN: # ldapadd -x -D 'cn=root,dc=it,dc=com' -W -x表示用簡單驗證,-D表示指定目錄,-W表示彈出密碼輸入提示 dn: uid=QQ,dc=it,dc=com objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson uid: qq cn: qq sn: qq telephoneNumber: 138888888 description: openldap test telexNumber: tex-8888888 street: my street postOfficeBox: postofficebox displayName: qqdisplay homePhone: home1111111 mobile: mobile99999 mail:[email protected]

輸入完所有信息後,按Ctrl+d結束存盤。如果出現出錯信息,請查一下對象類和屬性的對應關系有沒有錯或輸入失誤。初學者就容易出錯的地方是對象類和屬性的對應關系沒有處理好。對象類和屬性是在schema文檔中定義的。它們之間的關系是這樣的,對象類中有些屬性是必選的,有些屬性是可選的。錄入信息的屬性必須在對象類中有定義才能用。 輸入以下命令可查詢到剛才輸入的信息。 # ldapsearch -x -b 'dc=it,dc=com' -b設置目錄起點,如果設置了BASE參數,該項可不用。 如果按以上配置文件設置了acl,用上面的查詢命令是查詢不到受保護的內容的。如上面的userPassword and mail。要查詢到這些受限內容,需要通過驗證才可以。 # ldapsearch -x -LLL -h it.com -b 'dc=it,dc=com' -D 'uid=qq,dc=it,dc=com' -W 'uid=qq' 接著提示輸入密碼。輸入userPassword的密碼回車,所有信息就都出來了。 .ldif文件方式也就是把以上手工輸入的內容先寫入一個.ldif文件中,然後,用ldapadd命令的-f參數導入。 # ldapadd -x -D "cn=root,dc=it,dc=com" -W -f test.ldif 一個完整的global.ldif文件例子: dn: dc=info, dc=net objectClass: top objectClass: organization o: info.net dn: ou=People, dc=info, dc=net objectClass: top objectClass: organizationalUnit ou: People description: User Info dn: cn=Admin, dc=info, dc=net objectClass: top objectClass: person objectClass: organizationalPerson cn: Admin sn: Admin userPassword: Admin description: Administrator for info.net dn: id=1, ou=people, dc=info, dc=net objectclass: top objectclass: InfoPerson id: 1 username: 張三 tel:021-63138990 card_id:ABC001 再次提醒,注意每行後面不要留有空格。 腳本錄入方式需要自已編寫腳本,或到網上下載。有一個用PHP寫的LDAP管理工具不錯,叫phpLDAPadmin。可以到以下網址下載: http://phpldapadmin.sourceforge.net/。安裝方法也很簡單,只要解壓出來,拷貝到apache的web目錄下,按說明配置一下設定文檔,就ok了。 接著為大家介紹一下幾個常用的ldap命令,如果你用了phpLDAPadmin程序,其實它已經有一個很好的圖形介面幫你完成這些命令了。但了解一下還是對你還是很有益的,因為命令方法才是最根本的。 1、刪除命令ldapdelete # ldapdelete -x -D 'cn=root,dc=it,dc=com' -W 'uid=qq1,dc=it,dc=com' 2、設置使用者密碼,當然了,你的用戶需要有userPassword項了。 #ldappasswd -x -D "cn=root,dc=it,dc=com" -W "uid=qq1,dc=it,dc=com" -S New password: Re-enter new password: Enter bind password: Result: SUCcess (0) 注意:"Enter bind password" 是 "cn=root,dc=it,dc=com"管理員的密碼。 3、管理員密碼更改 #slappasswd New password Re-enter new password {SSHA}83DJ4KVwqlk1uh9k2uDb8+NT1U4RgkEs 接下?碓倏降



dn: dc=info, dc=net objectClass: top objectClass: organization o: info.net dn: ou=People, dc=info, dc=net objectClass: top objectClass: organizationalUnit ou: People description: User Info dn: cn=Admin, dc=info, dc=net objectClass: top objectClass: person objectClass: organizationalPerson cn: Admin sn: Admin userPassword: Admin description: Administrator for info.net dn: id=1, ou=people, dc=info, dc=net objectclass: top objectclass: InfoPerson id: 1 username: 張三 tel:021-63138990 card_id:ABC001 再次提醒,注意每行後面不要留有空格。 腳本錄入方式需要自已編寫腳本,或到網上下載。有一個用PHP寫的LDAP管理工具不錯,叫phpLDAPadmin。可以到以下網址下載: http://phpldapadmin.sourceforge.net/。安裝方法也很簡單,只要解壓出來,拷貝到apache的web目錄下,按說明配置一下設定文檔,就ok了。 接著為大家介紹一下幾個常用的ldap命令,如果你用了phpLDAPadmin程序,其實它已經有一個很好的圖形介面幫你完成這些命令了。但了解一下還是對你還是很有益的,因為命令方法才是最根本的。 1、刪除命令ldapdelete # ldapdelete -x -D 'cn=root,dc=it,dc=com' -W 'uid=qq1,dc=it,dc=com' 2、設置使用者密碼,當然了,你的用戶需要有userPassword項了。 #ldappasswd -x -D "cn=root,dc=it,dc=com" -W "uid=qq1,dc=it,dc=com" -S New password: Re-enter new password: Enter bind password: Result: SUCcess (0) 注意:"Enter bind password" 是 "cn=root,dc=it,dc=com"管理員的密碼。 3、管理員密碼更改 #slappasswd New password Re-enter new password {SSHA}83DJ4KVwqlk1uh9k2uDb8+NT1U4RgkEs 接下?碓倏降



# ldapsearch -x -LLL -h it.com -b 'dc=it,dc=com' -D 'uid=qq,dc=it,dc=com' -W 'uid=qq' 接著提示輸入密碼。輸入userPassword的密碼回車,所有信息就都出來了。 .ldif文件方式也就是把以上手工輸入的內容先寫入一個.ldif文件中,然後,用ldapadd命令的-f參數導入。 # ldapadd -x -D "cn=root,dc=it,dc=com" -W -f test.ldif 一個完整的global.ldif文件例子: dn: dc=info, dc=net objectClass: top objectClass: organization o: info.net dn: ou=People, dc=info, dc=net objectClass: top objectClass: organizationalUnit ou: People description: User Info dn: cn=Admin, dc=info, dc=net objectClass: top objectClass: person objectClass: organizationalPerson cn: Admin sn: Admin userPassword: Admin description: Administrator for info.net dn: id=1, ou=people, dc=info, dc=net objectclass: top objectclass: InfoPerson id: 1 username: 張三 tel:021-63138990 card_id:ABC001 再次提醒,注意每行後面不要留有空格。 腳本錄入方式需要自已編寫腳本,或到網上下載。有一個用PHP寫的LDAP管理工具不錯,叫phpLDAPadmin。可以到以下網址下載: http://phpldapadmin.sourceforge.net/。安裝方法也很簡單,只要解壓出來,拷貝到apache的web目錄下,按說明配置一下設定文檔,就ok了。 接著為大家介紹一下幾個常用的ldap命令,如果你用了phpLDAPadmin程序,其實它已經有一個很好的圖形介面幫你完成這些命令了。但了解一下還是對你還是很有益的,因為命令方法才是最根本的。 1、刪除命令ldapdelete # ldapdelete -x -D 'cn=root,dc=it,dc=com' -W 'uid=qq1,dc=it,dc=com' 2、設置使用者密碼,當然了,你的用戶需要有userPassword項了。 #ldappasswd -x -D "cn=root,dc=it,dc=com" -W "uid=qq1,dc=it,dc=com" -S New password: Re-enter new password: Enter bind password: Result: SUCcess (0) 注意:"Enter bind password" 是 "cn=root,dc=it,dc=com"管理員的密碼。 3、管理員密碼更改 #slappasswd New password Re-enter new password {SSHA}83DJ4KVwqlk1uh9k2uDb8+NT1U4RgkEs 接下?碓倏降



Copyright © Linux教程網 All Rights Reserved