0005-Windows Kerberos客戶端配置並訪問CDH

溫馨提示:要看高清無碼套圖,請使用手機打開並單擊圖片放大查看。

1.概述

本文檔描述Windows Server2008 R2(windows的內核版本是6.1,與windows 7相同)下安裝Kerberos Client及FireFox下HTTP訪問HDFS、Yarn、Hive、HBase等Hadoop服務的Web UI(如Namenode的50070,Yarn的8088)的過程。安裝文檔主要分爲以下幾步:

1.在Windows Server2008 R2 64位上安裝Kerberos Client。

2.在Windows下使用kinit測試。

3.通過keytab在Windows下進行kinit操作。

4.配置FireFox。

5.驗證服務是否正常訪問。

這篇文檔將着重介紹Winodws Server R2下安裝及使用Kerberos,並基於以下假設:

1.CDH環境已搭建並正常運行

2.HDFS、Yarn、HBase、Hive等組件已安裝部署

3.集羣已完成Kerberos的配置,並正常使用

以下是對本次測試環境,但不是本操作手冊的硬限制:

1.操作系統:Redhat7.2

2.CM版本:CM5.11.1

3.CDH版本:CDH5.11.1

4.採用ec2-user對集羣進行部署

2. Kerberos安裝

2.1 Kerberos安裝包準備

在Kerberos官網下載Kerberos安裝包(http://web.mit.edu/kerberos/dist/),如下截圖:

0005-Windows Kerberos客戶端配置並訪問CDH

根據自己Windows操作系統下載不同的Client,32位或者64位。

2.2安裝Kerberos

1.將下載下來的客戶端雙擊打開

0005-Windows Kerberos客戶端配置並訪問CDH

2.點擊下一步,如下圖所示

0005-Windows Kerberos客戶端配置並訪問CDH

3.選擇“同意”,點擊下一步

0005-Windows Kerberos客戶端配置並訪問CDH

4.選擇“Typical”進入下一步

0005-Windows Kerberos客戶端配置並訪問CDH

5.點擊“install”進行安裝

0005-Windows Kerberos客戶端配置並訪問CDH

點擊“finish”安裝完成

6.配置C:\ProgramData\MIT\Kerberos5\krb5.ini文件

0005-Windows Kerberos客戶端配置並訪問CDH

將KDC Server服務器上/ect/krb5.conf文件中的部分內容,拷貝到krb5.ini文件中

0005-Windows Kerberos客戶端配置並訪問CDH

注意:此處將標註部分拷貝至krb5.ini文件中,否則會導致MIT Kerberos無法正常啓動,如果直接將krb5.conf文件更名爲ini文件並替換krb5.ini文件會出現文件格式問題導致MIT Kerberos無法正常啓動。

7.配置完成後,啓動MIT Kerberos客戶端,如下圖所示:

0005-Windows Kerberos客戶端配置並訪問CDH

3 在Window下使用kinit測試

3.1 使用密碼登錄Kerberos

1.KDC Server上通過admin創建一個用戶

 ec2-user@ip-172-31-18-97  keytab$ sudo kadmin.local
 Authenticating as principal  root/[email protected] with password.
 kadmin.local:   addprinc [email protected]
 WARNING: no policy specified for [email protected];  defaulting to no policy
 Enter password for principal  "[email protected]":
 Re-enter password for principal  "[email protected]": Principal "[email protected]" created. 

0005-Windows Kerberos客戶端配置並訪問CDH

測試正常

0005-Windows Kerberos客戶端配置並訪問CDH

2.在Winodw端,通過MIT Kerberos客戶Get Ticket

0005-Windows Kerberos客戶端配置並訪問CDH

在如下列表中可以看到獲取到的Ticket

0005-Windows Kerberos客戶端配置並訪問CDH

3.銷燬獲取到的Ticket

選中列表中需要銷燬的Ticket,點擊Destroy Ticket

0005-Windows Kerberos客戶端配置並訪問CDH

0005-Windows Kerberos客戶端配置並訪問CDH

4.命令行下初始化

0005-Windows Kerberos客戶端配置並訪問CDH

在客戶端可以看到初始化成功的Ticket

0005-Windows Kerberos客戶端配置並訪問CDH

5.命令行下kdestroy

0005-Windows Kerberos客戶端配置並訪問CDH

客戶端數據已destroy

0005-Windows Kerberos客戶端配置並訪問CDH

3.2 使用Keytab文件登錄Kerberos

1.在KDC Server創建一個ketab文件,使用上一步創建的[email protected]

ec2-user@ip-172-31-18-97  keytab$ sudo kadmin.local
Authenticating  as principal root/[email protected] with password.
kadmin.local:  xst -norandkey -k test.keytab [email protected]
kadmin.local:  Principal test.keytab does not exist.
Entry  for principal [email protected] with kvno 1, encryption type  aes256-cts-hmac-sha1-96 added to keytab WRFILE:-k.
Entry  for principal [email protected] with kvno 1, encryption type  aes128-cts-hmac-sha1-96 added to keytab WRFILE:-k.
Entry  for principal [email protected] with kvno 1, encryption type des3-cbc-sha1  added to keytab WRFILE:-k.
Entry  for principal [email protected] with kvno 1, encryption type arcfour-hmac  added to keytab WRFILE:-k.
Entry  for principal [email protected] with kvno 1, encryption type  camellia256-cts-cmac added to keytab WRFILE:-k.
Entry  for principal [email protected] with kvno 1, encryption type  camellia128-cts-cmac added to keytab WRFILE:-k.
Entry  for principal [email protected] with kvno 1, encryption type des-hmac-sha1  added to keytab WRFILE:-k.
Entry  for principal [email protected] with kvno 1, encryption type des-cbc-md5  added to keytab WRFILE:-k. 

注意:在生成keytab文件時需要加參數”-norandkey”否則會導致,直接使用kinit [email protected]初始化時會提示密碼錯誤。

生成成功

0005-Windows Kerberos客戶端配置並訪問CDH

0005-Windows Kerberos客戶端配置並訪問CDH

測試test.keytab文件

0005-Windows Kerberos客戶端配置並訪問CDH

注意:在非root用戶下需要將生成的keytab文件,權限設置到644以上,否則會初始化失敗或者使用sudo權限初始化

0005-Windows Kerberos客戶端配置並訪問CDH

2.將生成的test.keytab文件拷貝到Windows Server上,在CMD命令行進行初始化

0005-Windows Kerberos客戶端配置並訪問CDH

初始化成功,在MIT Kerberos客戶端顯示

0005-Windows Kerberos客戶端配置並訪問CDH

4 FireFox瀏覽器訪問

4.1 FireFox瀏覽器配置

1.打開FireFox瀏覽器,在地址欄輸入about:config

0005-Windows Kerberos客戶端配置並訪問CDH

2.修改配置參數

network.negotiate-auth.trusted-uris = ip-172-31-18-97.ap-southeast-1.compute.internal,ip-172-31-19-209.ap-southeast-1.compute.internalnetwork.auth.use-sspi = false 

注意:network.negotiate-auth.trusted-uris此參數主要配置需要訪問服務的hostname,如果需要訪問多個host則以“,”分割。

0005-Windows Kerberos客戶端配置並訪問CDH

0005-Windows Kerberos客戶端配置並訪問CDH

4.2 測試訪問HDFS服務

1.訪問HDFS的50070端口

0005-Windows Kerberos客戶端配置並訪問CDH

由於此時未將hdfs的ticket初始化所以不能正常訪問,提示輸入principal和密碼

2.在CM節點的/var/run/cloudera-scm-agent目錄下選擇最新的xxx-hdfs-NAMENODE目錄下的hdfs.keytab文件

0005-Windows Kerberos客戶端配置並訪問CDH

0005-Windows Kerberos客戶端配置並訪問CDH

3.測試hdfs.keytab是否正常

通過kadmin.loca命令列出所有hdfs的身份

 root@ip-172-31-18-97 577-hdfs-NAMENODE#  kadmin.local
 Authenticating as principal  hdfs/[email protected] with password.
 kadmin.local:   listprincs hdfs*
 hdfs/[email protected]
 hdfs/[email protected]
 hdfs/[email protected]
 hdfs/[email protected] 

0005-Windows Kerberos客戶端配置並訪問CDH

 root@ip-172-31-18-97 577-hdfs-NAMENODE# kinit  -kt hdfs.keytab  hdfs/[email protected]
 root@ip-172-31-18-97 577-hdfs-NAMENODE# klist
 Ticket cache: FILE:/tmp/krb5cc\_0
 Default principal: hdfs/[email protected] 
 Valid starting       Expires              Service principal07/26/2017 11:23:08  07/27/2017 11:23:08  krbtgt/[email protected]        
  renew until 07/31/2017 11:23:08 

0005-Windows Kerberos客戶端配置並訪問CDH

注意:可以使用listprincs列出的hdfs身份進行初始化

4.將hdfs.keytab文件拷貝到Windows機器上,通過CMD命令進行初始化

0005-Windows Kerberos客戶端配置並訪問CDH

5.再次通過FireFox瀏覽器訪問HDFS服務,正常訪問

0005-Windows Kerberos客戶端配置並訪問CDH

6.訪問Yarn資源管理服務是否能正常

0005-Windows Kerberos客戶端配置並訪問CDH

查看作業詳情時無法正常訪問,由於該hostname信息未添加到FireFox的network.negotiate-auth.trusted-uris配置中

0005-Windows Kerberos客戶端配置並訪問CDH

將該hostname添加到配置中

0005-Windows Kerberos客戶端配置並訪問CDH

再次訪問成功

0005-Windows Kerberos客戶端配置並訪問CDH

5 keytab合併及使用

1.將需要合併的keytab文件統一的放在同一個目錄下

0005-Windows Kerberos客戶端配置並訪問CDH

2.使用ktutil命令合併keytab文件,操作如下

 root@ip-172-31-18-97 keytab# ktutil 
 ktutil:   rkt hbase.keytab 
 ktutil:   rkt hive.keytab 
 ktutil:   rkt hdfs.keytab 
 ktutil:   rkt yarn.keytab 
 ktutil:   wkt test-new.keytab
 ktutil: 

在當前目錄下生成test-new.keytab文件

0005-Windows Kerberos客戶端配置並訪問CDH

注意:由於生成的keytab文件權限默認爲600,如果非root用戶則需要使用sudo執行ktutil命令或者提升keytab權限至644以上。

3.將生成的文件拷貝至Windows機器上,使用kinit進行初始化

使用hdfs憑證進行初始化

0005-Windows Kerberos客戶端配置並訪問CDH

HDFS的服務訪問成功

0005-Windows Kerberos客戶端配置並訪問CDH

使用hive憑證進行初始化

0005-Windows Kerberos客戶端配置並訪問CDH

訪問HDFS服務成功

0005-Windows Kerberos客戶端配置並訪問CDH

使用hbase憑證進行初始化

0005-Windows Kerberos客戶端配置並訪問CDH

訪問HDFS服務成功

0005-Windows Kerberos客戶端配置並訪問CDH

使用yarn憑證進行初始化

0005-Windows Kerberos客戶端配置並訪問CDH

訪問HDFS服務成功

0005-Windows Kerberos客戶端配置並訪問CDH

通過上述測試,無論使用hdfs/yarn/hbase/hive任何身份均可正常訪問HDFS服務,因此可以得出Kerberos只做身份認證,未做頁面的授權。

6.常見問題

1.無法安裝Kerberos,提示you must install a windows service錯誤

可能是由於Window版本問題,本文檔選擇的安裝包本次不支持Windows Server2008(windows的內核版本是6.0,與windows vista相同),所以建議客戶端機器選擇Windows7或以上版本。

2.設置Kerberos Credential Cache File路徑

配置Windows的環境變量

  • KRB5_CONFIG: Path for the kerberos inifile.()
  • KRB5CCNAME: Path for the kerberoscredential cache file.

0005-Windows Kerberos客戶端配置並訪問CDH

配置完環境變量後,需要重啓機器使其環境變量生效。注意默認的“KRB5CCNAME”目錄是在C:\temp.

3.在windows下的krb5.ini配置錯誤導致MIT Kerberos不能啓動

如果直接將krb5.conf文件更名爲ini文件並替換krb5.ini文件會出現文件格式問題導致MIT Kerberos無法正常啓動,配置信息如下:

# Configuration snippets may be placed in this  directory as well

[libdefaults]

 default_realm = CLOUDERA.COM

 dns_lookup_realm = false

 ticket_lifetime = 24h

 renew_lifetime = 7d

 forwardable = true

 rdns =  false

# default_realm = EXAMPLE.COM

 #default_ccache_name =  KEYRING:persistent:%{uid}

[realms]

# EXAMPLE.COM = {

#  kdc =  kerberos.example.com

#   admin_server = kerberos.example.com

# }

 CLOUDERA.COM = {

  kdc =  ip-172-31-18-97.ap-southeast-1.compute.internal

  admin_server  = ip-172-31-18-97.ap-southeast-1.compute.internal

 }

[domain_realm]

# .example.com = EXAMPLE.COM

# example.com = EXAMPLE.COM

 .ip-172-31-18-97.ap-southeast-1.compute.internal  = CLOUDERA.COM

 ip-172-31-18-97.ap-southeast-1.compute.internal  = CLOUDERA.COM

4.在創建後憑證後,使用該憑證創建keytab文件後,kinit該憑證報密碼錯誤

在生成keytab文件時需要加參數”-norandkey”否則會導致直接使用kinit [email protected]直接初始化時會提示密碼錯誤。

5.在通過瀏覽器訪問Hadoop服務時部分功能能正常,部分功能不正常

需要確認訪問的host地址是否加入network.negotiate-auth.trusted-uris中,此參數主要配置需要訪問服務的hostname,如果需要訪問多個host則以“,”分割。

6.不需要合併所有Hadoop相關的服務的keytab來訪問不同的頁面,成功初始化一個用戶比如HDFS即可。

7 參考文檔

http://doc.mapr.com/display/MapR/Configuring+Kerberos+Authentication+for+Windows

https://www.cloudera.com/documentation/enterprise/latest/topics/cdh\_sg\_browser\_access\_kerberos\_protected\_url.html

https://community.hortonworks.com/articles/28537/user-authentication-from-windows-workstation-to-hd.html

http://web.mit.edu/kerberos/dist/index.html#kfw-4.0

醉酒鞭名馬,少年多浮誇! 嶺南浣溪沙,嘔吐酒肆下!摯友不肯放,數據玩的花!
溫馨提示:要看高清無碼套圖,請使用手機打開並單擊圖片放大查看。
0005-Windows Kerberos客戶端配置並訪問CDH

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章