CentOS 搭建 LDAP
LDAP(轻量级目录访问协议)是一种基于X.500标准的目录服务协议,它主要用于存储、检索和管理大量的信息,在CentOS系统中搭建LDAP,可以方便地实现用户管理和权限控制,本文将详细介绍在CentOS系统中搭建LDAP的过程。

搭建LDAP的准备工作
确保CentOS系统已经安装,且已配置好网络。
安装所需的软件包:
yum install openldap openldap-servers openldap-clients
配置防火墙,允许LDAP端口(默认为389)的访问。
搭建LDAP服务
配置LDAP主服务器
a. 修改配置文件
vi /etc/openldap/slapd.conf
修改以下配置项:
base dc=example,dc=com suffix "dc=example,dc=com" directory "/var/lib/ldap" rootdn "cn=admin,dc=example,dc=com" rootpw secretb. 初始化LDAP数据库

slapd-configure
c. 启动LDAP服务
systemctl start slapd
d. 设置LDAP服务开机自启
systemctl enable slapd
配置LDAP客户端
a. 修改客户端配置文件
vi /etc/openldap/ldap.conf
修改以下配置项:
base dc=example,dc=com uri ldap://localhostb. 验证客户端连接
ldapsearch -x -LLL -H ldap:/// -b dc=example,dc=com
LDAP用户管理
创建用户
ldapadd -x -D "cn=admin,dc=example,dc=com" -W -f /path/to/user.ldif
查询用户

ldapsearch -x -LLL -H ldap:/// -b dc=example,dc=com -s base "uid=user1"
修改用户信息
ldapmodify -x -D "cn=admin,dc=example,dc=com" -W -f /path/to/user.ldif
删除用户
ldapdelete -x -D "cn=admin,dc=example,dc=com" -W -f /path/to/user.ldif
FAQs
Q1:如何修改LDAP密码? A1:可以使用以下命令修改LDAP密码:
ldapmodify -x -D "cn=admin,dc=example,dc=com" -W -f /path/to/passwd.ldif
在passwd.ldif文件中添加以下内容:
dn: cn=admin,dc=example,dc=com
changetype: modify
replace: userPassword
userPassword: newpassword Q2:如何查看LDAP日志? A2:LDAP日志位于/var/log/openldap目录下,可以查看slapd.log文件:
cat /var/log/openldap/slapd.log

