2007年07月23日
OpenLDAP 操作備忘
環境: Fedora Core 3, openldap 2.2.29
架構:
安裝 OpenLDAP
yum install openldap openldap-clients openldap-devel openldap-servers
基本設定
vi /etc/openldap/ldap.conf
HOST 127.0.0.1 BASE dc=mycompany,dc=com,dc=tw slappasswd
New password: your_password
Re-enter new password: your_password{SSHA}xxxxxxxxxxxx.....
vi /etc/openldap/slapd.conf
database bdb suffix "dc=mycompany,dc=com,dc=tw" rootdn "cn=Manager,dc=mycompany,dc=com,dc=tw" rootpw {SSHA}xxxxxxxxxxxx.....
編輯組織架構節點
vi /root/unit.ldif
#root
dn: dc=mycompany,dc=com,dc=tw
dc: mycompany
objectClass: dcObject
objectClass: organizationalUnit
ou: mycompany.com.tw#staff
dn: ou=staff,dc=mycompany,dc=com,dc=tw
ou: staff
objectClass: organizationalUnit
編輯公司成員資料
vi /root/staff.ldif
#Adan
dn: cn=Adan,ou=staff,dc=mycompany,dc=com,dc=tw
cn: Adan
sn: N/A
objectClass: person
objectClass: inetOrgPerson
givenName: Adan
mail: adan@mycompany.com
telephoneNumber: 04-28825252
mobile: 0912-345678
ou: Sales Dept.
o: mycompany
title: Manager#Bob
dn: cn=Bob,ou=staff,dc=mycompany,dc=com,dc=tw
cn: Bob
sn: N/A
objectClass: person
objectClass: inetOrgPerson
givenName: Bob
mail: Bob@mycompany.com
telephoneNumber: 04-28825252
mobile: 0912-345678
ou: Sales Dept.
o: mycompany
title: Sales
啟動 / 停止 LDAP Server
/etc/init.d/ldap start
/etc/init.d/ldap stop
新增
新增節點
slapadd -v -l unit.ldif
chown ldap:ldap /var/lib/ldap/*
新增公司成員
ldapadd -x -W -D 'cn=Manager,dc=mycompany,dc=com,dc=tw' -f staff.ldif
ps. slapadd 通常在 ldap server 未啟動時執行, ldapadd 只能在 ldap server 啟動的狀態下執行
查詢
列出所有資料
ldapsearch -x
只列出指定節點下的資料
ldapsearch -x -b 'ou=staff,dc=mycompany,dc=com,dc=tw'
刪除
刪除某節點 (leaf node)
ldapdelete -x -W -D 'cn=Manager,dc=mycompany,dc=com,dc=tw' cn=Adan,ou=staff,dc=mycompany,dc=com,dc=tw
刪除某節點以下 (含該節點) 的所有資料 (non-leaf node)
ldapdelete -r -x -W -D 'cn=Manager,dc=mycompany,dc=com,dc=tw' ou=staff,dc=mycompany,dc=com,dc=tw
異動
vi modify
dn: cn=Adan,ou=staff,dc=mycompany,dc=com,dc=tw
changetype: modify
replace: telephoneNumber
telephoneNumber: 02-23939889
-
add: description
description: This is a testldapmodify -x -W -D 'cn=Manager,dc=mycompany,dc=com,dc=tw' -f modify
ps. man ldapmodify 有更多的範例
安裝 GUI 管理介面
在 Windows 安裝 JXplorer
在 Linux 安裝 JXplorer
- 安裝 JRE: 請參考「在 Fedora Core 6 安裝 Freemind」
- 下載 JXplorer: JXv3.2deploy.tar.bz2
- tar jxf JXv3.2.deploy.tar.bz2
- cd jxplorer
- chmod +x jxplorer.sh
- ./jxplorer.sh
(操作畫面同上)
其他備忘
以 LDIF 格式顯示所有資料
slapcat
清除所有 LDAP 資料, 從零開始
/etc/init.d/ldap stop
rm -f /var/lib/ldap/*
slapadd -v -l new_structure.ldif
chown ldap:ldap /var/lib/ldap/*
/etc/init.d/ldap start關於 /etc/openldap/DB_CONFIG.Example
有這個檔案的 openldap, 在啟動 ldap server 前, 必須:
cp /etc/openldap/DB_CONFIG.Example /var/lib/ldap/DB_CONFIG
chown ldap:ldap /var/lib/ldap/DB_CONFIG在 e-mail 軟體中使用 LDAP 服務
相關網頁
參考資料
Posted by Jamyy at 2007年07月23日 14:38
Trackback Pings
TrackBack URL for this entry:
/cgi-bin/mt/mt-tb.cgi/294