一、安装 Docker
安装一个linux,可以是Centos或Ubuntu,如果是Centos 7.X,那么要注意先将系统自带的docker先删除。下文以Centos7.9为例
#删除自带的不完整版本
yum remove docker docker-client docker-client-latest \
docker-common docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 安装完整版 docker-ce
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce
systemctl start docker
systemctl enable docker
# 安装 docker-compose,就是从github中下载一个回来。2.X版本都可以。
curl -L https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-`uname -s`-`uname -m` \
-o /usr/local/bin/docker-compose
chmod a+x /usr/local/bin/docker-compose
二、建立含Oracle和PG数据库驱动的镜像文件
建立 基于 PG 的 meta 数据库
mkdir /pgdata
docker pull postgres:12.3
docker run --name postgres12 -e POSTGRES_PASSWORD=password -p 5432:5432 -v /pgdata:/var/lib/postgresql/data -d postgres:12.3
docker exec -it postgres12 bash
# 进入到 docker 内部
su postgres
psql -U postgres -W (登录时要输入密码,如 docker 所设)
# 进入到 docker 的 postgresql 内部
create user superset with password 'password';
create database superset owner superset;
exit
exit
# (退回到宿主操作系统)
exit
#编辑 /pgdata/pg_hba.conf 最后一行,看看有没有:
host all all all md5
# 如果没有,需加上去,以保证数据库能被其它机器访问
#关闭 pg库
docker stop postgresql12
```bash
mkdir /root/docker_superset
cd /root/docker_superset
docker pull postgres:12.3
docker
docker pull apache/superset:3.0.0
vi superset_conf.py
创建 /root/docker_superset/superset_conf.py 内容如下:
SECRET_KEY = 'superset'
SQLALCHEMY_DATABASE_URI = 'postgresql://superset:password@postgres12/superset'
WTF_CSRF_ENABLED = False
TALISMAN_ENABLED = False
BABEL_DEFAULT_LOCALE = "zh"
LANGUAGES = {
"zh": {"flag": "cn", "name": "简体中文"},
"en": {"flag": "us", "name": "English"},
}
创建目录 /root/docker_superset/oracle_driver/
在网上找Oracle的驱动文件,
oracle-instantclient-basic-xxxxxxx.rpm 的文件(xxxx是版本号)
将其解压提取里面文件并放到上面的目录中。(https://yum.oracle.com/repo/OracleLinux/OL8/oracle/instantclient21/x86_64/)
下载 libaio1_0.3.113-5_amd64.deb 文件。Debian -- 软件包下载地址选择 -- libaio1_0.3.113-5_amd64.deb (不一定要个版本)
并把文件也放到上面目录中。
创建Dockerfile,COPY里面的内容应按上面的驱动文件实际情况为准。
cat /root/docker_superset/Dockerfile
FROM apache/superset:3.0.0
USER root
COPY superset_config.py /app/pythonpath
RUN mkdir /oracledriver
ENV LD_LIBRARY_PATH=/oracledriver
COPY ./oracledriver/adrci /oracledriver/adrci
COPY ./oracledriver/genezi /oracledriver/genezi
COPY ./oracledriver/libclntshcore.so.18.1 /oracledriver/libclntshcore.so.18.1
COPY ./oracledriver/libclntsh.so /oracledriver/libclntsh.so
COPY ./oracledriver/libclntsh.so.18.1 /oracledriver/libclntsh.so.18.1
COPY ./oracledriver/libipc1.so /oracledriver/libipc1.so
COPY ./oracledriver/libmql1.so /oracledriver/libmql1.so
COPY ./oracledriver/libnnz18.so /oracledriver/libnnz18.so
COPY ./oracledriver/libocci.so /oracledriver/libocci.so
COPY ./oracledriver/libocci.so.18.1 /oracledriver/libocci.so.18.1
COPY ./oracledriver/libociei.so /oracledriver/libociei.so
COPY ./oracledriver/libocijdbc18.so /oracledriver/libocijdbc18.so
COPY ./oracledriver/libons.so /oracledriver/libons.so
COPY ./oracledriver/liboramysql18.so /oracledriver/liboramysql18.so
COPY ./oracledriver/ojdbc8.jar /oracledriver/ojdbc8.jar
COPY ./oracledriver/ucp.jar /oracledriver/ucp.jar
COPY ./oracledriver/uidrvci /oracledriver/uidrvci
COPY ./oracledriver/xstreams.jar /oracledriver/xstreams.jar
COPY ./oracledriver/libaio1_0.3.113-5_amd64.deb /oracledriver/libaio1_0.3.113-5_amd64.deb
RUN dpkg -i /oracledriver/libaio1_0.3.113-5_amd64.deb
RUN pip install cx_oracle psycopg2 pyhive &&\
pybabel compile -d /app/superset/translations; exit 0
USER superset
创建本地镜像,在 /root/docker_superset 目录上运行以下命令,留意最后有一个 点,表示当前目录
docker build --no-cache -t superset-pg-ora:3.0.0 .
在 /root/docker_superset 目录上创建 docker-compose.yml
cat docker-compose.yml
version: '1.0'
networks:
superset-net:
name: ss-net
services:
superset:
image: superset-pg-ora:3.0.0
container_name: superset
hostname: superset
restart: always
ports:
- 8080:8088
environment:
- TZ=Asia/Shanghai
networks:
- superset-net
depends_on:
- postgres12
postgres12:
image: postgres:12.3
restart: always
volumes:
- /pgdata:/var/lib/postgresql/data
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
environment:
POSTGRES_PASSWORD: password
networks:
- superset-net
执行
#起动系统
docker-compose up -d
# 创建 superset 的管理员用户
docker exec -it superset superset fab create-admin \
--username admin \
--firstname Superset \
--lastname Admin \
--email admin@superset.com \
--password admin
#升级数据库(包含一部分初始化)
docker exec -it superset superset db upgrade
#初始化 Superset
docker exec -it superset superset init
登录后
Oracle的连接串应写成:
oracle+cx_oracle://user:password@ip_address:1521/orcl