系統版本:centos7.4html
openldap版本2.4數據庫
安裝並啓動服務windows
安裝:centos
yum install openldap openldap-servers openldap-clients
拷貝數據庫配置文件api
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的相關的一些配置app
啓動OpenLDAP Server:dom
systemctl start slapd
systemctl enable slapd
systemctl status slapd
slapd即standard alone ldap daemon,該進程默認監聽389端口工具
設置root用戶密碼測試
先用一個命令生成一個LDAP管理用戶root密碼:ui
slappasswd New password: Re-enter new password: {SSHA}krOGXDmiCdSXuXocOf10F96LJO5ijdXo #記住這個,下面會用到
新建一個rootpwd.ldif(名稱是自定義的)的文件:
vi rootpwd.ldif dn: olcDatabase={0}config,cn=config changetype: modify add: olcRootPW olcRootPW: {SSHA}krOGXDmiCdSXuXocOf10F96LJO5ijdXo
下面使用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 New password: Re-enter new password: {SSHA}OpMcf0c+pEqFLZm3i+YiI2qhId1G/yM3
新建一個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=Manager,dc=zhidaoauto,dc=com" read by * none dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcSuffix olcSuffix: dc=zhidaoauto,dc=com dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcRootDN olcRootDN: cn=Manager,dc=zhidaoauto,dc=com dn: olcDatabase={2}hdb,cn=config changetype: modify add: olcRootPW olcRootPW: {SSHA}OpMcf0c+pEqFLZm3i+YiI2qhId1G/yM3 #替換上面生成的密碼 dn: olcDatabase={2}hdb,cn=config changetype: modify add: olcAccess olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=zhidaoauto,dc=com" write by anonymous auth by self write by * none olcAccess: {1}to dn.base="" by * read olcAccess: {2}to * by dn="cn=Manager,dc=zhidaoauto,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=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
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=Manager,dc=zhidaoauto,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=Manager,dc=zhidaoauto,dc=com" -H ldap://localhost -b "dc=zhidaoauto,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做爲管理工具
登陸帳號爲:
登陸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"組了
https://blog.frognew.com/2017/05/openldap-install-notes.html#ldapadmin