系統版本:centos7.4html
openldap版本2.4數據庫
安裝:vim
yum install openldap openldap-servers openldap-clients
拷貝數據庫配置文件windows
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG chown ldap:ldap /var/lib/ldap/DB_CONFIG
DB_CONIFG
中主要是關於Berkeley DB的相關的一些配置centos
啓動OpenLDAP Server:api
systemctl start slapd systemctl enable slapd systemctl status slapd
slapd即standard alone ldap daemon,該進程默認監聽389端口app
先用一個命令生成一個LDAP管理用戶root密碼:dom
slappasswd -s 123456 New password: Re-enter new password: {SSHA}eNZrBtwRRsUg03i5cmGATh3ZnDNfm3Od #記住這個,下面會用到
新建一個rootpwd.ldif(名稱是自定義的)的文件:/opt/ldif工具
vi rootpwd.ldif dn: olcDatabase={0}config,cn=config changetype: modify add: olcRootPW olcRootPW: {SSHA}eNZrBtwRRsUg03i5cmGATh3ZnDNfm3Od
下面使用ldapadd命令將上面的rootpwd.ldif文件寫入LDAP:測試
ldapadd -Y EXTERNAL -H ldapi:/// -f rootpwd.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 modifying entry "olcDatabase={0}config,cn=config"
導入schema
導入schema,schema包含爲了支持特殊場景相關的屬性,可根據選擇導入,這裏先所有導入:
ls /etc/openldap/schema/*.ldif | while read f; do ldapadd -Y EXTERNAL -H ldapi:/// -f $f; done
設定默認域
先使用slappasswd生成一個密碼:
slappasswd -s 123456 New password: Re-enter new password: {SSHA}eNZrBtwRRsUg03i5cmGATh3ZnDNfm3Od
新建一個domain.ldif的文件:
vi domain.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=admin,dc=ceshi,dc=com" read by * none
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=ceshi,dc=com
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=admin,dc=ceshi,dc=com
#這個是admin的密碼設置/若是要修改密碼把這段拿出來 add改爲replace,而後執行 ldapadd -Y EXTERNAL -H ldapi:/// -f rootpwd.ldif
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}AtEg7bsctKkWCpeeSdazKcrFCASuU8fP
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
dn="cn=admin,dc=ceshi,dc=com" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=admin,dc=ceshi,dc=com" write by * read
olcAccess
即access,該key用於指定目錄的ACL即誰有什麼權限能夠存取什麼olcRootDN
設定管理員root用戶的distingush name寫入:
ldapmodify -Y EXTERNAL -H ldapi:/// -f domain.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 modifying entry "olcDatabase={1}monitor,cn=config" modifying entry "olcDatabase={2}hdb,cn=config" modifying entry "olcDatabase={2}hdb,cn=config" modifying entry "olcDatabase={2}hdb,cn=config" modifying entry "olcDatabase={2}hdb,cn=config"
添加基本目錄
新建一個basedomain.ldif的文件:
dn: dc=ceshi,dc=com
objectclass: dcObject
objectclass: organization
o: Ceshi.Inc
dc: ceshi
dn: cn=admin,dc=ceshi,dc=com
objectClass: organizationalRole
cn: admin
description: Directory admin
dn: ou=it,dc=ceshi,dc=com
ou: it
objectClass: organizationalUnit
dn: cn=hanxiaohui,ou=it,dc=ceshi,dc=com
ou: it
cn: hanxiaohui
sn: hui
userPassword: 123456
objectClass: inetOrgPerson
objectClass: organizationalPerson
dc=zhidaoauto,dc=com
至關於/com/zhidaoauto
cn=Manager,dc=zhidaoauto,dc=com
表示在/com/zhidaoauto
域下的管理員用戶Managerou=People,dc=zhidaoauto,dc=com
表示在/com/zhidaoauto
域下的一個組織單元People
寫入:
ldapadd -x -D cn=admin,dc=ceshi,dc=com -W -f basedomain.ldif Enter LDAP Password: adding new entry "dc=zhidaoauto,dc=com" adding new entry "cn=Manager,dc=zhidaoauto,dc=com" adding new entry "ou=People,dc=zhidaoauto,dc=com" adding new entry "ou=Group,dc=zhidaoauto,dc=com"
測試:
ldapsearch -LLL -W -x -D "cn=admin,dc=ceshi,dc=com" -H ldap:/// -b "dc=admin,dc=com" Enter LDAP Password: dn: dc=zhidaoauto,dc=com objectClass: top objectClass: dcObject objectClass: organization o: zhidaoauto com dc: zhidaoauto dn: cn=Manager,dc=zhidaoauto,dc=com objectClass: organizationalRole cn: Manager description: Directory Manager dn: ou=People,dc=zhidaoauto,dc=com objectClass: organizationalUnit ou: People dn: ou=Group,dc=zhidaoauto,dc=com objectClass: organizationalUnit ou: Group
能夠在局域網內的windows電腦上下載ldapadmin做爲管理工具 下載地址: http://www.ldapadmin.org/download/ldapadmin.html
登陸帳號爲:
登陸ldap的用戶dn爲:cn=Manager,dc=zhidaoauto,dc=com
ou=Group和ou=People的區別:
從ou=Group裏建立的是組,從ou=People建立的是用戶
ou=People裏的用戶怎麼加入到ou=Group下邊的組呢:
右鍵"yunwei"組-->properties
這樣就把ou=People裏"zhaijunming"用戶添加到ou=Group裏的"yunwei"組了
添加用戶:
1) [root@localhost /opt/ldif 17:55:41&&31]#slappasswd -s 1q2w3e4r {SSHA}dYGee/j6y0qOeHqCTgp3vkIGETMOZYkQ 2) vim changeAdminPwd.ldif (用上面的密碼) ------------------------------------------------------------- dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcRootPW olcRootPW: {SSHA}AtEg7bsctKkWCpeeSdazKcrFCASuU8fP -------------------------------------------------------------- 3) ldapadd -Y EXTERNAL -H ldapi:/// -f changeAdminPwd.ldif
https://blog.frognew.com/2017/05/openldap-install-notes.html#ldapadmin
https://www.cnblogs.com/zhaijunming5/p/9522756.html