-
背景
HUE 3.11.0支持AWS的s3集群贩猎,但在內(nèi)網(wǎng)環(huán)境部署時發(fā)現(xiàn)HUE無法訪問自有的s3集群,打開s3的filebrowser后一直卡住佑惠,約6分鐘后timeout宙址。
-
分析&定位
根據(jù)http://gethue.com/introducing-s3-support-in-hue/ 提供的配置指南,并無指定endpoint的配置項债热,只能指定region砾嫉,判斷是hue只會去連接Amazon的aws 集群。
-
通過Google發(fā)現(xiàn)相關ISSUE:https://issues.cloudera.org/browse/HUE-5420 確認前面的分析(支持自定義endpoint的功能在3.12.0中才能支持)窒篱。
同時由于使用的CDH版本的問題焕刮,直接升級HUE版本可能存在其他風險,決定直接在3.11.0上添加該feature墙杯。找到相關的patchset:https://github.com/cloudera/hue/commit/51e26240ac6d0aa6c86403051678bbe5d73ab8ec
?
-
解決方案:
-
在aws/src/aws/conf.py中增加相關配置項的讀取
#/opt/cloudera/parcels/CDH-5.9.0-1.cdh5.9.0.p0.23/lib/hue/desktop/libs/aws/src/aws/conf.py def get_default_region(): return AWS_ACCOUNTS['default'].REGION.get() +DEFAULT_CALLING_FORMAT='boto.s3.connection.S3Connection.DefaultCallingFormat' AWS_ACCOUNTS = UnspecifiedConfigSection( ... REGION=Config( key='region', default='us-east-1', type=str + ), + PROXY_ADDRESS=Config( + help=_('Alternate address for endpoint.'), + key='proxy_address', + default=None, + type=str + ), + PROXY_PORT=Config( + help=_('Alternate port for endpoint.'), + key='proxy_port', + default=None, + type=int + ), + CALLING_FORMAT=Config( + key='calling_format', + default=DEFAULT_CALLING_FORMAT, + type=str + ), + IS_SECURE=Config( + key='is_secure', + default=True, + type=coerce_bool
?
-
在aws/src/aws/client.py中判斷是否使用自定義endpoint然后創(chuàng)建對應的connection
#/opt/cloudera/parcels/CDH-5.9.0-1.cdh5.9.0.p0.23/lib/hue/desktop/libs/aws/src/aws/client.py import boto import boto.s3 +import boto.s3.connection import boto.utils from aws.conf import get_default_region, has_iam_metadata @@ -27,12 +28,17 @@ class Client(object): def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, aws_security_token=None, region=None, - timeout=HTTP_SOCKET_TIMEOUT_S): + timeout=HTTP_SOCKET_TIMEOUT_S, proxy_address=None, + proxy_port=None, calling_format=None, is_secure=True): self._access_key_id = aws_access_key_id self._secret_access_key = aws_secret_access_key self._security_token = aws_security_token self._region = region.lower() if region else get_default_region() self._timeout = timeout + self._proxy_address = proxy_address + self._proxy_port = proxy_port + self._calling_format = conf.DEFAULT_CALLING_FORMAT if calling_format is None else calling_format + self._is_secure = is_secure boto.config.add_section('Boto') boto.config.set('Boto', 'http_socket_timeout', str(self._timeout)) @@ -51,15 +57,27 @@ def from_config(cls, conf): aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, aws_security_token=security_token, - region=conf.REGION.get() + region=conf.REGION.get(), + proxy_address=conf.PROXY_ADDRESS.get(), + proxy_port=conf.PROXY_PORT.get(), + calling_format=conf.CALLING_FORMAT.get(), + is_secure=conf.IS_SECURE.get() ) def get_s3_connection(self): # First attempt to connect via specified credentials - connection = boto.s3.connect_to_region(self._region, - aws_access_key_id=self._access_key_id, - aws_secret_access_key=self._secret_access_key) + if self._proxy_address is not None and self._proxy_port is not None: + # 此次有坑配并,需用boto.connect_s3,不要用patchset中的boto.s3.connection.S3Connection高镐,該connection會報bad resopnse溉旋,可能是版本問題 + connection = boto.connect_s3( + aws_access_key_id = self._access_key_id, + aws_secret_access_key = self._secret_access_key, + host = self._proxy_address, + port = self._proxy_port, + is_secure = self._is_secure, + calling_format = self._calling_format + ) + else: + connection = boto.s3.connect_to_region(self._region, + aws_access_key_id=self._access_key_id, + aws_secret_access_key=self._secret_access_key)
-
在CDH的hue配置(hue服務范圍->hue_safety_valve.ini 的 Hue 服務高級配置代碼段(安全閥))中添加相關的參數(shù)
proxy_address,porxy_port,is_secure,calling_format
[aws] [[aws_accounts]] [[[default]]] access_key_id= your access_key_id secret_access_key= your secret_access_key allow_environment_credentials=false region=us-east-1 proxy_address=10.213.44.119 proxy_port=7480 is_secure=false calling_format=boto.s3.connection.OrdinaryCallingFormat
-
重啟hue server 即可
?
-
-
后記
-
如果在filebrowser中點擊bucket列表進入后頁面卡死,可能是因為自建的s3集群返回的文件時間戳格式不對嫉髓。比如返回的時間戳格式是UTC時間 "2016-12-20T00.01.02.123Z"就會觸發(fā)如下的校驗观腊,注釋掉即可
# /opt/cloudera/parcels/CDH-5.9.0-1.cdh5.9.0.p0.23/lib/hue/desktop/libs/aws/src/aws/s3/init.py 139L, 4066C try: stripped = time.strptime(datetime[:-4], '%a, %d %b %Y %H:%M:%S') assert datetime[-4:] == ' GMT', 'Time [%s] is not in GMT.' % datetime except ValueError: stripped = time.strptime(datetime[:-5], '%Y-%m-%dT%H:%M:%S') # assert datetime[-5:] == '.000Z', 'Time [%s] is not in GMT.' % datetime return int(calendar.timegm(stripped))
-
-
Hue debug模式開關:hue服務范圍->啟用 Django 調(diào)試模式
?