天天看點

JupyterHub與OpenLDAP內建

1.文檔編寫目的

Fayson在前面文章《如何在非安全的CDH叢集中部署Jupyter并內建Spark2》及《如何在非安全的CDH叢集中部署多使用者JupyterHub服務并內建Spark2》中介紹了Jupyter與JupyterHub的部署與Spark2內建。JupyterHub的使用者預設是基于OS系統使用者,對于使用者的管理和維護都需要在伺服器上進行操作不便于管理。本篇文章Fayson主要介紹在JupyterHub中如何與OpenLDAP服務內建。

  • 測試環境

1.CM5.15.0和CDH版本5.14.2

2.JupyterHub版本為0.9.2

3.Python版本為3.6.5

  • 前置條件

1.JupyterHub已部署成功

2.JupyterHub與OpenLDAP內建

在JupyterHub中預設隻支援作業系統PAM預設的認證方式,如果需要JupyterHub支援OpenLDAP認證,則需要安裝OpenLDAP認證的插件,插件位址:https://github.com/jupyterhub/ldapauthenticator

1.在Python3環境中安裝jupyterhub-ldapauthenticator包,指令如下:

[root@cdh03 ~]# /opt/cloudera/anaconda3/bin/pip install jupyterhub-ldapauthenticator           

複制

(可左右滑動)

JupyterHub與OpenLDAP內建

安裝完成後驗證是否安裝成功

[root@cdh03 ~]# /opt/cloudera/anaconda3/bin/pip show jupyterhub-ldapauthenticator           

複制

(可左右滑動)

JupyterHub與OpenLDAP內建

2.修改/etc/jupyterhub/jupyterhub_config.py檔案,增加OpenLDAP配置,在檔案預設增加内容如下:

#指定JupyterHub認證類型
c.JupyterHub.authenticator_class = 'ldapauthenticator.LDAPAuthenticator'
#OpenLDAP服務位址
c.LDAPAuthenticator.server_address = 'ldap://cdh01.fayson.com'
#通路使用者群組的DN
c.LDAPAuthenticator.bind_dn_template = [
    "uid={username},ou=People,dc=fayson,dc=com",
    "uid={username},ou=Group,dc=fayson,dc=com"
]           

複制

(可左右滑動)

JupyterHub與OpenLDAP內建

3.啟動Jupyterhub服務

[root@cdh03 jupyterhub]# /opt/cloudera/anaconda3/bin/jupyterhub -f /etc/jupyterhub/jupyterhub_config.py --debug           

複制

(可左右滑動)

JupyterHub與OpenLDAP內建

如上顯示啟動成功,在啟動指令後添加--debug參數可以顯示DEBUG日志,-f指定JupyterHub啟動加載的配置檔案。

3.內建驗證

1.在OpenLDAP上建立一個testldap測試使用者

JupyterHub與OpenLDAP內建

2.在浏覽器輸入http://cdh03.fayson.com:8000通路JupyterHub,使用testldap使用者登入

JupyterHub與OpenLDAP內建

登入成功

JupyterHub與OpenLDAP內建

打開一個Notebook,并運作一段測試的pyspark代碼

JupyterHub與OpenLDAP內建

檢視Yarn上的作業

JupyterHub與OpenLDAP內建
JupyterHub與OpenLDAP內建

4.總結

1.JupyterHub與OpenLDAP內建需要安裝jupyterhub-ldapauthenticator插件。

2.可以通過配置Group限制通路JupyterHub的使用者組,更多配置可參考GitHub:https://github.com/jupyterhub/ldapauthenticator