LDAP基础安装配置

2024-06-13 01:32
文章标签 基础 配置 安装 ldap

本文主要是介绍LDAP基础安装配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • LDAP 安装配置
    • 环境
      • 配置 LDAP server 与 client 互通
    • LDAP 安装
      • 安装基础包
    • 配置 LDAP
      • 准备
      • 配置
    • 启动 LDAP 日志记录
    • 客户端配置
      • LDAP客户端配置以使用LDAP服务器
    • 验证 LDAP 登录

LDAP 安装配置

使用 EPEL 最新版本 LDAP 进行安装配置

环境

Host NameIp AddressosRole
ldap-server172.16.10.220CentOS Linux release 7.5.1804LDAP Server
ldap-client172.16.10.10CentOS Linux release 7.5.1804LDAP Client

配置 LDAP server 与 client 互通

# cat /etc/hosts
172.16.10.220 ldap-server
172.16.10.10 ldap-client

LDAP 安装

安装基础包

  1. 配置 epel 源

    # yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    # yum clean all && yum makecache
    
  2. 安装基础包

    # yum -y install openldap compat-openldap openldap-servers openldap-clients openldap-servers-sql openldap-devel
  3. 启动 LDAP 服务并开机启动

    # systemctl start slapd && systemctl enable slapd && systemctl status slapd
    
  4. 验证 LDAP 启动信息

    # netstat -ntupl | grep LISTEN | grep -i 389
    

    输出:

    tcp        0      0 0.0.0.0:389             0.0.0.0:*               LISTEN      1355/slapd
    tcp6       0      0 :::389                  :::*                    LISTEN      1355/slappasswd
    

配置 LDAP

准备

配置 LDAP 管理原密码

# slappasswd -h {SSHA} -s FCzxpJWCccuB
{SSHA}44gsVwtbroqGajIMm/rA3QFEQRHRZIRW

配置

OpenLDAP服务器配置文件位于 /etc/openldap/slapd.d/ 。要开始配置LDAP,我们需要更新变量 “olcSuffix” 和 “olcRootDN“

  • olcSuffix - 数据库后缀,它是LDAP服务器提供信息的域名。简单来说,更改为自己的域名。

  • olcRootDN - 具有对LDAP执行所有管理活动的无限制访问权限的用户的根专有名称(DN)条目,如root用户。

  • olcRootPW - 上述RootDN的LDAP管理员密码。

以上条目需要在/etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif文件中更新。建议不要手动编辑LDAP配置,因为每次运行ldapmodify命令时都会丢失更改。

使用单独配置进行配置和导入到 LDAP

  1. DB

    配置 DB

    # cat db.ldif
    dn: olcDatabase={2}hdb,cn=config
    changetype: modify
    replace: olcSuffix
    olcSuffix: dc=laoshiren,dc=com # 此处 `dc`更改为自己的域名dn: olcDatabase={2}hdb,cn=config
    changetype: modify
    replace: olcRootDN
    olcRootDN: cn=manager,dc=laoshiren,dc=com # 此处`cn`:为管理用户、`dc`都更改为自己的配置dn: olcDatabase={2}hdb,cn=config
    changetype: modify
    replace: olcRootPW
    olcRootPW: {SSHA}44gsVwtbroqGajIMm/rA3QFEQRHRZIRW

    推送 DB 到 LDAP

    # ldapmodify -Y EXTERNAL  -H ldapi:/// -f db.ldif
    SASL/EXTERNAL authentication started
    SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
    SASL SSF: 0
    modifying entry "olcDatabase={2}hdb,cn=config"modifying entry "olcDatabase={2}hdb,cn=config"modifying entry "olcDatabase={2}hdb,cn=config"
    

    设置数据库文件

    # 将示例数据库配置文件复制到/var/lib/ldap并更新文件权限。
    # cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
    # chown ldap:ldap /var/lib/ldap/*

    添加cosine和nis LDAP模式

    ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
    SASL/EXTERNAL authentication started
    SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
    SASL SSF: 0
    adding new entry "cn=cosine,cn=schema,cn=config"ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
    SASL/EXTERNAL authentication started
    SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
    SASL SSF: 0
    adding new entry "cn=nis,cn=schema,cn=config"ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
    SASL/EXTERNAL authentication started
    SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
    SASL SSF: 0
    adding new entry "cn=inetorgperson,cn=schema,cn=config"
  2. 监控

    对/etc/openldap/slapd.d/cn=config/olcDatabase={1 }monitor.ldif (不要手动编辑)文件进行更改,以仅将监视器访问限制为ldap root(ldapadm)用户而不是其他用户。

    配置 monitor

    # cat monitor.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=manager,dc=laoshiren,dc=com" read by * none
    

    推送 monitor 到 LDAP

    # ldapmodify -Y EXTERNAL  -H ldapi:/// -f monitor.ldif
    SASL/EXTERNAL authentication started
    SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
    SASL SSF: 0
    modifying entry "olcDatabase={1}monitor,cn=config"
    
  3. 生成 bash 文件(为设置的域)

    # cat base.ldif
    dn: dc=laoshiren,dc=com
    dc: laoshiren
    objectClass: top
    objectClass: domaindn: cn=manager ,dc=laoshiren,dc=com
    objectClass: organizationalRole
    cn: manager
    description: LDAP Managerdn: ou=People,dc=laoshiren,dc=com
    objectClass: organizationalUnit
    ou: Peopledn: ou=Group,dc=laoshiren,dc=com
    objectClass: organizationalUnit
    ou: Group

    构建目录结构

    # ldapadd -x -W -D "cn=manager,dc=laoshiren,dc=com" -f base.ldif
    Enter LDAP Password: # 配置 LDAP 管理原密码
    adding new entry "dc=laoshiren,dc=com"adding new entry "cn=manager ,dc=laoshiren,dc=com"adding new entry "ou=People,dc=laoshiren,dc=com"adding new entry "ou=Group,dc=laoshiren,dc=com"
    
  4. 使用命令创建用户

    创建用户的配置文件

    # cat laoshiren.ldif
    dn: uid=laoshiren,ou=People,dc=laoshiren,dc=com
    objectClass: top
    objectClass: account
    objectClass: posixAccount
    objectClass: shadowAccount
    cn: laoshiren
    uid: laoshiren
    uidNumber: 9999
    gidNumber: 100
    homeDirectory: /home/laoshiren
    loginShell: /bin/bash
    gecos: Laoshiren [Admin (at) laoshiren]
    userPassword: {crypt}x
    shadowLastChange: 17058
    shadowMin: 0
    shadowMax: 99999
    shadowWarning: 7

    使用ldapadd在 OpenLDAP 中春构建名为laoshiren的新用户

    # ldapadd -x -W -D "cn=manager,dc=laoshiren,dc=com" -f laoshiren.ldif
    Enter LDAP Password:#管理员密码
    adding new entry "uid=laoshiren,ou=People,dc=laoshiren,dc=com"
    

    为用户分配密码

    # ldappasswd -s 123456 -W -D "cn=manager,dc=laoshiren,dc=com" -x "uid=laoshiren,ou=People,dc=laoshiren,dc=com"

    参数

    -s: 指定用户名的密码
    -x: 用户名,密码已更改
    -D: 要对LDAP服务器进行身份验证的可分辨名称
    

    验证 LDAP 条目

    # ldapsearch -x cn=laoshiren -b dc=laoshiren,dc=com
    # extended LDIF
    #
    # LDAPv3
    # base <dc=laoshiren,dc=com> with scope subtree
    # filter: cn=laoshiren
    # requesting: ALL
    ## laoshiren, People, laoshiren.com
    dn: uid=laoshiren,ou=People,dc=laoshiren,dc=com
    objectClass: top
    objectClass: account
    objectClass: posixAccount
    objectClass: shadowAccount
    cn: laoshiren
    uid: laoshiren
    uidNumber: 9999
    gidNumber: 100
    homeDirectory: /home/laoshiren
    loginShell: /bin/bash
    gecos: Laoshiren [Admin (at) laoshiren]
    shadowLastChange: 17058
    shadowMin: 0
    shadowMax: 99999
    shadowWarning: 7
    userPassword:: e1NTSEF9NG8yNDV1SGZuSEwxaEh0K1FPVlhnY1lYVDRJcGN0MTU=# search result
    search: 2
    result: 0 Success# numResponses: 2
    # numEntries: 1
    

启动 LDAP 日志记录

配置Rsyslog以将LDAP事件记录到日志文件/var/log/ldap.log

# vim /etc/rsyslog.conf
# 文件末尾增加
local4.* /var/log/ldap.log
# 重启 rsyslog 服务
systemctl restart rsyslog

客户端配置

LDAP客户端配置以使用LDAP服务器

  1. 准备

    # yum install -y openldap-clients nss-pam-ldapd
    
  2. 添加客户端到 LDAP 服务器端进行单点登录

    authconfig --enableldap --enableldapauth --ldapserver=172.16.10.220 --ldapbasedn="dc=laoshiren,dc=com" --enablemkhomedir --update
  3. 重启 LDAP 客户端服务

    systemctl restart nslcd && systemctl status nslcd
    

验证 LDAP 登录

  • 使用getent命令从LDAP服务器获取LDAP条目(用户信息)

    # getent passwd laoshiren
    
  • 输出:

    laoshiren:x:9999:100:Laoshiren [Admin (at) laoshiren]:/home/laoshiren:/bin/bash
    
  • 验证登录

这篇关于LDAP基础安装配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1055910

相关文章

VSCode配置Anaconda Python环境的实现

《VSCode配置AnacondaPython环境的实现》VisualStudioCode中可以使用Anaconda环境进行Python开发,本文主要介绍了VSCode配置AnacondaPytho... 目录前言一、安装 Visual Studio Code 和 Anaconda二、创建或激活 conda

Pycharm安装报错:Cannot detect a launch configuration解决办法

《Pycharm安装报错:Cannotdetectalaunchconfiguration解决办法》本文主要介绍了Pycharm安装报错:Cannotdetectalaunchconfigur... 本文主要介绍了Pycharm安装报错:Cannot detect a launch configuratio

pytorch+torchvision+python版本对应及环境安装

《pytorch+torchvision+python版本对应及环境安装》本文主要介绍了pytorch+torchvision+python版本对应及环境安装,安装过程中需要注意Numpy版本的降级,... 目录一、版本对应二、安装命令(pip)1. 版本2. 安装全过程3. 命令相关解释参考文章一、版本对

Windows系统下如何查找JDK的安装路径

《Windows系统下如何查找JDK的安装路径》:本文主要介绍Windows系统下如何查找JDK的安装路径,文中介绍了三种方法,分别是通过命令行检查、使用verbose选项查找jre目录、以及查看... 目录一、确认是否安装了JDK二、查找路径三、另外一种方式如果很久之前安装了JDK,或者在别人的电脑上,想

大数据spark3.5安装部署之local模式详解

《大数据spark3.5安装部署之local模式详解》本文介绍了如何在本地模式下安装和配置Spark,并展示了如何使用SparkShell进行基本的数据处理操作,同时,还介绍了如何通过Spark-su... 目录下载上传解压配置jdk解压配置环境变量启动查看交互操作命令行提交应用spark,一个数据处理框架

IDEA连接达梦数据库的详细配置指南

《IDEA连接达梦数据库的详细配置指南》达梦数据库(DMDatabase)作为国产关系型数据库的代表,广泛应用于企业级系统开发,本文将详细介绍如何在IntelliJIDEA中配置并连接达梦数据库,助力... 目录准备工作1. 下载达梦JDBC驱动配置步骤1. 将驱动添加到IDEA2. 创建数据库连接连接参数

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

2025最新版Python3.13.1安装使用指南(超详细)

《2025最新版Python3.13.1安装使用指南(超详细)》Python编程语言自诞生以来,已经成为全球最受欢迎的编程语言之一,它简单易学易用,以标准库和功能强大且广泛外挂的扩展库,为用户提供包罗... 目录2025最新版python 3.13.1安装使用指南1. 2025年Python语言最新排名2.

MyBatis的配置对象Configuration作用及说明

《MyBatis的配置对象Configuration作用及说明》MyBatis的Configuration对象是MyBatis的核心配置对象,它包含了MyBatis运行时所需的几乎所有配置信息,这个对... 目录MyBATis配置对象Configuration作用Configuration 对象的主要作用C

Python依赖库的几种离线安装方法总结

《Python依赖库的几种离线安装方法总结》:本文主要介绍如何在Python中使用pip工具进行依赖库的安装和管理,包括如何导出和导入依赖包列表、如何下载和安装单个或多个库包及其依赖,以及如何指定... 目录前言一、如何copy一个python环境二、如何下载一个包及其依赖并安装三、如何导出requirem