OpenLdap是基于LDAP协议的开源程序,它的程序名称叫做slapd
LDAP(Lightweight Directory Access Protocol)
采用树状结构存储数据(类似于前面学习的DNS服务程序),用于在IP网络层面实现对分布式目录的访问和管理操作,条目是LDAP协议中最基本的元素,可以想象成字典中的单词或者数据库中的记录,通常对LDAP服务程序的添加、删除、更改、搜索都是以条目为基本对象的。
配置LDAP服务端
安装openldap与相关的软件包
yum install -y openldap openldap-clients openldap-servers migrationtools
生成密钥文件
slappasswd -s linuxprobe -n > /etc/openldap/passwd
cat /etc/openldap/passwd
{SSHA}v/GJvGG8SbIuCxhfTDVhkmWEuz2afNIR
写入一条主机与IP地址的解析记录
echo "192.168.10.10 instructor.linuxprobe.com" >> /etc/hosts
因为LDAP目录服务是以明文的方式在网络中传输数据的(包括密码),这样真的很不安全,所以我们采用TLS加密机制来解决这个问题,使用openssl工具生成X509格式的证书文件(有效期为365天):
[cc lang="bash"]
[root@linuxprobe ~]# openssl req -new -x509 -nodes -out /etc/openldap/certs/cert.pem -keyout /etc/openldap/certs/priv.pem -days 365
Generating a 2048 bit RSA private key
..........................................+++
..............................................................+++
writing new private key to '/etc/openldap/certs/priv.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:敲击回车
State or Province Name (full name) []:敲击回车
Locality Name (eg, city) [Default City]:敲击回车
Organization Name (eg, company) [Default Company Ltd]:敲击回车
Organizational Unit Name (eg, section) []:敲击回车
Common Name (eg, your name or your server hostname) []:instructor.linuxprobe.com
Email Address []:敲击回车
[/cc]
修改证书的所属与权限:
cd /etc/openldap/certs/
chown ldap:ldap *
chmod 600 priv.pem
ls -al
复制一份LDAP的配置模板
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
生成数据库文件(不用担心报错信息)
slaptest
修改LDAP数据库的所属主与组
chown ldap:ldap /var/lib/ldap/*
启动slapd服务程序并设置为开机启动
systemctl restart slapd
systemctl enable slapd
ldapadd [参数] LDIF文件 用于将LDIF文件导入到目录服务数据库中
参数 作用
-x 进行简单认证。
-D 用于绑定服务器的dn。
-h: 目录服务的地址。
-w: 绑定dn的密码。
-f: 使用LDIF文件进行条目添加的文件。
添加cosine和nis模块
cd /etc/openldap/schema/
ldapadd -Y EXTERNAL -H ldapi:/// -D "cn=config" -f cosine.ldif
ldapadd -Y EXTERNAL -