Chinaunix首页 | 论坛 | 博客
  • 博客访问: 511791
  • 博文数量: 112
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 662
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-20 07:22
个人简介

一步一个脚印

文章分类

全部博文(112)

文章存档

2019年(2)

2017年(2)

2016年(2)

2015年(6)

2014年(35)

2013年(65)

分类: 系统运维

2019-06-18 16:11:47

原文地址:Centos7 Ldap统一认证部署 作者:xiaodylan

LDAP介绍

        LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP。它是基于X.500标准的,但是简单多了并且可以根据需要定制。与X.500不同,LDAP支持TCP/IP,这对访问Internet是必须的。LDAP的核心规范在RFC中都有定义,所有与LDAP相关的RFC都可以在LDAPman RFC网页中找到。
        这篇部署文档是我参考了N多的国内外文章才整理出来的。

使用目的:

        使用LDAP对运维相关用户名密码做统一管理。可以实现一个帐号登录多个不同系统。

部署:

一、Server端安装

Step 1: Install the following packages:

 # yum install -y openldap openldap-clients openldap-servers migrationtools

二、配置

Step 2: Configure OpenLDAP Server: 

[root@HBC-CtrlCenter ~]# vim /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{2\}hdb.ldif

change two lines:   #change  dc=yooma

olcSuffix: dc=yooma,dc=com               
olcRootDN: cn=root,dc=yooma,dc=com

add one line:
olcRootPW: 123456 #密码根据自己需要修改

:wq!

Step 3: Configure Monitoring Database Configuration file: 

[root@HBC-CtrlCenter ~]# vim /etc/openldap/slapd.d/cn\=config/olcDatabase\=\{1\}monitor.ldif

#修改dn.base=""中的cn、dc项与step2中的相同

olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=extern
al,cn=auth" read by dn.base="cn=root,dc=yooma,dc=com" read by * none

:wq!

Step 4: Prepare the LDAP database:

[root@HBC-CtrlCenter ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

[root@HBC-CtrlCenter ~]# chown -R ldap.ldap /var/lib/ldap

Step 5: Test the configuration:

 

[root@HBC-CtrlCenter ~]# slaptest -u
56e7c83d ldif_read_file: checksum error on "/etc/openldap/slapd.d/cn=config/olcDatabase={1}monitor.ldif"
56e7c83d ldif_read_file: checksum error on "/etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif"
config file testing succeeded  #验证成功

Step 6: Start and enable the slapd service at boot: 

[root@HBC-CtrlCenter ~]# systemctl start slapd

[root@HBC-CtrlCenter ~]# systemctl enable slapd

Step 7: Check the LDAP activity:

 

[root@HBC-CtrlCenter ~]# netstat -lt | grep ldap
tcp 0 0 0.0.0.0:ldap 0.0.0.0:* LISTEN 
tcp6 0 0 [::]:ldap [::]:* LISTEN

[root@HBC-CtrlCenter ~]# netstat -tunlp | egrep "389|636"
tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 18814/slapd 
tcp6 0 0 :::389 :::* LISTEN 18814/slapd

Step 8: To start the configuration of the LDAP server, add the follwing LDAP schemas:

[root@HBC-CtrlCenter ~]# cd /etc/openldap/schema/

# ldapadd -Y EXTERNAL -H  -D "cn=config" -f cosine.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f nis.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f collective.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f corba.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f core.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f duaconf.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f dyngroup.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f inetorgperson.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f java.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f misc.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f openldap.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f pmi.ldif
# ldapadd -Y EXTERNAL -H  -D "cn=config" -f ppolicy.ldif

##################################################
 # NOTE-: You can add schema files according to your need: #
 ##################################################

Step 9: Now use Migration Tools to create LDAP DIT: 

[root@HBC-CtrlCenter ~]# cd /usr/share/migrationtools/

[root@HBC-CtrlCenter migrationtools]# vim migrate_common.ph 

on the Line Number 61, change "ou=Groups"
$NAMINGCONTEXT{'group'} = "ou=Groups";
on the Line Number 71, change your domain name
$DEFAULT_MAIL_DOMAIN = "yooma.com";
on the line number 74, change your base name
$DEFAULT_BASE = "dc=yooma,dc=com";
on the line number 90, change schema value
$EXTENDED_SCHEMA = 1;

:wq!

Step 10: Generate a base.ldif file for your Domain DIT: 

[root@HBC-CtrlCenter migrationtools]# ./migrate_base.pl /root/base.ldif

Step 11: Load "base.ldif" into LDAP Database: 

[root@HBC-CtrlCenter migrationtools]# ldapadd -x -W -D "cn=root,dc=yooma,dc=com" -f /root/base.ldif

Step 12: Now Create some users and Groups and migrate it from local database to LDAP database: 

 #mkdir /home/guests
 #useradd -d /home/guests/ldapuser1 ldapuser1
 #useradd -d /home/guests/ldapuser2 ldapuser2

 #echo 'password' | passwd --stdin ldapuser1
 #echo 'password' | passwd --stdin ldapuser2

Step 13: Now filter out these Users and Groups and it password from /etc/shadow to different file: 

#getent passwd | tail -n 5 > /root/users

#getent shadow | tail -n 5 > /root/shadow

# getent group | tail -n 5 > /root/groups

Step 14: Now you need to create ldif file for these users using migrationtools: 

[root@HBC-CtrlCenter ~]# cd /usr/share/migrationtools

[root@HBC-CtrlCenter migrationtools]# vim migrate_passwd.pl

#search /etc/shadow and replace it into /root/shadow on Line Number 188.

:wq!

[root@HBC-CtrlCenter migrationtools]# ./migrate_passwd.pl /root/users > users.ldif

[root@HBC-CtrlCenter migrationtools]# ./migrate_group.pl /root/groups > groups.ldif

Step 15: Upload these users and groups ldif file into LDAP Database: 

[root@HBC-CtrlCenter migrationtools]# ldapadd -x -W -D "cn=root,dc=yooma,dc=com" -f users.ldif

 [root@HBC-CtrlCenter migrationtools]# ldapadd -x -W -D "cn=root,dc=yooma,dc=com" -f groups.ldif

Step 16: Now search LDAP DIT for all records: 

[root@HBC-CtrlCenter migrationtools]# ldapsearch -x -b "dc=yooma,dc=com" -H 

三、客户端安装配置调试

[root@HBC-C1-WB-5 ~]# yum install -y nss-pam*

[root@HBC-C1-WB-5 ~]# authconfig-tui   #chose the secend [ Use LDAP] and next

click OK.

[root@HBC-C1-WB-5 ~]# su ldapuser1

bash-4.2$     #测试成功

 

阅读(1278) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~