温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。
Fayson的github:https://github.com/fayson/cdhproject
提示:代码块部分可以左右滑动查看噢
1.文档编写目的
众所周知Hadoop安全模块不存储用户和用户组信息,而是依赖Linux系统的用户和用户组。同时在集群开启安全认证模式之后,需要映射Kerberos Principle到Linux的用户以及映射用户到用户组。那么随之而来的问题是如何统一管理用户信息。这里统一管理用户信息的方式有多种(如OpenLDAP、AD等等),在前面Fayson介绍了如何在Redhat6中安装OpenLDAP,本篇文章主要讲述如何在ReadHat7中安装OpenLDAP并配置客户端。
- 内容概述
1.OpenLDAP服务安装
2.导入根域及管理员账号
3.导入基础文件及用户和用户组
4.配置OpenLDAP客户端
- 测试环境
1.Redhat7.3
2.OpenLDAP版本2.4.44
2.OpenLDAP安装及配置
在集群中选择一台服务器(ip-172-31-24-169.ap-southeast-1.compute.internal)作为OpenLDAP的Server
1.执行如下命令安装OpenLDAP服务
1[root@ip-172-31-24-169 ~]# yum -y install openldap openldap-clients openldap-servers migrationtools openldap-devel nss- pam-ldapd bind-dyndb-ldap compat-openldap perl-LDAP krb5-server-ldap php-ldap openssl
(可左右滑动)
查看安装的RPM包
1[root@ip-172-31-24-169 ~]# rpm -qa |grep openldap
(可左右滑动)
2.使用openssl生成TLS加密文件(如果不需要配置OpenLDAP的TLS则跳过此步)
使用如下命令生成服务器的RSA私钥
1[root@ip-172-31-24-169 certs]# openssl genrsa -out ldap.key 1024
(可左右滑动)
使用如下命令生成签名文件
1[root@ip-172-31-24-169 certs]# openssl req -new -key ldap.key -out ldap.csr
(可左右滑动)
注意:生成签名文件时必填的信息为“your server’s hostname”且为当前服务器的hostname。
使用如下文件生成公钥文件
1[root@ip-172-31-24-169 certs]# openssl x509 -req -days 3653 -in ldap.csr -signkey ldap.key -out ldap.crt
(可左右滑动)
将生成的公钥文件和私钥拷贝至/etc/openldap/certs目录下:
1[root@ip-172-31-24-169 certs]# scp ldap.crt ldap.key /etc/openldap/certs/ 2[root@ip-172-31-24-169 certs]# ll /etc/openldap/certs/
(可左右滑动)
3.修改OpenLDAP的slapd.ldif配置文件
安装OpenLDAP服务后默认的配置文件及数据库文件在/usr/share/openldap-servers目录下
将该目录下的slapd.ldif文件拷贝至/root目录下
1[root@ip-172-31-24-169 openldap-servers]# cp slapd.ldif /root/ 2[root@ip-172-31-24-169 openldap-servers]# cd /root/ 3[root@ip-172-31-24-169 ~]# vim slapd.ldif
(可左右滑动)
修改slapd.ldif文件,将部分注释去掉,增加include的文件及配置管理员账号和OpenLDAP的根域信息,文件全部内容如下:
注意:配置文件中需要注意的TLS Settings配置,如果不启用则可以将相关的配置注释。
配置文件中多处配置dc=fayson,dc=com,由于我们OpenLDAP的域为fayson.com,如果LDAP的域为ldap.fayson.com则我们的配置为dc=ldap,dc=fayson,dc=com,根据自己LDAP的域名进行相应的修改。
1# 2# See slapd-config(5) for details on configuration options. 3# This file should NOT be world readable. 4# 5dn: cn=config 6objectClass: olcGlobal 7cn: config 8olcArgsFile: /var/run/openldap/slapd.args 9olcPidFile: /var/run/openldap/slapd.pid 10# 11# TLS settings 12# 13olcTLSCACertificatePath: /etc/openldap/certs 14olcTLSCertificateFile: /etc/openldap/certs/ldap.crt 15olcTLSCertificateKeyFile: /etc/openldap/certs/ldap.key 16# 17# Schema settings 18# 19dn: cn=schema,cn=config 20objectClass: olcSchemaConfig 21cn: schema 22include: file:///etc/openldap/schema/corba.ldif 23include: file:///etc/openldap/schema/core.ldif 24include: file:///etc/openldap/schema/cosine.ldif 25include: file:///etc/openldap/schema/duaconf.ldif 26include: file:///etc/openldap/schema/dyngroup.ldif 27include: file:///etc/openldap/schema/inetorgperson.ldif 28include: file:///etc/openldap/schema/java.ldif 29include: file:///etc/openldap/schema/misc.ldif 30include: file:///etc/openldap/schema/nis.ldif 31include: file:///etc/openldap/schema/openldap.ldif 32include: file:///etc/openldap/schema/ppolicy.ldif 33include: file:///etc/openldap/schema/collective.ldif 34# 35# Frontend settings 36# 37dn: olcDatabase=frontend,cn=config 38objectClass: olcDatabaseConfig 39objectClass: olcFrontendConfig 40olcDatabase: frontend 41# 42# Configuration database 43# 44dn: olcDatabase=config,cn=config 45objectClass: olcDatabaseConfig 46olcDatabase: config 47olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage by * none 48# 49# Server status monitoring 50# 51dn: olcDatabase=monitor,cn=config 52objectClass: olcDatabaseConfig 53olcDatabase: monitor 54olcAccess: to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read by dn.base="cn=Manager,dc=fayson,dc=com" read by * none 55# 56# Backend database definitions 57# 58dn: olcDatabase=hdb,cn=config 59objectClass: olcDatabaseConfig 60objectClass: olcHdbConfig 61olcDatabase: hdb 62olcSuffix: dc=fayson,dc=com 63olcRootDN: cn=Manager,dc=fayson,dc=com 64olcRootPW: 123456 65olcDbDirectory: /var/lib/ldap 66olcDbIndex: objectClass eq,pres 67olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub 68olcDbIndex: uidNumber,gidNumber,loginShell eq,pres 69olcDbIndex: uid,memberUid eq,pres,sub 70olcDbIndex: nisMapName,nisMapEntry eq,pres,sub
(可左右滑动)
4.使用如下命令,重新生成OpenLDAP的配置
1[root@ip-172-31-24-169 ~]# rm -rf /etc/openldap/slapd.d/* 2[root@ip-172-31-24-169 ~]# slapadd -F /etc/openldap/slapd.d -n 0 -l /root/slapd.ldif
(可左右滑动)
测试配置文件是否正确,返回“config file testing succeeded”则表示配置文件正确
1[root@ip-172-31-24-169 ~]# slaptest -u -F /etc/openldap/slapd.d
(可左右滑动)
修改配置文件的属主,操作如下:
1[root@ip-172-31-24-169 ~]# chown -R ldap. /etc/openldap/slapd.d/ 2[root@ip-172-31-24-169 ~]# ll /etc/openldap/slapd.d/
(可左右滑动)
5.安装OpenLDAP的数据库文件
将/usr/share/openldap-servers/目录下的DB_CONFIG.example文件拷贝至/var/lib/ldap目录下并重命名为DB_CONFIG,操作如下:
1[root@ip-172-31-24-169 ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG 2[root@ip-172-31-24-169 ~]# ll /var/lib/ldap/
(可左右滑动)
修改数据库文件属主
1[root@ip-172-31-24-169 ~]# chown -R ldap. /var/lib/ldap/ 2[root@ip-172-31-24-169 ~]# ll /var/lib/ldap/
(可左右滑动)
6.完成上述操作后,执行如下命令将slapd服务添加到系统自启动服务并启动slapd服务,查看服务启动状态
1[root@ip-172-31-24-169 ~]# systemctl enable slapd 2[root@ip-172-31-24-169 ~]# systemctl start slapd 3[root@ip-172-31-24-169 ~]# systemctl status slapd
(可左右滑动)
至此OpenLDAP服务安装成功。
3.导入根域及管理员账号
1.创建root.ldif文件,内容如下
1[root@ip-172-31-24-169 ldap]# vim root.ldif 2dn: dc=fayson,dc=com 3dc: fayson 4objectClass: top 5objectClass: domain 6dn: cn=Manager,dc=fayson,dc=com 7objectClass: organizationalRole 8cn: Manager
(可左右滑动)
2.导入根域及管理员信息到OpenLDAP服务中
1[root@ip-172-31-24-169 ldap]# ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f root.ldif
(可左右滑动)
3.查看是否导入成功
1[root@ip-172-31-24-169 ldap]# ldapsearch -h ip-172-31-24-169.ap-southeast-1.compute.internal -b "dc=fayson,dc=com" -D "cn=Manager,dc=fayson,dc=com" -W
(可左右滑动)
4.导入基础文件及用户和用户组
在安装OpenLDAP服务是安装了migrationtools服务,这里我们可以通过该服务生成OpenLDAP的基础文件、用户和用户组的ldif文件
1.进入/usr/share/migrationtools/目录修改migrate_common.ph文件,将文件中的$DEFAULT_MAIL_DOMAIN和$DEFAULT_BASE修改为自己OpenLDAP的域
1# Default DNS domain 2$DEFAULT_MAIL_DOMAIN = "fayson.com"; 3# Default base 4$DEFAULT_BASE = "dc=fayson,dc=com";
(可左右滑动)
2.使用如下命令导出OpenLdap的base.ldif文件
1[root@ip-172-31-24-169 ldap]# /usr/share/migrationtools/migrate_base.pl >base.ldif 2[root@ip-172-31-24-169 ldap]# ll 3[root@ip-172-31-24-169 ldap]# vim base.ldif
(可左右滑动)
根据自己的需求保留需要的基础域配置,此处是Fayson的配置
1dn: ou=People,dc=fayson,dc=com 2ou: People 3objectClass: top 4objectClass: organizationalUnit 5dn: ou=Group,dc=fayson,dc=com 6ou: Group 7objectClass: top 8objectClass: organizationalUnit 9
(可左右滑动)
3.执行如下命令导出操作系统的group.ldif文件
1[root@ip-172-31-24-169 ldap]# /usr/share/migrationtools/migrate_group.pl /etc/group > group.ldif 2[root@ip-172-31-24-169 ldap]# ll 3[root@ip-172-31-24-169 ldap]# vim group.ldif
(可左右滑动)
根据需要删除不需要导入OpenLDAP服务的group,如下是Fayson的配置
1dn: cn=root,ou=Group,dc=fayson,dc=com 2objectClass: posixGroup 3objectClass: top 4cn: root 5userPassword: {crypt}x 6gidNumber: 0 7dn: cn=fayson,ou=Group,dc=fayson,dc=com 8objectClass: posixGroup 9objectClass: top 10cn: fayson 11userPassword: {crypt}x 12gidNumber: 1001 13
(可左右滑动)
4.使用如下命令导出操作系统用户的ldif文
1[root@ip-172-31-24-169 ldap]# /usr/share/migrationtools/migrate_passwd.pl /etc/passwd >user.ldif 2[root@ip-172-31-24-169 ldap]# ll 3[root@ip-172-31-24-169 ldap]# vim user.ldif
(可左右滑动)
根据需要保留user.ldif文件中需要导入OpenLDAP服务的用户信息,注意用户信息与group.ldif中组的对应,否则会出现用户无相应组的问题,如下是Fayson的配置
1dn: uid=root,ou=People,dc=fayson,dc=com 2uid: root 3cn: root 4objectClass: account 5objectClass: posixAccount 6objectClass: top 7objectClass: shadowAccount 8userPassword: {crypt}!! 9shadowLastChange: 17094 10shadowMin: 0 11shadowMax: 99999 12shadowWarning: 7 13loginShell: /bin/bash 14uidNumber: 0 15gidNumber: 0 16homeDirectory: /root 17gecos: root 18dn: uid=fayson,ou=People,dc=fayson,dc=com 19uid: fayson 20cn: fayson 21objectClass: account 22objectClass: posixAccount 23objectClass: top 24objectClass: shadowAccount 25userPassword: {crypt}!! 26shadowLastChange: 17566 27shadowMin: 0 28shadowMax: 99999 29shadowWarning: 7 30loginShell: /bin/bash 31uidNumber: 1001 32gidNumber: 1001 33homeDirectory: /home/fayson 34
(可左右滑动)
使用slapadd命令将基础文件及用户和组导入OpenLDAP
ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f base.ldif ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f group.ldif ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f user.ldif
(可左右滑动)
4.查看是否导入成功
ldapsearch -h ip-172-31-24-169.ap-southeast-1.compute.internal -b "dc=fayson,dc=com" -D "cn=Manager,dc=fayson,dc=com" -W|grep dn
(可左右滑动)
5.OpenLDAP客户端配置
1.在ip-172-31-30-69节点安装OpenLDAP的客户端软件包
[root@ip-172-31-30-69 ~]# yum -y install openldap-clients
(可左右滑动)
2.修改/etc/openldap/ldap.conf文件,内容如下:
[root@ip-172-31-30-69 ~]# yum -y install openldap-clients [root@ip-172-31-30-69 ~]# vim /etc/openldap/ldap.conf # # LDAP Defaults # # See ldap.conf(5) for details # This file should be world readable but not world writable. #BASE dc=example,dc=com #URI ldap://ldap.example.com ldap://ldap-master.example.com:666 #SIZELIMIT 12 #TIMELIMIT 15 #DEREF never TLS_CACERTDIR /etc/openldap/certs URI ldap://ip-172-31-24-169.ap-southeast-1.compute.internal BASE dc=fayson,dc=com # Turning this off breaks GSSAPI used with krb5 when rdns = false SASL_NOCANON on
(可左右滑动)
3.测试客户端是否配置成功
[root@ip-172-31-30-69 ~]# ldapsearch -D "cn=Manager,dc=fayson,dc=com" -W |grep dn
(可左右滑动)
注意:如果未配置/etc/openldap/ldap.conf文件则需要在ldapsearch命令后加-hip-172-31-24-169.ap-southeast-1.compute.internal -b"dc=fayson,dc=com"参数。
提示:代码块部分可以左右滑动查看噢
为天地立心,为生民立命,为往圣继绝学,为万世开太平。
温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。
原创文章,欢迎转载,转载请注明:转载自微信公众号Hadoop实操