天天看點

單台機器簡單安裝配置openldap伺服器單台機器簡單安裝配置openldap伺服器

單台機器簡單安裝配置openldap伺服器

LDAP是輕量目錄通路協定,英文全稱是Lightweight Directory Access Protocol,一般都簡稱為LDAP。

現在市場上有關LDAP的産品已有很多,各大軟體公司都在他們的産品中內建了LDAP服務,如Microsoft的ActiveDirectory、Lotus的Domino Directory、IBM的WebSphere中也內建了LDAP服務。LDAP的開源實作是OpenLDAP,它比商業産品一點也不差,而且源碼開放。

OpenLDAP 是最常用的目錄服務之一,它是一個由開源社群及志願者開發和管理的一個開源項目,提供了目錄服務的所有功能,包括目錄搜尋、身份認證、安全通道、過濾器等等。大多數的 Linux 發行版裡面都帶有 OpenLDAP 的安裝包。

安裝openldap服務

yum install -y openldap openldap-*
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
systemctl restart slapd
systemctl enable slapd
           

配置ldap服務

#生成管理者密碼

[[email protected] ~]# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[[email protected] ~]# vim chrootpw.ldif
#specify the password generated above for "olcRootPW" section
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[[email protected] ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.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"
           

導入基本模式

[[email protected] ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=cosine,cn=schema,cn=config"
[[email protected] ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=nis,cn=schema,cn=config"
[[email protected] ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=inetorgperson,cn=schema,cn=config"
           

在ldap的DB中設定域名

#生成管理者密碼

[[email protected] ~]# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[[email protected] ~]# vim chdomain.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=jumpserver,dc=tk" read by * none

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=jumpserver,dc=tk

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=jumpserver,dc=tk

dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx

dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=jumpserver,dc=tk" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=jumpserver,dc=tk" write by * read
[[email protected] ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.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"

[[email protected] ~]# vim basedomain.ldif 
#replace to your own domain name for "dc=***,dc=***" section
dn: dc=jumpserver,dc=tk
objectClass: top
objectClass: dcObject
objectclass: organization
o: Server tk
dc: jumpserver

dn: cn=Manager,dc=jumpserver,dc=tk
objectClass: organizationalRole
cn: Manager
description: Directory Manager

dn: ou=People,dc=jumpserver,dc=tk
objectClass: organizationalUnit
ou: People

dn: ou=Group,dc=jumpserver,dc=tk
objectClass: organizationalUnit
ou: Group

[[email protected] ~]# ldapadd -x -D cn=Manager,dc=jumpserver,dc=tk -W -f basedomain.ldif
Enter LDAP Password: # 輸入目錄管理者密碼
adding new entry "dc=jumpserver,dc=tk"
adding new entry "cn=Manager,dc=jumpserver,dc=tk"
adding new entry "ou=People,dc=jumpserver,dc=tk"
adding new entry "ou=Group,dc=jumpserver,dc=tk"
           

繼續閱讀