日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CentOS 6.9下OpenLDAP 的安装与配置

發(fā)布時(shí)間:2025/5/22 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CentOS 6.9下OpenLDAP 的安装与配置 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

LDAP 基礎(chǔ)教程

LDAP 全稱輕量級目錄訪問協(xié)議(英文:Lightweight Directory Access Protocol),是一個(gè)運(yùn)行在 TCP/IP 上的目錄訪問協(xié)議。LDAP實(shí)現(xiàn)提供被稱為目錄服務(wù)的信息服務(wù),可以看做是一張?zhí)厥獾臄?shù)據(jù)庫系統(tǒng)。可以有效的解決眾多網(wǎng)絡(luò)服務(wù)的用戶賬戶問題,規(guī)定了統(tǒng)一的身份信息數(shù)據(jù)庫、身份認(rèn)證機(jī)制和接口,實(shí)現(xiàn)了資源和信息的統(tǒng)一管理,保證了數(shù)據(jù)的一致性和完整性。

使用場景

有兩個(gè)系統(tǒng)A,B;需要把A系統(tǒng)創(chuàng)建的用戶同步到B中,而B是個(gè)apache 開源項(xiàng)目,此時(shí)需要借助LDAP來解決。首先在A中建用戶的同時(shí),同步更新到LDAP中,然后B系統(tǒng)從LDAP中同步到自己的系統(tǒng)中,這樣就實(shí)現(xiàn)了A中的用戶到B系統(tǒng)的同步。

LDAP理解

在LDAP中,信息以樹狀方式組織,基本數(shù)據(jù)單元是條目,而每個(gè)條目由屬性構(gòu)成,屬性由類型(Type)和一個(gè)或多個(gè)值(Value)組成。

Entry

包含的信息描述了現(xiàn)實(shí)世界中的一個(gè)真實(shí)的對象,在目錄系統(tǒng)中可以理解為一個(gè)節(jié)點(diǎn)。在目錄中添加一個(gè)Entry時(shí),該Entry必須屬于一個(gè)或者多個(gè)對象類(Oject Class),Entry的類型由屬性O(shè)bject Class規(guī)定。每個(gè)Entry都有一個(gè)唯一的DN(distinguished name)來標(biāo)識Entry在directory中的位置。用Java的方式Entry相當(dāng)于一個(gè)Instances,而Ojbect class自然就是Class。

根節(jié)點(diǎn)DN的命名有多種方法,其中之一就是域名命名法,例如sohu.com根階節(jié)點(diǎn)的DN應(yīng)該是DN:dc=sohu,dc=com,People節(jié)點(diǎn)的DN:ou=People,dc=example,dc=com,RDN是目錄樹中節(jié)點(diǎn)的相對標(biāo)識,例如People節(jié)點(diǎn)的RDN:ou=people。

Attribute

每個(gè)Entry都是由許多Attribute組成,每個(gè)屬性描述的是對象的一個(gè)特征,每個(gè)屬性由一個(gè)類型和一個(gè)或多個(gè)值Value組成。
每個(gè)屬性類型有所對應(yīng)的語法和匹配規(guī)則;對象類和屬性類型的定義均可以使用繼承的概念。每個(gè)條目創(chuàng)建時(shí),必須定義所屬的對象類,必須提供對象類中的必選屬性類型的屬性值,在LDAP中一個(gè)屬性類型可以對應(yīng)多個(gè)值。
常見屬性:

屬性名是否必填描述
c國家
dcdomain component,常用來指一個(gè)域名的一部分
o該條目所屬的組織名(Organization Name)
ou一個(gè)組織單元的名字
cncommon name,一個(gè)對象的名字,如果指人,使用全名
snSurname,一個(gè)人的姓
uidUserid,某個(gè)用戶的登錄名,與Linux系統(tǒng)中用戶的uid不同
userPassword登陸密碼
mail郵箱
givenName一個(gè)人的名
displayName顯示條目時(shí)要使用的首選名稱
uidNumber賬號的UID
gidNumber賬號的GID
homeDirectory用戶的家目錄指定
loginShell用戶登錄的SHELL
employeeNumber工號相關(guān)信息
homePhone家庭電話
mobile該條目的手機(jī)號碼
description該條目的描述信息

Object class

在LDAP中,一個(gè)條目必須包含一個(gè)Oject class屬性,且需要賦予至少一個(gè)值。每個(gè)值將用作一條LDAP條目進(jìn)行數(shù)據(jù)存儲的模板,模板中包含了一個(gè)條目必須被賦值的屬性和可選的屬性。
Object分為三類,結(jié)構(gòu)型(Structural),如Person和orginzationUnit,輔助型(Auxiliary),如extensibeObject,抽象型(Abstract):如top,抽象型的ObjectClass不能直接使用。
下面部分常用的ObjectClass,定義在/etc/openldap/schema/core.schema文件中

名稱描述必要屬性
domain
organizationo
organizationalUnitou
personsn,cn
organizationPersoncn,sn
top抽象型,頂級ObjectClass
posixAccountLinux用戶cn,gidNumber,homeDirectory,uid,uidNumber
posixGroupLinux用戶組cn,gidNumber
  • Entry必須僅包含一個(gè)Structural類型的OjectClass,其他兩種類型可包括0或者多個(gè)。

LDAP 功能模型

描述LDAP 協(xié)議可以采用的相關(guān)操作,來訪問存儲在目錄樹中的數(shù)據(jù),可以將操作分
成三組:
(1) 更新操作 包括添加,刪除,重命名,修改Entry
(2) Interrogation Operation 用于數(shù)據(jù)的查詢
(3) 認(rèn)證和控制 (bind unbind abandon)

LDAP 安全模型

(1) 提供一個(gè)框架,包含目錄中的信息不被非法訪問,LDAP 的安全模型主要是通過身份認(rèn)
證、安全通道和訪問控制(ACL)來實(shí)現(xiàn)。
(2) LDAP 是一個(gè)面向連接的協(xié)議,在能夠?qū)DAP 目錄進(jìn)行任何操作之前,LDAP 客戶端
端必須獲得一個(gè)到LDAP 服務(wù)端的一個(gè)連接,在這個(gè)過程中需要對LDAP 客戶端的身份進(jìn)
行驗(yàn)證(可以理解為用戶綁定)。
(3) 在用戶通過驗(yàn)證之后,為用戶分配附加的權(quán)限,比如一些用戶只能查看特定的Entry,而不能修改。一些用戶可以查看并且修改所有的Entry等。

下面是一個(gè)典型的 LDAP 目錄樹結(jié)構(gòu),其中每個(gè)節(jié)點(diǎn)表示一個(gè)條目。在下一節(jié)中,我們將按照這個(gè)結(jié)構(gòu)來配置一個(gè)簡單的 LDAP 服務(wù)。

本文僅涉及沒有SSL的OpenLDAP配置。

一、環(huán)境準(zhǔn)備

兩臺虛擬機(jī)

IPhostname說明
192.168.1.101openldap-serverserver端
192.168.1.102openldap-clientclient端

關(guān)閉SELinux

查看SELinux狀態(tài):getenforce, 或/usr/sbin/sestatus
臨時(shí)關(guān)閉:

setenforce 0

永久關(guān)閉:

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config grep SELINUX=disabled /etc/selinux/config

關(guān)閉iptables

chkconfig iptables off /etc/init.d/iptables stop /etc/init.d/iptables status

官方文檔:

http://www.openldap.org/doc/admin24/

步驟
分為server端操作和client端操作

二、server端安裝OpenLDAP

1. yum安裝OpenLDAP

[root@openldap-server ~]# yum install openldap openldap-servers openldap-servers-sql openldap-clients openldap-devel compat-openldap -y

OpenLDAP的相關(guān)配置文件信息

  • /etc/openldap/slapd.conf:OpenLDAP的主配置文件,記錄根域信息,管理員名稱,密碼,日志,權(quán)限等
  • /etc/openldap/slapd.d/*:這下面是/etc/openldap/slapd.conf配置信息生成的文件,每修改一次配置信息,這里的東西就要重新生成
  • /etc/openldap/schema/*:OpenLDAP的schema存放的地方
  • /var/lib/ldap/*:OpenLDAP的數(shù)據(jù)文件
  • /usr/share/openldap-servers/slapd.conf.obsolete 模板配置文件
  • /usr/share/openldap-servers/DB_CONFIG.example 模板數(shù)據(jù)庫配置文件

OpenLDAP監(jiān)聽的端口:

  • 默認(rèn)監(jiān)聽端口:389(明文數(shù)據(jù)傳輸)
  • 加密監(jiān)聽端口:636(密文數(shù)據(jù)傳輸)

2. 復(fù)制ldap配置文件到/etc

[root@openldap-server ~]# cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf

3. 生成ldap管理員密碼(把ldappassword改為自己的管理員密碼)

[root@openldap-server ~]# slappasswd -s ldappassword {SSHA}b6YpCvRFWAWQdJpueuyzk79VXlikj4Z1

4. 修改slapd.conf

修改其中cn,dc相關(guān)內(nèi)容,及rootpw密文密碼,rootpw配置上面設(shè)置的密碼
(rootpw必須頂格寫,與密碼Tab鍵分開)

[root@openldap-server ~]# cp /etc/openldap/slapd.conf /etc/openldap/slapd.conf.bak [root@openldap-server ~]# vim /etc/openldap/slapd.conf ...... database bdb suffix "dc=qq,dc=com" checkpoint 1024 15 rootdn "cn=Manager,dc=qq,dc=com" #管理LDAP中信息的最高權(quán)限,即管理員權(quán)限,登陸時(shí)用。 ...... rootpw {SSHA}b6YpCvRFWAWQdJpueuyzk79VXlikj4Z1

檢測/etc/openldap/slapd.conf是否有錯(cuò)誤

[root@openldap-server ~]# slaptest -f /etc/openldap/slapd.conf config file testing succeeded

5. 檢測并重新生成ldap數(shù)據(jù)庫

[root@openldap-server ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG # 拷貝DB_CONFIG文件 [root@openldap-server ~]# cd /etc/openldap/ [root@openldap-server openldap]# ls -l slapd.d/ drwxr-x--- 3 ldap ldap 4096 7月 13 13:59 cn=config -rw-r----- 1 ldap ldap 1281 7月 13 13:50 cn=config.ldif [root@openldap-server openldap]# rm -rf slapd.d/* # 刪除默認(rèn)配置 (否則添加ldap用戶時(shí)會(huì)報(bào)錯(cuò)) [root@openldap-server openldap]#官方對于OpenLDAP2.4 ,不推薦使用 slapd.conf 作為配置文件。從這個(gè)版本開始所有配置數(shù)據(jù)都保存在 /etc/openldap/slapd.d/中[root@openldap-server openldap]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/ 5b02d207 bdb_db_open: database "dc=qq,dc=com": db_open(/var/lib/ldap/id2entry.bdb) failed: No such file or directory (2). 5b02d207 backend_startup_one (type=bdb, suffix="dc=qq,dc=com"): bi_db_open failed! (2) slap_startup failed (test would succeed using the -u switch) [root@openldap-server openldap]# slaptest -u config file testing succeeded 出現(xiàn)succeed繼續(xù)

6. 修改相關(guān)ldap文件權(quán)限

[root@openldap-server openldap]# chown -R ldap:ldap /var/lib/ldap/ [root@openldap-server openldap]# chown -R ldap:ldap /etc/openldap/

7. 啟動(dòng)slapd服務(wù)

[root@openldap-server openldap]# service slapd start Starting slapd: [ OK ] [root@openldap-server openldap]# service slapd status slapd (pid 12896) is running... [root@openldap-server openldap]# chkconfig slapd on [root@openldap-server openldap]# lsof -i:389 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME slapd 12896 ldap 7u IPv4 702934 0t0 TCP *:ldap (LISTEN) slapd 12896 ldap 8u IPv6 702935 0t0 TCP *:ldap (LISTEN)

三、OpenLDAP日志功能開啟

1. slapd.conf配置文件里加上日志行

這里的日志級別有很多種,這里選擇256這個(gè)值的級別(主從節(jié)點(diǎn)都要打開openldap日志功能)

[root@openldap-master ~]# cp /etc/openldap/slapd.conf{,.bak3} [root@openldap-master ~]# vim /etc/openldap/slapd.conf #中間的空格用tab鍵分開 ....... # 最后添加 loglevel 256

2. 修改了配置文件,所有得重新生成配置文件的信息

[root@openldap-master ~]# rm -rf /etc/openldap/slapd.d/* [root@openldap-master ~]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/ config file testing succeeded [root@openldap-master ~]# slaptest -u config file testing succeeded [root@openldap-master ~]# chown -R ldap:ldap /var/lib/ldap/ [root@openldap-master ~]# chown -R ldap:ldap /etc/openldap/

3. 修改/etc/rsyslog.conf文件,加上下面內(nèi)容

[root@openldap-master ~]# cp /etc/rsyslog.conf{,.bak} [root@openldap-master ~]# vim /etc/rsyslog.conf ........ # 最后添加 local4.* /var/log/slapd/slapd.log

4. 創(chuàng)建日志文件目錄,授權(quán)

[root@openldap-master ~]# mkdir /var/log/slapd [root@openldap-master ~]# chmod 755 /var/log/slapd/ [root@openldap-master ~]# chown ldap.ldap /var/log/slapd/

5. 重啟syslog服務(wù)和slapd服務(wù)

[root@openldap-master ~]# /etc/init.d/rsyslog restart Shutting down system logger: [ OK ] Starting system logger: [ OK ][root@openldap-master ~]# /etc/init.d/slapd restart Stopping slapd: [ OK ] Starting slapd: [ OK ] [root@openldap-master ~]# lsof -i:389 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME slapd 13773 ldap 7u IPv4 840484 0t0 TCP *:ldap (LISTEN) slapd 13773 ldap 8u IPv6 840485 0t0 TCP *:ldap (LISTEN)

6. 查看openldap日志信息

[root@openldap-master ~]# tail -f /var/log/slapd/slapd.log

四、server端安裝migrationtools,創(chuàng)建根域條目(可選)

參考:http://book.51cto.com/art/201602/505737.htm

1. 安裝migrationtools 工具

migrationtools 實(shí)現(xiàn)OpenLDAP 用戶及用戶組的添加。

[root@openldap-server openldap]# yum install migrationtools -y

2. 編輯/usr/share/migrationtools/migrate_common.ph并修改相關(guān)配置

[root@openldap-server openldap]# cp /usr/share/migrationtools/migrate_common.ph{,.bak} [root@openldap-server openldap]# vim /usr/share/migrationtools/migrate_common.ph # 搜索”dc=”,值改為與slapd.conf一致內(nèi)容 ...... # Default DNS domain $DEFAULT_MAIL_DOMAIN = "qq.com";# Default base $DEFAULT_BASE = "dc=qq,dc=com";

3. 創(chuàng)建OpenLDAP 根域條目,base.ldif

[root@openldap-server openldap]# /usr/share/migrationtools/migrate_base.pl > base.ldif [root@openldap-server openldap]# cat base.ldif dn: dc=qq,dc=com dc: qq objectClass: top objectClass: domaindn: ou=Hosts,dc=qq,dc=com ou: Hosts objectClass: top objectClass: organizationalUnitdn: ou=Rpc,dc=qq,dc=com ou: Rpc objectClass: top objectClass: organizationalUnitdn: ou=Services,dc=qq,dc=com ou: Services objectClass: top objectClass: organizationalUnitdn: nisMapName=netgroup.byuser,dc=qq,dc=com nismapname: netgroup.byuser objectClass: top objectClass: nisMapdn: ou=Mounts,dc=qq,dc=com ou: Mounts objectClass: top objectClass: organizationalUnitdn: ou=Networks,dc=qq,dc=com ou: Networks objectClass: top objectClass: organizationalUnitdn: ou=People,dc=qq,dc=com ou: People objectClass: top objectClass: organizationalUnitdn: ou=Group,dc=qq,dc=com ou: Group objectClass: top objectClass: organizationalUnitdn: ou=Netgroup,dc=qq,dc=com ou: Netgroup objectClass: top objectClass: organizationalUnitdn: ou=Protocols,dc=qq,dc=com ou: Protocols objectClass: top objectClass: organizationalUnitdn: ou=Aliases,dc=qq,dc=com ou: Aliases objectClass: top objectClass: organizationalUnitdn: nisMapName=netgroup.byhost,dc=qq,dc=com nismapname: netgroup.byhost objectClass: top objectClass: nisMap

可以編輯base.ldif 進(jìn)行修改,將不需要的條目刪除,然后通過ldapadd 導(dǎo)入至OpenLDAP目錄樹。

4. 添加base.ldif到ldap(輸入密碼為上面創(chuàng)建的:ldappassword)

[root@openldap-server openldap]# ldapadd -x -D "cn=Manager,dc=qq,dc=com" -w ldappassword -f ./base.ldif Enter LDAP Password:ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1) '出現(xiàn)這個(gè)錯(cuò)誤的時(shí)候,查看服務(wù)和端口都已經(jīng)開啟了,需要你手動(dòng)指定主機(jī)名和你的端口號(ldap端口號為389),使用-h 加上主機(jī)名。[root@openldap-server openldap]# ldapadd -x -D "cn=Manager,dc=qq,dc=com" -w ldappassword -f ./base.ldif -h openldap-server -p 389adding new entry "dc=qq,dc=com"adding new entry "ou=Hosts,dc=qq,dc=com"adding new entry "ou=Rpc,dc=qq,dc=com"adding new entry "ou=Services,dc=qq,dc=com"adding new entry "nisMapName=netgroup.byuser,dc=qq,dc=com"adding new entry "ou=Mounts,dc=qq,dc=com"adding new entry "ou=Networks,dc=qq,dc=com"adding new entry "ou=People,dc=qq,dc=com"adding new entry "ou=Group,dc=qq,dc=com"adding new entry "ou=Netgroup,dc=qq,dc=com"adding new entry "ou=Protocols,dc=qq,dc=com"adding new entry "ou=Aliases,dc=qq,dc=com"adding new entry "nisMapName=netgroup.byhost,dc=qq,dc=com"

5. 檢查ldapadd是否成功(密碼為上面創(chuàng)建的:ldappassword)(必須檢查確認(rèn)Manager數(shù)據(jù)添加了,才能通過phpldapAdmin登錄)

[root@openldap-server openldap]# ldapsearch -x -D "cn=Manager,dc=qq,dc=com" -b "ou=Aliases,dc=qq,dc=com" -w ldappassword # extended LDIF # # LDAPv3 # base <ou=Aliases,dc=qq,dc=com> with scope subtree # filter: (objectclass=*) # requesting: ALL ## Aliases, qq.com dn: ou=Aliases,dc=qq,dc=com ou: Aliases objectClass: top objectClass: organizationalUnit# search result search: 2 result: 0 Success# numResponses: 2 # numEntries: 1

六、安裝openLdap桌面服務(wù)

1. yum安裝httpd及PhpLdapAdmin

[root@openldap-server openldap]# rpm -ivh http://mirrors.ukfast.co.uk/sites/dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm [root@openldap-server openldap]# yum install httpd phpldapadmin -y

2. 配置/etc/httpd/conf.d/phpldapadmin.conf允許從遠(yuǎn)程訪問

[root@openldap-server openldap]# cp -a /etc/httpd/conf.d/phpldapadmin.conf{,.bak} #可以先把此文件cp備份一份 [root@openldap-server openldap]# vim /etc/httpd/conf.d/phpldapadmin.conf Alias /phpldapadmin /usr/share/phpldapadmin/htdocs Alias /ldapadmin /usr/share/phpldapadmin/htdocs <Directory /usr/share/phpldapadmin/htdocs> Order Deny,Allow Allow from all Allow from 127.0.0.1 #或者去掉下面這三行內(nèi)容,表示運(yùn)行所有客戶機(jī)訪問(本測試案例就去掉了這三行)Allow from ::1Allow from all #允許哪些IP地址訪問phpldapadmin,我寫的全部。 </Directory>

3. 修改/etc/phpldapadmin/config.php配置用DN登錄

[root@openldap-server openldap]# cp /etc/phpldapadmin/config.php{,.bak} [root@openldap-server openldap]# vim /etc/phpldapadmin/config.php ....... //$servers->setValue('login','attr','uid'); #注釋掉這一行 $servers->setValue('login','attr','dn'); #添加這一行[root@openldap-server openldap]# diff /etc/phpldapadmin/config.php /etc/phpldapadmin/config.php.bak 398,399c398,399 < //$servers->setValue('login','attr','uid'); < $servers->setValue('login','attr','dn'); --- > $servers->setValue('login','attr','uid'); >

4. 啟動(dòng)httpd服務(wù)

[root@openldap-server openldap]# chkconfig httpd on [root@openldap-server openldap]# service httpd start Starting httpd: httpd: apr_sockaddr_info_get() failed for openldap-server httpd: Could not reliably determine the server's' fully qualified domain name, using 127.0.0.1 for ServerName[ OK ] [root@openldap-server openldap]# service httpd status httpd (pid 13010) is running... [root@openldap-server openldap]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 13010 root 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13012 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13013 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13014 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13015 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13016 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13017 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13018 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN) httpd 13019 apache 4u IPv6 757231 0t0 TCP *:http (LISTEN)

5. 打開Web UI并登錄LDAP

URL: $IP/phpldapadmin 用戶名 "cn=Manager,dc=qq,dc=com" 密碼 "ldappassword"

七、新建組織(公司)、管理員、組及用戶

添加用戶和用戶組的方式有兩種。一種是將系統(tǒng)用戶通過migrationtools 工具生成LDIF 文件并結(jié)合ldapadd 命令導(dǎo)入OpenLDAP 目錄樹中,生成OpenLDAP 用戶。另一種通過自定義LDIF 文件并通過OpenLDAP 命令進(jìn)行添加或者修改操作。本文主要介紹第二種來完成OpenLDAP用戶的添加。

1. 組織

創(chuàng)建組織:

[root@openldap-server data]# vim o.ldif #在根目錄下建立不同組織 dn: o=tengxun,dc=qq,dc=com objectclass: top objectclass: dcobject objectclass: organization dc: qq o: tengxun description: 騰訊 street: 深圳騰訊大廈

此LDIF 文件中存在中文字符,建議使用Linux dos2unix 命令進(jìn)行轉(zhuǎn)換,例如dos2unix -k –n filenew_file。作者建議盡可能不要使用中文字符進(jìn)行添加,而使用英文添加。

導(dǎo)入組織數(shù)據(jù)

[root@openldap-server data]# ldapadd -x -D "cn=Manager,dc=qq,dc=com" -w ldappassword -f ./o.ldif -h openldap-server -p 389 adding new entry "o=tengxun,dc=qq,dc=com"

============================================================
如果報(bào)錯(cuò):

[root@openldap-server data]# ldapadd -x -D "cn=Manager,dc=qq,dc=com" -w ldappassword -f ./o.ldif -h openldap-server -p 389 ldapadd: attributeDescription "dn": (possible missing newline after line 3, entry "o=tengxun,dc=qq,dc=com"?) adding new entry "o=tengxun,dc=qq,dc=com" ldap_add: Type or value exists (20)additional info: ou: value #0 provided more than once

產(chǎn)生原因:o.ldif文件中的不規(guī)范的空格所致!!即導(dǎo)入的數(shù)據(jù)含有空格所致!
糾錯(cuò)如下:

dn:(空格)o=tengxun,dc=qq,dc=com changetype:(空格)add(結(jié)尾無空格) objectclass:(空格)top(結(jié)尾無空格) objectclass:(空格)organizationalUnit(結(jié)尾無空格) ou:(空格)echnology(結(jié)尾無空格) (1空行,空行必須要定格,不能留空格)(結(jié)尾無空格) ........(后面的配置內(nèi)容糾正方法同樣)

===========================================================

查詢剛導(dǎo)入數(shù)據(jù)

[root@openldap-server data]# ldapsearch -x -D "cn=Manager,dc=qq,dc=com" -b "o=tengxun,dc=qq,dc=com" -w ldappassword -h openldap-server -p 389 # extended LDIF # # LDAPv3 # base <o=tengxun,dc=qq,dc=com> with scope subtree # filter: (objectclass=*) # requesting: ALL ## tengxun, qq.com dn: o=tengxun,dc=qq,dc=com objectClass: top objectClass: dcObject objectClass: organization dc: qq o: tengxun description:: 572R5biF street:: 5YyX5Lqs5biC5a6J57+U5YyX6YeM55SyMTHlj7fljJfkuqzliJvkuJrlpKfljqZC5bqnNzAx5a6k# search result search: 2 result: 0 Success# numResponses: 2 # numEntries: 1

2. 管理員及組

在新建組織下創(chuàng)建管理員及組

在tengxun組織下創(chuàng)建一個(gè) Manager 的組織角色(該角色內(nèi)的用戶具有管理整個(gè) LDAP 的權(quán)限)和 People 和 Group 兩個(gè)組織單元: [root@openldap-server data]# vim admin_group.ldif # admin dn: cn=Manager,o=tengxun,dc=qq,dc=com objectClass: organizationalRole cn: Manager# Group組 dn: ou=Group,o=tengxun,dc=qq,dc=com ou: Group objectClass: organizationalUnit# People組 dn: ou=People,o=tengxun,dc=qq,dc=com ou: People objectClass: organizationalUnit

導(dǎo)入組數(shù)據(jù)

[root@openldap-server data]# ldapadd -x -D "cn=Manager,dc=qq,dc=com" -w ldappassword -f ./admin_group.ldif -h openldap-server -p 389 adding new entry "cn=Manager,o=tengxun,dc=qq,dc=com"adding new entry "ou=Group,o=tengxun,dc=qq,dc=com"adding new entry "ou=People,o=tengxun,dc=qq,dc=com"

通過以上的所有步驟,我們就設(shè)置好了一個(gè) LDAP 目錄樹:其中基準(zhǔn) dn: o=tengxun,dc=qq,dc=com 是該樹的根節(jié)點(diǎn),其下有一個(gè)管理域 cn=Manager,o=tengxun,dc=qq,dc=com 和兩個(gè)組織單元 ou=People,o=tengxun,dc=qq,dc=com 及 ou=Group,o=tengxun,dc=qq,dc=com。

3. 用戶

創(chuàng)建用戶及部門(cn組)

[root@openldap-server data]# vim adduser.ldif # create new # replace to your own domain name for "dc=***,dc=***" section dn: uid=huateng.ma,ou=People,o=tengxun,dc=qq,dc=com objectClass: top objectclass: person #objectclass: organizationalPerson objectclass: inetOrgPerson objectClass: shadowAccount uid: huateng.ma cn: huateng.ma sn: ma displayName: 馬化騰 ou: People description: 可視化 #userPassword: ldappassword userPassword: {SSHA}b6YpCvRFWAWQdJpueuyzk79VXlikj4Z1 mail: huateng.ma@qq.comdn: cn=kaifa,ou=Group,o=tengxun,dc=qq,dc=com objectClass: top objectClass: groupOfUniqueNames cn: kaifa uniquemember: uid=huateng.ma,ou=People,o=tengxun,dc=qq,dc=com

導(dǎo)入用戶數(shù)據(jù)

[root@openldap-server data]# ldapadd -x -D "cn=Manager,dc=qq,dc=com" -w ldappassword -f ./adduser.ldif -h openldap-server -p 389 adding new entry "uid=huateng.ma,ou=People,o=tengxun,dc=qq,dc=com" adding new entry "cn=kaifa,ou=Group,o=tengxun,dc=qq,dc=com"

可以登陸phpLDAPadmin的web界面查詢新導(dǎo)入的數(shù)據(jù)

添加其它用戶

[root@openldap-server data]# vim adduser.ldif # create new # replace to your own domain name for "dc=***,dc=***" section dn: uid=san.zhang,ou=People,o=tengxun,dc=qq,dc=com objectClass: top objectclass: person #objectclass: organizationalPerson objectclass: inetOrgPerson objectClass: shadowAccount uid: san.zhang cn: san.zhang sn: zhang displayName: 張三 ou: People description: 可視化 #userPassword: ldappassword userPassword: {SSHA}b6YpCvRFWAWQdJpueuyzk79VXlikj4Z1 mail: san.zhang@qq.com

把san.zhang用戶加入到kaifa組中(沒驗(yàn)證)

dn: cn=kaifa,ou=Group,o=tengxun,dc=qq,dc=com changetype: modify add: memberuid memberuid: san.zhang
或者

通過OpenLDAP界面把san.zhang用戶添加到kaifa組中

點(diǎn)擊左側(cè)相應(yīng)組織下的"ou=Group" --> "cn=kaifa" --> "uniqueMember" --> 點(diǎn)擊下面的賦值,復(fù)制上面一行,然后修改uid保存即可。

八、參考:

http://book.51cto.com/art/201602/505669.htm
https://www.cnblogs.com/kevingrace/p/9052669.html
https://www.cnblogs.com/AloneSword/p/4758814.html

當(dāng)你發(fā)現(xiàn)自己的才華撐不起野心時(shí),就請安靜下來學(xué)習(xí)吧

轉(zhuǎn)載于:https://blog.51cto.com/moerjinrong/2152891

總結(jié)

以上是生活随笔為你收集整理的CentOS 6.9下OpenLDAP 的安装与配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。