最近安裝ldap看了不少教程,整理下用到的有用的資料,并把自己的搭建過(guò)程分享。
參考
-
ldap介紹:openLDAP入門(mén)與安裝
-
官方文檔:https://www.openldap.org/doc/admin22/schema.html
-
安裝配置:Centos7 搭建openldap完整詳細(xì)教程(真實(shí)可用)
-
bug解決:ldap運(yùn)維中遇到的問(wèn)題
-
schema自定義:導(dǎo)入schema到openLdap window文件轉(zhuǎn)為unix文件
1,安裝和配置
yum 安裝相關(guān)包
yum install -y openldap openldap-clients openldap-servers
拷貝數(shù)據(jù)庫(kù)配置文件
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown -R ldap. /var/lib/ldap/DB_CONFIG
啟動(dòng)服務(wù),先啟動(dòng)服務(wù),配置后面再進(jìn)行修改
systemctl start slapd
systemctl enable slapd
#查看狀態(tài)
systemctl status slapd
修改配置
從openldap2.4.23版本開(kāi)始,所有配置都保存在/etc/openldap/slapd.d目錄下的cn=config文件夾內(nèi),不再使用slapd.conf作為配置文件。配置文件的后綴為 ldif,ldap的配置在開(kāi)頭都會(huì)有一行注釋?zhuān)f(shuō)明此為自動(dòng)生成的文件,請(qǐng)勿編輯,需要使用ldapmodify命令進(jìn)行修改。
設(shè)置用戶密碼,生成的加密密碼后面需要用到(ldap的加密是同樣的密碼加密后都不一樣)
slappasswd -s 123456
{SSHA}N158sFqO97cIPBV/eOW1b80oV4BIvlvW
開(kāi)始修改,創(chuàng)建一個(gè)修改文件。
vim changepwd.ldif
添加內(nèi)容
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}N158sFqO97cIPBV/eOW1b80oV4BIvlvW
然后執(zhí)行,在執(zhí)行下面的命令前,你可以先查看原本的/etc/openldap/slapd.d/olcDatabase={0}config文件,里面是沒(méi)有olcRootPW這個(gè)項(xiàng)的,執(zhí)行命令后,你再看就會(huì)新增了olcRootPW項(xiàng),而且內(nèi)容是我們文件中指定的值加密后的字符串
ldapadd -Y EXTERNAL -H ldapi:/// -f changepwd.ldif
備注:如果/etc/openldap/slapd.d/下cn=config/olcDatabase={0}config文件已經(jīng)存在olcRootPW 使用replace
changepwd.ldif內(nèi)容:
dn: olcDatabase={0}config,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}N158sFqO97cIPBV/eOW1b80oV4BIvlvW
ldapmodify -Y EXTERNAL -H ldapi:/// -f changepwd.ldif
導(dǎo)入配置
# 我們需要向 LDAP 中導(dǎo)入一些基本的 Schema。這些 Schema 文件位于 /etc/openldap/schema/ 目錄中,schema控制著條目擁有哪些對(duì)象類(lèi)和屬性,可以自行選擇需要的進(jìn)行導(dǎo)入,
# 依次執(zhí)行下面的命令,導(dǎo)入基礎(chǔ)的一些配置,我這里將所有的都導(dǎo)入一下,其中core.ldif是默認(rèn)已經(jīng)加載了的,不用導(dǎo)入
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/collective.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/corba.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/duaconf.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/dyngroup.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/java.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/misc.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/openldap.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/pmi.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/ppolicy.ldif
修改域名
域名的信息保存在/etc/openldap/slapd.d/cn=config文件夾下
olcDatabase={1}monitor,cn=config配置中可以查看,不能直接修改。這邊使用命令修改。
創(chuàng)建一個(gè)changedomain.ldif修改文件。
vim changedomain.ldif
比如我域名是dc=sichuan,dc=cmcc ,用戶為cn=Manager,changedomain.ldif文件配置如下:
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read by dn.base="cn=Manager,dc=sichuan,dc=cmcc" read by * none
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=sichuan,dc=cmcc
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=sichuan,dc=cmcc
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}7j4lLAvS1mToAZpIyefQdTYqCvL0hiVa
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=sichuan,dc=cmcc" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=sichuan,dc=cmcc" write by * read
執(zhí)行:
ldapmodify -Y EXTERNAL -H ldapi:/// -f changedomain.ldif
創(chuàng)建組織單元
在dc=sichuan,dc=cmcc組織下 創(chuàng)建Account 和Role兩個(gè)組織單元:
新增cmcc.ldif文件
vim cmcc.ldif
dn: dc=sichuan,dc=cmcc
objectClass: domain
objectClass: top
o: cmcc
dc: sichuan
dn: ou=Account,dc=sichuan,dc=cmcc
objectClass: organizationalUnit
ou: Account
description: account for cmcc
dn: ou=Role,dc=sichuan,dc=cmcc
objectClass: organizationalUnit
ou: Role
description: role for cmcc
執(zhí)行命令,添加配置, 這里要注意修改域名為自己配置的域名,然后需要輸入上面我們的密碼(123456)
ldapadd -x -D cn=Manager,dc=sichuan,dc=cmcc -W -f cmcc.ldif
2,schema自定義格式
schema,是一個(gè)標(biāo)準(zhǔn),定義了ldap的對(duì)象和屬性,也就是ldap能夠存儲(chǔ)什么數(shù)據(jù),數(shù)據(jù)有什么屬性等。
/etc/openldap/slapd.d/cn=config/cn=schema/文件夾保存了運(yùn)行使用的schema文件,我們需要生成cmcc.schema放進(jìn)來(lái)。
由于ldap中的對(duì)象不滿足現(xiàn)有需求,需要自定義對(duì)象和屬性。
創(chuàng)建兩個(gè)對(duì)象cmcc-Account和cmcc-Role
cmcc-Account對(duì)象包含Uid,accPassword ,accRole , accstatus , accReserve1 , accReserve2 , accReserveList1 , accReserveList2屬性
cmcc-Role對(duì)象包含roleName, roleDesc, accReserve1 , accReserve2 , accReserveList1 , accReserveList2屬性
創(chuàng)建cmcc.schema文件
vim cmcc.schema
attributetype ( 1.3.6.1.4.1.79145.1.2.1.2 NAME 'accPassword'
DESC 'accPassword'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768}
SINGLE-value )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.3 NAME 'accRole'
DESC 'accRole'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.4 NAME 'accstatus'
DESC 'accstatus'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768}
SINGLE-value )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.5 NAME 'accReserve1'
DESC 'accReserve1'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768}
SINGLE-value )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.6 NAME 'accReserve2'
DESC 'accReserve2'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768}
SINGLE-value )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.7 NAME 'accReserveList1'
DESC 'accReserveList1'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.8 NAME 'accReserveList2'
DESC 'accReserveList2'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.9 NAME 'roleName'
DESC 'roleName'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768}
SINGLE-value )
attributetype ( 1.3.6.1.4.1.79145.1.2.1.10 NAME 'roleDesc'
DESC 'roleDesc'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768}
SINGLE-value )
objectclass ( 1.3.6.1.4.1.79145.1.2.2.1 NAME 'cmcc-Account'
DESC 'a cmcc-Account'
SUP top STRUCTURAL
MUST ( uID )
MAY ( accPassword $ accRole $ accstatus $ accReserve1 $ accReserve2 $ accReserveList1 $ accReserveList2 ) )
objectclass ( 1.3.6.1.4.1.79145.1.2.2.2 NAME 'cmcc-Role'
DESC 'a cmcc-Role'
SUP top STRUCTURAL
MUST ( roleName )
MAY ( roleDesc $ accReserve1 $ accReserve2 $ accReserveList1 $ accReserveList2 ) )
將cmcc.schema文件放到/etc/openldap/schema
在tmp文件夾 創(chuàng)建schema文件夾
創(chuàng)建convert.conf文件,在末尾加入cmcc.schema
cd /tmp
mkdir schema
vim convert.conf
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/collective.schema
include /etc/openldap/schema/corba.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/duaconf.schema
include /etc/openldap/schema/dyngroup.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/java.schema
include /etc/openldap/schema/misc.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/openldap.schema
include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/cmcc.schema
生成ldap信息文件
slaptest -f /tmp/convert.conf -F /tmp/schema
給ldap添加生成的cmcc.ldif文件
cp /tmp/schema/cn\=config/cn\=schema/cn\=\{12\}cmcc.ldif /etc/openldap/slapd.d/cn\=config/cn\=schema/
#給ldap 添加權(quán)限
cd /etc/openldap/slapd.d/cn=config/cn=schema/
chown ldap:ldap cn\=\{12}cmcc.ldif
重啟
ps aux | grep ldap
kill -9 pid
//啟動(dòng)
systemctl start slapd
//狀態(tài)
systemctl status slapd
3,連接ldap數(shù)據(jù)庫(kù)效果
我使用的window版LdapAdmin.exe 連接的ldap。
查看自定義schema是否成功,可以點(diǎn)擊Tools->schema 查看object classes 和Attribue Types中是否存在。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-660496.html
登陸界面:
組織結(jié)構(gòu):文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-660496.html
到了這里,關(guān)于Ladp數(shù)據(jù)庫(kù)安裝和配置自定義schema ,Centos7環(huán)境的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!