-
背景
HUE 3.11.0支持AWS的s3集群,但在内网环境部署时发现HUE无法访问自有的s3集群,打开s3的filebrowser后一直卡住,约6分钟后timeout。
-
分析&定位
根据http://gethue.com/introducing-s3-support-in-hue/ 提供的配置指南,并无指定endpoint的配置项,只能指定region,判断是hue只会去连接Amazon的aws 集群。
-
通过Google发现相关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然后创建对应的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 服务高级配置代码段(安全阀))中添加相关的参数
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"就会触发如下的校验,注释掉即可
# /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 调试模式