本文主要是介绍LDAP基础安装配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- LDAP 安装配置
- 环境
- 配置 LDAP server 与 client 互通
- LDAP 安装
- 安装基础包
- 配置 LDAP
- 准备
- 配置
- 启动 LDAP 日志记录
- 客户端配置
- LDAP客户端配置以使用LDAP服务器
- 验证 LDAP 登录
LDAP 安装配置
使用 EPEL 最新版本 LDAP 进行安装配置
环境
Host Name | Ip Address | os | Role |
---|---|---|---|
ldap-server | 172.16.10.220 | CentOS Linux release 7.5.1804 | LDAP Server |
ldap-client | 172.16.10.10 | CentOS Linux release 7.5.1804 | LDAP Client |
配置 LDAP server 与 client 互通
# cat /etc/hosts
172.16.10.220 ldap-server
172.16.10.10 ldap-client
LDAP 安装
安装基础包
-
配置 epel 源
# yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # yum clean all && yum makecache
-
安装基础包
# yum -y install openldap compat-openldap openldap-servers openldap-clients openldap-servers-sql openldap-devel
-
启动 LDAP 服务并开机启动
# systemctl start slapd && systemctl enable slapd && systemctl status slapd
-
验证 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
-
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"
-
监控
对/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"
-
生成 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"
-
使用命令创建用户
创建用户的配置文件
# 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服务器
-
准备
# yum install -y openldap-clients nss-pam-ldapd
-
添加客户端到 LDAP 服务器端进行单点登录
authconfig --enableldap --enableldapauth --ldapserver=172.16.10.220 --ldapbasedn="dc=laoshiren,dc=com" --enablemkhomedir --update
-
重启 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基础安装配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!