参考:https://blog.csdn.net/weixin_42660202/article/details/115611879
一、安装hue4.9
1.从docker中心仓库下载hue.9的镜像
docker pull gethue/hue:4.9.0
2.安装运行hue4.9的镜像容器,-d后台运行 -p执行容器端口和hue端口的映射, --name指定该容器的名称
docker run -it -d -p 8888:8888 --name=hue gethue/hue:4.9.0
3.浏览器访问http://localhost:8888,初次登陆需要设置用户名密码,登陆进去后由于没有配置任何需要访问的数据连接,所以报错。
二.配置连接mysql数据库
1.hue在docker容器中的配置文件位置:/usr/share/hue/desktop/conf/hue.ini,由于docker容器中没有自带vim,需要将配置文件复制到宿主机
docker cp hue:/usr/share/hue/desktop/conf/hue.ini ./hue.ini
2.对复制出来的hue.ini通过vim进行编辑,编辑完成后保存(数据库连接后面需要带charset=utf8,否则查询出来的数据中文乱码,此处连接的是mysql5.6,高版本的mysql连接参数可能不同)
[[[mysql]]]
name = MySQL
interface=sqlalchemy
options='{"url": "mysql://user:password@host:port/database?charset=utf8"}'
3.将配置文件从宿主机复制到容器中,并覆盖原来的配置文件
docker cp ./hue.ini hue_least:/usr/share/hue/desktop/conf/hue.ini
4.重启docker容器
docker restart hue
5.重新访问hue,已经可以连接mysql数据库查询了
三 配置元数据库
由于hue默认用的是sqllite,在访问hue时经常被锁,所以可以更换元数据库为mysql
1.在mysql中创建hue的元数据库
2.编辑配置文件hue.ini(前面从容器中复制出来的配置文件),添加如下内容,name值为刚才创建的hue数据库,编辑完成后保存,特别注意是编辑database下的参数,配置文件中还有一个databases,千万不要编辑错
[[database]]
engine=mysql
host=xxxx
port=3306
user=xxx
password=xxx
name=hue
options={ "init_command":"SET NAMES 'utf8'"}
3.将配置文件从宿主机复制到容器中,并覆盖原来的配置文件
docker cp ./hue.ini hue_least:/usr/share/hue/desktop/conf/hue.ini
4.进入容器
docker exec -it -u root hue_least bash
5.初始化元数据库
#进入脚本目录
cd build/env/bin/
#初始化库
./hue syncdb
#初始化表
./hue migrate
执行结果如下:
root@6353e4c791be:/usr/share/hue/build/env/bin# ./hue migrate
[09/May/2022 13:06:26 ] settings INFO Welcome to Hue 4.9.0
[09/May/2022 06:06:26 -0700] backend WARNING pam module not found
[09/May/2022 06:06:26 -0700] backend WARNING mozilla_django_oidc module not found
[09/May/2022 06:06:26 -0700] client WARNING gcs_oauth2_boto_plugin module not found
[09/May/2022 06:06:27 -0700] decorators INFO AXES: BEGIN LOG
[09/May/2022 06:06:27 -0700] decorators INFO AXES: Using django-axes 4.5.4
[09/May/2022 06:06:27 -0700] decorators INFO AXES: blocking by IP only.
[09/May/2022 06:06:27 -0700] views WARNING httplib2 module not found
[09/May/2022 06:06:27 -0700] backend WARNING httplib2 module not found
[09/May/2022 06:06:27 -0700] urls WARNING djangosaml2 module not found
[09/May/2022 06:06:27 -0700] api3 WARNING simple_salesforce module not found
[09/May/2022 06:06:27 -0700] jdbc WARNING Failed to import py4j
System check identified some issues:
WARNINGS:
jobbrowser.DagDetails.dag_info: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
jobbrowser.QueryDetails.hive_query: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
Operations to perform:
Apply all migrations: admin, auth, axes, beeswax, contenttypes, desktop, jobsub, oozie, pig, sessions, sites, useradmin
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying axes.0001_initial... OK
Applying axes.0002_auto_20151217_2044... OK
Applying axes.0003_auto_20160322_0929... OK
Applying axes.0004_auto_20181024_1538... OK
Applying axes.0005_remove_accessattempt_trusted... OK
Applying beeswax.0001_initial... OK
Applying beeswax.0002_auto_20200320_0746... OK
Applying desktop.0001_initial... OK
Applying desktop.0002_initial... OK
Applying desktop.0003_initial... OK
Applying desktop.0004_initial... OK
Applying desktop.0005_initial... OK
Applying desktop.0006_initial... OK
Applying desktop.0007_initial... OK
Applying desktop.0008_auto_20191031_0704... OK
Applying desktop.0009_auto_20191202_1056... OK
Applying desktop.0010_auto_20200115_0908... OK
Applying desktop.0011_document2_connector... OK
Applying desktop.0012_connector_interface... OK
Applying jobsub.0001_initial... OK
Applying oozie.0001_initial... OK
Applying oozie.0002_initial... OK
Applying oozie.0003_initial... OK
Applying oozie.0004_initial... OK
Applying oozie.0005_initial... OK
Applying oozie.0006_auto_20200714_1204... OK
Applying oozie.0007_auto_20210126_2113... OK
Applying pig.0001_initial... OK
Applying pig.0002_auto_20200714_1204... OK
Applying sessions.0001_initial... OK
Applying sites.0001_initial... OK
Applying sites.0002_alter_domain_unique... OK
Applying useradmin.0001_initial... OK
Applying useradmin.0002_userprofile_json_data... OK
Applying useradmin.0003_auto_20200203_0802... OK
Applying useradmin.0004_userprofile_hostname... OK
[09/May/2022 06:07:24 -0700] models INFO HuePermissions: 33 added, 0 updated, 0 up to date, 0 stale, 0 deleted
6.输入exit,退出容器,并且重启容器
docker restart hue
7.重新访问hue,需要重新创建账号密码,进入主页