2017年9月22日金曜日

HDP Sandbox(Docker版)にKerberos+SPNEGOとSSLを設定する

Ubuntu 16.04をインストールしDockerを設定する

https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/

Sandbox Docker版をインストールする

https://hortonworks.com/downloads/#sandbox からDocker版をダウンロードします(ほぼ11GB!)
ダウンロード後、下記のようなコマンドを実行(*は実際は数字)

docker load < /path/to/HDP_2_6_1_docker_image_*_*_*_*_*_*.tar

しばらく待つと、イメージが完了です。

必須ではないですが、ポートフォワーディングがあると直接(プロキシーなどを使わずに)Sandboxにアクセスできるようになるので、設定したほうがおすすめです。
その場合はhttps://raw.githubusercontent.com/hortonworks/data-tutorials/master/tutorials/hdp/sandbox-port-forwarding-guide/assets/start-sandbox-hdp.sh を利用するといいでしょう。
このスクリプトをダウンロードし実行するとSandboxのコンテナーが始まります。(docker psで確認)
AmbariにログインしてHDPがちゃんと動いているか確認してください。

* Ambariにログインできない場合は/usr/sbin/ambari-admin-password-resetコマンドでAdminユーザのパスワードを変更する必要があるかもしれません。
* HiveなどのMySQLを使用するサービスが開始できない場合はmysqldが開始しているか確認してください。
* HDFS DataNodeが始まらない場合は"chown -R hdfs:hadoop /hadoop/hdfs"を試してみてください。Zookeeperなども/hadoop/zookeeperのパーミッションを確認してください。
* yumコマンドが"PYCURL ERROR 22"などでうまくいかない場合は"yum clean all"を試してください。(補足2も参照)

または、上記をスクリプトにして見ました。

HDP Sandbox DockerにKerberosを設定する

ここからが本番です。
ところで、もし、コンテナの調子が悪くなったときは、削除して作り直すほうが、トラブルシュートするより早い場合があります。(docker rm -f sandbox-hdp)

curl -O https://raw.githubusercontent.com/hajimeo/samples/master/bash/setup_security.sh
source ./setup_security.sh
# MIT KDCをUbuntu上にインストールする関数を実行(最初の一回だけ)
f_kdc_install_on_host
# Kerberos化をAmbariから実行する関数を実行
f_ambari_kerberos_setup "EXAMPLE.COM" "172.17.0.1" "" "sandbox.hortonworks.com" "sandbox.hortonworks.com"

* 最後の関数の引数は、1)Realm名、2)KDCサーバーのホスト名かIP Address、3)パスワード(空欄の場合はhadoop)、4)Ambari Serverが走っているホスト名、5)Sandboxホスト名
Sandboxホスト名は正しく名前解決できる必要があります。(/etc/hostsを確認)

HDP Sandbox DockerにSPNEGOを設定する

上記のf_ambari_kerberos_setup以外を実行後、

f_hadoop_spnego_setup "EXAMPLE.COM" "hortonworks.com" "sandbox.hortonworks.com" "8080" "sandbox.hortonworks.com"

引数は、1)REALM、2)Cookieに使用されるDomain名、3)Ambari Serverが走っているホスト名、4)同ポート番号、5)Sandboxほホスト名
Ambariから必要なサービスを再起動してください。

確認!

# --negotiate無しだと失敗するべき
[hdfs@sandbox ~]$ curl -I "http://`hostname -f`:50070/jmx"
HTTP/1.1 401 Authentication required
Cache-Control: must-revalidate,no-cache,no-store
Date: Fri, 22 Sep 2017 01:16:35 GMT
Pragma: no-cache
Date: Fri, 22 Sep 2017 01:16:35 GMT
Pragma: no-cache
Content-Type: text/html; charset=iso-8859-1
X-FRAME-OPTIONS: SAMEORIGIN
WWW-Authenticate: Negotiate
Set-Cookie: hadoop.auth=; Path=/; Domain=hortonworks.com; HttpOnly
Content-Length: 1396
Server: Jetty(6.1.26.hwx)

# kinit後、--negotiate付きだと成功するべき
[hdfs@sandbox ~]$ curl -I --negotiate -u: "http://`hostname -f`:50070/jmx"
HTTP/1.1 401 Authentication required
Cache-Control: must-revalidate,no-cache,no-store
Date: Fri, 22 Sep 2017 01:17:30 GMT
Pragma: no-cache
Date: Fri, 22 Sep 2017 01:17:30 GMT
Pragma: no-cache
Content-Type: text/html; charset=iso-8859-1
X-FRAME-OPTIONS: SAMEORIGIN
WWW-Authenticate: Negotiate
Set-Cookie: hadoop.auth=; Path=/; Domain=hortonworks.com; HttpOnly
Content-Length: 1396
Server: Jetty(6.1.26.hwx)

HTTP/1.1 200 OK
Cache-Control: no-cache
Expires: Fri, 22 Sep 2017 01:17:30 GMT
Date: Fri, 22 Sep 2017 01:17:30 GMT
Pragma: no-cache
Expires: Fri, 22 Sep 2017 01:17:30 GMT
Date: Fri, 22 Sep 2017 01:17:30 GMT
Pragma: no-cache
Content-Type: application/json; charset=utf8
X-FRAME-OPTIONS: SAMEORIGIN
Set-Cookie: hadoop.auth="u=hdfs&p=hdfs-sandbox@EXAMPLE.COM&t=kerberos&e=1506079050370&s=UMYdk7fS8byXBRACypD6kHJQtn4="; Path=/; Domain=hortonworks.com; HttpOnly
Content-Length: 105102
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: *
Server: Jetty(6.1.26.hwx)

HDP Sandbox DockerのHDFS,YARN,MR2にSSL(HTTPS)を設定する

上記と同様に、最後のコマンドが下記になります。

f_hadoop_ssl_setup "" "" "sandbox.hortonworks.com" "8080" "sandbox.hortonworks.com"


Ambariから必要なサービスを再起動してください。

確認!

[hdfs@sandbox ~]$ curl -kI --negotiate -u: "https://`hostname -f`:50470/jmx"
HTTP/1.1 401 Authentication required
Cache-Control: must-revalidate,no-cache,no-store
Date: Fri, 22 Sep 2017 01:33:49 GMT
Pragma: no-cache
Date: Fri, 22 Sep 2017 01:33:49 GMT
Pragma: no-cache
Content-Type: text/html; charset=iso-8859-1
X-FRAME-OPTIONS: SAMEORIGIN
WWW-Authenticate: Negotiate
Set-Cookie: hadoop.auth=; Path=/; Domain=hortonworks.com; Secure; HttpOnly
Content-Length: 1396
Server: Jetty(6.1.26.hwx)

HTTP/1.1 200 OK
...

補足

補足1:ちなみに、"help f_xxxxxxx"と打つとちょっとだけヘルプが出ます。

root@ho-ubu03:~# help f_hadoop_ssl_setup
Setup SSL for hadoop https://community.hortonworks.com/articles/92305/how-to-transfer-file-using
-secure-webhdfs-in-distc.html

Parameters:
    local _dname_extra="$1";
    local _password="$2";
    local _ambari_host="${3-$r_AMBARI_HOST}";
    local _ambari_port="${4-8080}";
    local _how_many="${5-$r_NUM_NODES}";
    local _start_from="${6-$r_NODE_START_NUM}";
    local _domain_suffix="${7-$r_DOMAIN_SUFFIX}";
    local _work_dir="${8-./}";

Show source code? [N]:


補足2:今日現在で、Sandboxのチュートリアル関係と思われるレポジトリーがアクセスできない模様です。
AmbariがKerberos関係のパッケージをインストールする際に失敗します。

http://dev2.hortonworks.com.s3.amazonaws.com/repo/dev/master/utils/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 403 Forbidden"

取り敢えず、今は/etc/yum.repos.d/sandbox.repoを移動して使ってます。

0 件のコメント:

コメントを投稿