安裝OpenLDAP
使用如下命令安裝OpenLDAP:
yum -y install openldap compat-openldap openldap-clients openldap-servers openldap-servers-sql openldap-devel migrationtools
OpenLDAP版本
slapd -VV
配置OpenLDAP管理員密碼
slappasswd -s 123456
OpenLDAP配置文件
olcDatabase={2}hdb.ldif
vim /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}hdb.ldif
在配置文件中增加一行:
olcRootPW: {SSHA}cz194nylg0li+7PAiECh6Jt0UNXPv3k2
其中cn=root中的root表示OpenLDAP管理員的用戶名,而olcRootPW表示OpenLDAP管理員的密碼。
olcSuffix: dc=nmcm,dc=com
olcRootDN: cn=root,dc=nmcm,dc=com
olcDatabase={2}hdb.ldif
vim /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{1\}monitor.ldif
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=extern
al,cn=auth" read by dn.base="cn=root,dc=nmcm,dc=com" read by * none
驗證OpenLDAP配置
驗證OpenLDAP的基本配置
slaptest -u
啓動OpenLDAP服務
systemctl enable slapd
systemctl start slapd
systemctl status slapd
啓動錯誤
Read/write permissions for DB file '/var/lib/ldap/id2entry.bdb' are required.
Read/write permissions for DB file '/var/lib/ldap/dn2id.bdb' are required.
權限問題
chown -R ldap.ldap /etc/openldap/
chown -R ldap.ldap /var/lib/ldap/
OpenLDAP默認監聽的端口是389
lsof -i:389
配置OpenLDAP數據庫
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap -R /var/lib/ldap
chmod 700 -R /var/lib/ldap
ll /var/lib/ldap/
OpenLDAP默認使用的數據庫是BerkeleyDB,/var/lib/ldap/就是BerkeleyDB數據庫默認存儲的路徑。
導入基本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
migrate_common.ph文件
migrate_common.ph文件主要用於生成ldif文件使用
vim /usr/share/migrationtools/migrate_common.ph
$DEFAULT_MAIL_DOMAIN = “nmcm.com”;
$DEFAULT_BASE = “dc=nmcm,dc=com”;
$EXTENDED_SCHEMA = 1;
添加用戶及用戶組
默認情況下OpenLDAP是沒有普通用戶的,但是有一個管理員用戶,就是前面配置的root。
添加用戶組,使用如下命令:
groupadd nsccwx
groupadd nmcm
添加用戶並設置密碼,使用如下命令:
useradd -g nsccwx zhaojq
useradd -g nmcm hankm
echo ‘123456’ | passwd –stdin zhaojq
echo ‘123456’ | passwd –stdin hankm
查看配置的相關屬性:
grep ":10[0-9][0-9]" /etc/passwd > /root/users
cat users
grep ":10[0-9][0-9]" /etc/group > /root/groups
cat groups
根據上述生成的用戶和用戶組屬性,使用migrate_passwd.pl文件生成要添加用戶和用戶組的ldif。
/usr/share/migrationtools/migrate_passwd.pl /root/users > /root/users.ldif
cat users.ldif
/usr/share/migrationtools/migrate_group.pl /root/groups > /root/groups.ldif
cat groups.ldif
新加用戶到OpenLDAP中,直接修改users.ldif文件即可。
導入用戶及用戶組到OpenLDAP數據庫
配置openldap基礎的數據庫:
vim /root/base.ldif
dn: dc=nmcm,dc=com
o: nmcm com
dc: nmcm
objectClass: top
objectClass: dcObject
objectclass: organization
dn: cn=root,dc=nmcm,dc=com
cn: root
objectClass: organizationalRole
description: Directory Manager
dn: ou=People,dc=nmcm,dc=com
ou: People
objectClass: top
objectClass: organizationalUnit
dn: ou=Group,dc=nmcm,dc=com
ou: Group
objectClass: top
objectClass: organizationalUnit
導入基礎數據庫
ldapadd -x -w "123456" -D "cn=root,dc=nmcm,dc=com" -f /root/base.ldif
導入用戶到數據庫
ldapadd -x -w “123456” -D “cn=root,dc=nmcm,dc=com” -f /root/users.ldif
運行錯誤
ldap_add: No such object (32)
matched DN: dc=nmcm,dc=com
導入用戶組到數據庫
ldapadd -x -w “123456” -D “cn=root,dc=nmcm,dc=com” -f /root/groups.ldif