OpenLDAP online installation and configuration management

Install OpenLDAP

Using the following command to install OpenLDAP:

yum -y install openldap compat-openldap openldap-clients openldap-servers openldap-servers-sql openldap-devel migrationtools

OpenLDAP version

slapd -VV

Here Insert Picture Description

Configuring OpenLDAP administrator password

 slappasswd -s 123456

Here Insert Picture Description

OpenLDAP configuration files

olcDatabase={2}hdb.ldif
vim /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}hdb.ldif 

Add a line in the configuration file:

olcRootPW: {SSHA}cz194nylg0li+7PAiECh6Jt0UNXPv3k2

Where cn = root root for the user name of OpenLDAP administrator, and olcRootPW represent OpenLDAP administrator's password.

olcSuffix: dc=nmcm,dc=com

olcRootDN: cn=root,dc=nmcm,dc=com

Here Insert Picture Description

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

Here Insert Picture Description

Verify OpenLDAP Configuration

The basic configuration of the authentication OpenLDAP

slaptest -u

Here Insert Picture Description

Start OpenLDAP service

systemctl enable slapd

systemctl start slapd

systemctl status slapd

Startup Errors

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.

Permissions issue

chown -R ldap.ldap /etc/openldap/

chown -R ldap.ldap /var/lib/ldap/

Here Insert Picture DescriptionOpenLDAP default listening port is 389

lsof -i:389

Here Insert Picture Description

OpenLDAP Configuration Database

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 database is used by default BerkeleyDB, / var / lib / ldap / BerkeleyDB database is stored in the default path.
Here Insert Picture Description

Importing Basic 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

Here Insert Picture Description

migrate_common.ph file

migrate_common.ph file is mainly used to generate the ldif files

vim /usr/share/migrationtools/migrate_common.ph

$DEFAULT_MAIL_DOMAIN = “nmcm.com”;

$DEFAULT_BASE = “dc=nmcm,dc=com”;

$EXTENDED_SCHEMA = 1;

Here Insert Picture Description

Adding users and user groups

By default, OpenLDAP is no ordinary user, but there is an admin user is root configuration of the front.

Add User Group, using the following command:

groupadd nsccwx

groupadd nmcm

Add users and set a password, use the following command:

useradd -g nsccwx zhaojq

useradd -g nmcm hankm

echo ‘123456’ | passwd –stdin zhaojq

echo ‘123456’ | passwd –stdin hankm

View the configuration attributes:

grep ":10[0-9][0-9]" /etc/passwd > /root/users
cat users

grep ":10[0-9][0-9]" /etc/group > /root/groups
cat groups

According to the generated user and user group attributes, file generation using migrate_passwd.pl ldif to add users and user groups.

/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

Add new users to OpenLDAP, the file can be modified directly users.ldif.

Users and groups to import database OpenLDAP

Openldap-based configuration database:

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
Importing the underlying database
ldapadd -x -w "123456" -D "cn=root,dc=nmcm,dc=com" -f /root/base.ldif
Import users into the database
ldapadd -x -w “123456” -D “cn=root,dc=nmcm,dc=com” -f /root/users.ldif

Runtime Error

ldap_add: No such object (32)
	matched DN: dc=nmcm,dc=com
Import groups into the database
ldapadd -x -w “123456” -D “cn=root,dc=nmcm,dc=com” -f /root/groups.ldif
Published 72 original articles · won praise 66 · Views 150,000 +

Guess you like

Origin blog.csdn.net/miaodichiyou/article/details/101195121
Recommended