OpenLDAP 安装教程
在centos7上安装OpenLDAP
环境准备
两台虚拟机
node01 IP:192.168.1.143 server端
node02 IP:192.168.1.146 client端
均关闭iptables和selinux和firewall
Service端
步骤:
- 安装包
- 拷贝DB_CONFIG文件
- 设置目录权限
- 创建LDAP管理员密码
- 修改配置文件(三个)
- 启动并设置开机启动slapd服务
- 导入基本Schema
- 导入base.ldif文件
- 配置migrationtools
- 导入系统用户和组
- 重启服务
安装包
yum install openldap-servers openldap-clients migrationtools
拷贝 DB_CONFIG 文件
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
设置目录权限
chown -R ldap. /var/lib/ldap/
创建 LDAP 管理员密码
slappasswd
输入两次后,保存密文
New password:
Re-enter new password:
{SSHA}AFU2R+sLzJgjUIoW1B5SxcTUdFcuncLz
修改配置文件(三个)
vim /etc/openldap/slapd.d/cn=config/olcDatabase={0}config.ldif
# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 d30fb98e
dn: olcDatabase={0}config
objectClass: olcDatabaseConfig
olcDatabase: {0}config
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=extern
al,cn=auth" manage by * none
structuralObjectClass: olcDatabaseConfig
entryUUID: 73e7786c-50fa-1038-9bfb-9bfcf0927062
creatorsName: cn=config
createTimestamp: 20180920082518Z
entryCSN: 20180920082518.739228Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20180920082518Z
olcRootPW: {SSHA}37kYCk8iLCmIrGnRvLc7XLAuPqftFUF/ # 添加该行(密码)
vim /etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif
# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 d41d7411
dn: olcDatabase={2}hdb
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb
olcDbDirectory: /var/lib/ldap
olcSuffix: dc=sitoi,dc=cn # 更改dc
olcRootDN: cn=Manager,dc=sitoi,dc=cn # 更改dc
olcRootPW: {SSHA}37kYCk8iLCmIrGnRvLc7XLAuPqftFUF/ # 添加该行(密码)
olcDbIndex: objectClass eq,pres
olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
structuralObjectClass: olcHdbConfig
entryUUID: 73e77fe2-50fa-1038-9bfd-9bfcf0927062
creatorsName: cn=config
createTimestamp: 20180920082518Z
entryCSN: 20180920082518.739419Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20180920082518Z
olcAccess: {0}to attrs=userPassword by self write by dn.base="cn=Manager,dc=sitoi,dc=cn" write by anonymous auth by * none # 添加该行
olcAccess: {1}to * by dn.base="cn=Manager,dc=sitoi,dc=cn" write by self write by * read # 添加该行
vim /etc/openldap/slapd.d/cn=config/olcDatabase={1}monitor.ldif
# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 261d1986
dn: olcDatabase={1}monitor
objectClass: olcDatabaseConfig
olcDatabase: {1}monitor
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=extern
al,cn=auth" read by dn.base="cn=Manager,dc=sitoi,dc=cn" read by * none # 修改dc信息
structuralObjectClass: olcDatabaseConfig
entryUUID: 73e77bbe-50fa-1038-9bfc-9bfcf0927062
creatorsName: cn=config
createTimestamp: 20180920082518Z
entryCSN: 20180920082518.739313Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20180920082518Z
启动并设置开机启动 slapd 服务
systemctl enable slapd.service
systemctl start slapd.service
导入基本 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
导入 base.ldif 文件
vim base.ldif
dn: dc=sitoi,dc=cn
objectClass: dcObject
objectClass: organization
dc: sitoi
o : sitoi
dn: ou=People,dc=sitoi,dc=cn
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=sitoi,dc=cn
objectClass: organizationalUnit
ou: Group
执行导入
ldapadd -x -D cn=Manager,dc=sitoi,dc=cn -w sitoi -f base.ldif
配置 migrationtools
vim /usr/share/migrationtools/migrate_common.ph
更改以下配置
# Default DNS domain
$DEFAULT_MAIL_DOMAIN = "sitoi.cn";
# Default base
$DEFAULT_BASE = "dc=sitoi,dc=cn";
导入系统用户和组
利用 pl 脚本将 /etc/passwd 和 /etc/shadow 生成 LDAP 能读懂的文件格式,保存在 /tmp/ 下
/usr/share/migrationtools/migrate_base.pl > /tmp/base.ldif
/usr/share/migrationtools/migrate_passwd.pl /etc/passwd > /tmp/passwd.ldif
/usr/share/migrationtools/migrate_group.pl /etc/group > /tmp/group.ldif
导入 LDAP
需要输入管理员密码
ldapadd -x -D "cn=Manager,dc=sitoi,dc=cn" -w sitoi -f /tmp/base.ldif
ldapadd -x -D "cn=Manager,dc=sitoi,dc=cn" -w sitoi -f /tmp/group.ldif
ldapadd -x -D "cn=Manager,dc=sitoi,dc=cn" -w sitoi -f /tmp/passwd.ldif
重启服务
systemctl restart slapd