Hadoop自身是没有安全认证的,所以需要引入第三方的安全认证机制。kerberos是hadoop比较受欢迎的一种认证方式。kerberos配置比较简单。但是实际使用的时候,如果不严格遵守游戏规则。你会经常遇到“奇怪”的问题。
1. 安装kerberos的软件包
yum install krb5*
vi /etc/krb5.conf
2. 修改kerberos的配置文件
# more /etc/krb5.conf
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
default_realm = LIANG.COM
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24h
renew_lifetime = 2d
forwardable = false
[realms]
LIANG.COM = {
kdc = c6701
admin_server = c6701
default_domain = liang.com
key_stash_file = /var/kerberos/krb5kdc/.k5.LIANG.COM
dict_file = /usr/share/dict/words
}
[domain_realm]
.liang.com = LIANG.COM
liang.com = LIANG.COM
3. 修改kdc配置文件
cat /var/kerberos/krb5kdc/kdc.conf
[kdcdefaults]
kdc_ports = 88
kdc_tcp_ports = 88
[realms]
LIANG.COM = {
kadmind_port = 749
master_key_type = aes256-cts-hmac-sha1-96
acl_file = /var/kerberos/krb5kdc/kadm5.acl
dict_file = /usr/share/dict/words
supported_enctypes = des3-cbc-sha1:normal
max_life = 24h 0m 0s
max_renewable_life = 7d 0h 0m 0s
dict_file = /usr/share/dict/words
key_stash_file = /var/kerberos/krb5kdc/.k5.LIANG.COM
database_name = /var/kerberos/krb5kdc/principal
}
执行命令创建kdc数据库kdb5_util create -s -r HADOOP.LIANG.COM
4. 给数据库管理员添加ACL权限,修改kadm5.acl文件,*代表全部权限# cat /var/kerberos/krb5kdc/kadm5.acl
*/admin@ESGYN.COM *
5. 启动服务# service krb5kdc start
# service kadmin start
# service krb5kdc status
# service kadmin status
# chkconfig krb5kdc on
# chkconfig kadmin on
6. 补充:在每个客户端的系统参数/etc/profile中,加上下面参数,确保每次su - user都能使用同一个tgt,而不是创建一个新的,而找不到,最终导致su的用户kinit失败# workaround for kerberos loging
export KRB5CCNAME=FILE:/tmp/krb5cc_`id -u`
7. 创建principalkadmin.local -q "addprinc -pw "
针对hadoop用户,增加主机名,一同创建principal,增加安全性。
注意:hadoop只能通过小写的主机名进行注册。如果主机名有大写字母,手动改成小写。后续kinit的时候,也是使用小写的。hadoop会自动将大写的主机名变成小写。kadmin.local -q "addprinc -pw hdfs/"
8. 创建keytabkadmin.local -q "ktadd -norandkey -k /root/keytab/.keytab "
9. 注册kinit -kt /root/keytab/hdfs.keytab
针对hadoop用户,增加主机名,一同创建principal,增加安全性。kinit -kt /root/keytab/hdfs.keytab hdfs/`hostname`
10. 查询当前用户的kinit情况$ klist
Ticket cache: FILE:/tmp/krb5cc_1098
Default principal: hdfs/hdfs1.liang.com@LIANG.COM
Valid starting Expires Service principal
03/26/18 17:19:04 03/27/18 17:19:04 krbtgt/LIANG.COM@LIANG.COM
renew until 04/02/18 17:19:04
11. 查询keytab文件内容$ klist -kt /etc/security/keytab/hdfs.keytab
Keytab name: FILE:/root/keytab/hdfs.keytab
KVNO Timestamp Principal
---- ----------------- --------------------------------------------------------
1 04/07/17 16:16:04 hdfs/hdfs1.liang.com@LIANG.COM
1 04/07/17 16:16:04 hdfs/hdfs2.liang.com@LIANG.COM
1 04/07/17 16:16:05 hdfs/hdfs3.liang.com@LIANG.COM
12. 查询KDC,用户列表kadmin.local -q "listprincs"
13. 删除用户kadmin.local -q "delprinc -force HTTP/hdfs3.liang.com@LIANG.COM"
14. 修改密码kpasswd 用户名