Kerberos HA 搭建流程整理
简介
Kerberos 是一款身份认证软件。本次 HA 搭建采用了crontab
+kprop
的方式实现,具体内容参见 官方文档 。
主机安装
1
| yum install -y krb5-server krb5-libs krb5-workstation
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| includedir /etc/krb5.conf.d/
[logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/krb5kdc.log admin_server = FILE:/var/log/kadmind.log
[libdefaults] default_realm = <realm> dns_lookup_kdc = false dns_lookup_realm = false ticket_lifetime = 86400 renew_lifetime = 604800 forwardable = true default_tgs_enctypes = des3-hmac-sha1 aes256-cts default_tkt_enctypes = des3-hmac-sha1 aes256-cts permitted_enctypes = des3-hmac-sha1 aes256-cts udp_preference_limit = 1 kdc_timeout = 3000 rdns = false pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt default_ccache_name = KEYRING:persistent:%{uid}
[realms] <realm> = { kdc = <kdc_host1> admin_server = <kdc_host1> kdc = <kdc_host2> # admin_server = <kdc_host2> }
[domain_realm] .<domain> = <realm> <domain> = <realm>
|
1
| vim /var/kerberos/krb5kdc/kdc.conf
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [kdcdefaults] kdc_ports = 88 kdc_tcp_ports = 88
[realms] <realm> = { #master_key_type = aes256-cts max_life = 1d max_renewable_life= 7d 0h 0m 0s acl_file = /var/kerberos/krb5kdc/kadm5.acl dict_file = /usr/share/dict/words admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal }
|
1
| vim /var/kerberos/krb5kdc/kadm5.acl
|
1
| kdb5_util create -s -r <realm>
|
1 2 3 4
| systemctl enable kadmin systemctl enable krb5kdc systemctl start kadmin systemctl start krb5kdc
|
1 2 3 4
| firewall-cmd --permanent --add-service kerberos firewall-cmd --permanent --add-service kadmin firewall-cmd --permanent --add-service kprop firewall-cmd --reload
|
1 2 3 4 5
| addprinc cloudera-scm/admin addprinc -randkey host/<kdc_ip1> addprinc -randkey host/<kdc_ip2> ktadd host/<kdc_ip1> ktadd host/<kdc_ip2>
|
备机安装
1
| yum install -y krb5-server krb5-libs krb5-workstation
|
1 2 3 4 5
| scp <user>@<kdc_host1>:/etc/krb5.conf /etc/krb5.conf scp <user>@<kdc_host1>:/etc/krb5.keytab /etc/krb5.keytab scp <user>@<kdc_host1>:/var/kerberos/krb5kdc/kadm5.acl /var/kerberos/krb5kdc/kadm5.acl scp <user>@<kdc_host1>:/var/kerberos/krb5kdc/kdc.conf /var/kerberos/krb5kdc/kdc.conf scp <user>@<kdc_host1>:/var/kerberos/krb5kdc/.k5.<realm> /var/kerberos/krb5kdc/.k5.<realm>
|
1
| vim /var/kerberos/krb5kdc/kpropd.acl
|
1 2
| host/<kdc_host1>@<realm> host/<kdc_host2>@<realm>
|
1 2 3 4
| firewall-cmd --permanent --add-service kerberos firewall-cmd --permanent --add-service kadmin firewall-cmd --permanent --add-service kprop firewall-cmd --reload
|
1
| systemctl start kprop --now
|
手动同步数据库
主机
1
| kdb5_util dump /var/kerberos/krb5kdc/master.dump
|
1
| kprop -f /var/kerberos/krb5kdc/master.dump <kdc_host2>
|
注:若出现 SUCCESS 字样则代表传输成功。
备机
1
| mv /var/kerberos/krb5kdc/kpropd.acl /var/kerberos/krb5kdc/kpropd.acl.bk
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| includedir /etc/krb5.conf.d/
[logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/krb5kdc.log admin_server = FILE:/var/log/kadmind.log
[libdefaults] default_realm = <realm> dns_lookup_kdc = false dns_lookup_realm = false ticket_lifetime = 86400 renew_lifetime = 604800 forwardable = true default_tgs_enctypes = des3-hmac-sha1 aes256-cts default_tkt_enctypes = des3-hmac-sha1 aes256-cts permitted_enctypes = des3-hmac-sha1 aes256-cts udp_preference_limit = 1 kdc_timeout = 3000 rdns = false pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt default_ccache_name = KEYRING:persistent:%{uid}
[realms] <realm> = { kdc = <kdc_host1> admin_server = <kdc_host1> kdc = <kdc_host2> # admin_server = <kdc_host2> }
[domain_realm] .<domain> = <realm> <domain> = <realm>
|
1 2
| systemctl start krb5kdc systemctl start kadmin
|
注: 若用户目录对应则证明此处同步正常。
1 2
| systemctl enable krb5kdc --now systemctl stop kadmin
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| includedir /etc/krb5.conf.d/
[logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/krb5kdc.log admin_server = FILE:/var/log/kadmind.log
[libdefaults] default_realm = <realm> dns_lookup_kdc = false dns_lookup_realm = false ticket_lifetime = 86400 renew_lifetime = 604800 forwardable = true default_tgs_enctypes = des3-hmac-sha1 aes256-cts default_tkt_enctypes = des3-hmac-sha1 aes256-cts permitted_enctypes = des3-hmac-sha1 aes256-cts udp_preference_limit = 1 kdc_timeout = 3000 rdns = false pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt default_ccache_name = KEYRING:persistent:%{uid}
[realms] <realm> = { kdc = <kdc_host1> admin_server = <kdc_host1> kdc = <kdc_host2>
}
[domain_realm] .<domain> = <realm> <domain> = <realm>
|
1
| mv /var/kerberos/krb5kdc/kpropd.acl.bk /var/kerberos/krb5kdc/kpropd.acl
|
注:此处的备机如果拥有全部数据库的话可以将 kpropd.acl 文件移除,暂时做为主机使用。
配置自动同步
1
| vim /var/kerberos/krb5kdc/kprop_sync.sh
|
1 2 3 4 5 6 7
| #!/bin/bash DUMP=/var/kerberos/krb5kdc/master.dump SLAVE="<kdc_host2>" TIMESTAMP=`date` echo "Start at $TIMESTAMP" kdb5_util dump $DUMP kprop -f $DUMP -d $SLAVE
|
1 2
| chmod 700 /var/kerberos/krb5kdc/kprop_sync.sh bash /var/kerberos/krb5kdc/kprop_sync.sh
|
1
| 0 */30 * * * root /var/kerberos/krb5kdc/kprop_sync.sh > /var/kerberos/krb5kdc/lastupdate
|
1
| systemctl enable crond --now
|
测试
1
| kinit cloudera-scm/admin@<realm>
|
1
| xst -norandkey -k admin.keytab cloudera-scm/admin@<realm>
|
1 2 3 4 5 6 7 8
| [xxxx@xxxx xxxx]# ktutil ktutil: read_kt admin.keytab ktutil: list slot KVNO Principal ---- ---- --------------------------------------------------------------------- 1 2 xxxx/xxxxx@<realm> .... ktutil: quit
|
1
| kinit -kt admin.keytab cloudera-scm/admin@<realm>
|
客户端环境安装
1
| yum install -y krb5-workstation krb5-libs
|
1
| scp <user>@<ip>:/etc/krb5.conf /etc/krb5.conf
|
Windows 平台的注意事项
- Windows Server 和 Windows 专业版系统上可以使用 Windows 自己的 Kerberos (AD)
- Windows 平台的 Kerberos 与 MIT Kerberos (Linux) 并不是完全兼容的,如果有在 Windows 平台上开发应用程序的需求请选用 Windows AD。
- MIT Kerberos 提供了 Windows 版的客户端,支持浏览器调取 Kerberos 认证。
Firefox 访问 Kerberos 认证服务
在访问开启 Kerberos 鉴权情况下的 WebHDFS 界面的时候需要如下配置浏览器:
1
| network.negotiate-auth.trusted-uris
|
注:如果你使用的是 Windows 则还要把 network.auth.use-sspi 配置为 false
常见问题
Message stream modified (41)
此问题需要注释 renew_lifetime
配置项
Hue 更新令牌
如果遇到 Hue
令牌相关的更新问题可以使用如下命令进行配置:
1 2
| modprinc -maxrenewlife 90day krbtgt/<relam> modprinc -maxrenewlife 90day +allow_renewable hue/<host>@<relam>
|