1、使用yum方式安装
# yum install -y openldap openldap-clients openldap-servers
2、复制一个默认配置到指定目录下,并授权,这一步一定要做,然后再启动服务,不然生产密码时会报错
# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG # chown -R ldap /var/lib/ldap/DB_CONFIG
3、启动服务,先启动服务,配置后面再进行修改
# systemctl start slapd # systemctl enable slapd # systemctl status slapd
4、修改ldap配置并初始化配置
这里就是重点中的重点了,从openldap2.4.23版本开始,所有配置都保存在/etc/openldap/slapd.d目录下的cn=config文件夹内,不再使用slapd.conf作为配置文件。配置文件的后缀为 ldif,且每个配置文件都是通过命令自动生成的,任意打开一个配置文件,在开头都会有一行注释,说明此为自动生成的文件,请勿编辑,使用ldapmodify命令进行修改
a、生成管理员密码,记录下这个密码,{SSHA}这一串,后面需要用到
# slappasswd -s 123456
b、新增修改密码文件,ldif为后缀,编辑内容如下:
# vi changepwd.ldif
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}ZaGEy/jrSsRXokGaepRNSuZfTMgD+3Pi
执行命令,修改ldap配置,通过-f执行文件
# ldapadd -Y EXTERNAL -H ldapi:/// -f changepwd.ldif
查看olcDatabase={0}config内容,新增了一个olcRootPW项
# cat /etc/openldap/slapd.d/cn=config/olcDatabase={0}config.ldif
c、向LDAP中导入基本的 Schema
# 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
d、新增con.ldif,修改对应配置
# vi con.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=ileiming,dc=com” read by * nonedn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=ileiming,dc=comdn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=admin,dc=ileiming,dc=comdn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}qIIYCPeUeke+AOz8lvWyZplFxQRQIk6Gdn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by dn=”cn=admin,dc=ileiming,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=ileiming,dc=com” write by * read
保存以上配置并执行如下命令
# ldapmodify -Y EXTERNAL -H ldapi:/// -f con.ldif
e、添加memberOf模块
新增add-memberof.ldif, #开启memberof支持并新增用户支持memberof配置
# vi add-memberof.ldif
dn: cn=module{0},cn=config
cn: modulle{0}
objectClass: olcModuleList
objectclass: top
olcModuleload: memberof.la
olcModulePath: /usr/lib64/openldapdn: olcOverlay={0}memberof,olcDatabase={2}hdb,cn=config
objectClass: olcConfig
objectClass: olcMemberOf
objectClass: olcOverlayConfig
objectClass: top
olcOverlay: memberof
olcMemberOfDangling: ignore
olcMemberOfRefInt: TRUE
olcMemberOfGroupOC: groupOfUniqueNames
olcMemberOfMemberAD: uniqueMember
olcMemberOfMemberOfAD: memberOf
新增refint1.ldif文件
# vi refint1.ldif
dn: cn=module{0},cn=config
add: olcmoduleload
olcmoduleload: refint
新增refint2.ldif文件
# vi refint2.ldif
dn: olcOverlay=refint,olcDatabase={2}hdb,cn=config
objectClass: olcConfig
objectClass: olcOverlayConfig
objectClass: olcRefintConfig
objectClass: top
olcOverlay: refint
olcRefintAttribute: memberof uniqueMember manager owner
依次执行下面命令,加载配置,顺序不能错
# ldapadd -Q -Y EXTERNAL -H ldapi:/// -f add-memberof.ldif # ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f refint1.ldif # ldapadd -Q -Y EXTERNAL -H ldapi:/// -f refint2.ldif
f、创建一个组织
新增配置文件
# vi base.ldif
dn: dc=ileiming,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: Ileiming
dc: ileimingdn: cn=admin,dc=ileiming,dc=com
objectClass: organizationalRole
cn: admindn: ou=people,dc=ileiming,dc=com
ou: people
description: 用户根目录
objectClass: organizationalUnit
执行命令,添加配置, 这里要注意修改域名为自己配置的域名,然后需要输入上面我们生成的密码123456
# ldapadd -x -D cn=admin,dc=ileiming,dc=com -W -f base.ldif
h、关闭ldap匿名访问
# vi disable_anno.ldif
dn: cn=config
changetype: modify
add: olcDisallows
olcDisallows: bind_anondn: cn=config
changetype: modify
add: olcRequires
olcRequires: authcdn: olcDatabase={-1}frontend,cn=config
changetype: modify
add: olcRequires
olcRequires: authc
# ldapadd -Y EXTERNAL -H ldapi:/// -f disable_anno.ldif
转载请注明:LINUX服务器运维架构技术分享 » Ldap安装