使用docker-compose方式安装redash

转载自:https://anjia0532.github.io/2019/07/08/redash/

## 安装必要工具
apt install -y pwgen python-pip
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install docker-compose

# 也可以采用其他方式安装docker-compose
# 下载指令
curl -L https://github.com/docker/compose/releases/download/1.26.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 下载完成后没有执行权限, 添加执行权限
chmod +x /usr/local/bin/docker-compose

# 验证
# 查看版本指令
[root@worker ~]# docker-compose version
# 输出内容
docker-compose version 1.26.0, build d4451659
docker-py version: 4.2.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019


## 生成脚本
cat << EOF | sudo tee -a ./setup.sh
#!/usr/bin/env bash
# This script setups dockerized Redash on Ubuntu 18.04.
set -eu

REDASH_BASE_PATH=/opt/redash

create_directories() {
    if [[ ! -e $REDASH_BASE_PATH ]]; then
        sudo mkdir -p $REDASH_BASE_PATH
        sudo chown $USER:$USER $REDASH_BASE_PATH
    fi

    if [[ ! -e $REDASH_BASE_PATH/postgres-data ]]; then
        mkdir $REDASH_BASE_PATH/postgres-data
    fi
}

create_config() {
    if [[ -e $REDASH_BASE_PATH/env ]]; then
        rm $REDASH_BASE_PATH/env
        touch $REDASH_BASE_PATH/env
    fi

    COOKIE_SECRET=$(pwgen -1s 32)
    SECRET_KEY=$(pwgen -1s 32)
    POSTGRES_PASSWORD=$(pwgen -1s 32)
    REDASH_DATABASE_URL="postgresql://postgres:${POSTGRES_PASSWORD}@postgres/postgres"

    echo "PYTHONUNBUFFERED=0" >> $REDASH_BASE_PATH/env
    echo "REDASH_LOG_LEVEL=INFO" >> $REDASH_BASE_PATH/env
    echo "REDASH_REDIS_URL=redis://redis:6379/0" >> $REDASH_BASE_PATH/env
    echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> $REDASH_BASE_PATH/env
    echo "REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> $REDASH_BASE_PATH/env
    echo "REDASH_SECRET_KEY=$SECRET_KEY" >> $REDASH_BASE_PATH/env
    echo "REDASH_DATABASE_URL=$REDASH_DATABASE_URL" >> $REDASH_BASE_PATH/env
}

create_directories
create_config
EOF

## 生成必要配置文件
chmod +x ./setup.sh && ./setup.sh
# docker-compose.yml
version: "2"
x-redash-service: &redash-service
  image: redash/redash:7.0.0.b18042
  depends_on:
    - postgres
    - redis
  env_file: /opt/redash/env
  restart: always
services:
  server:
    <<: *redash-service
    command: server
    ports:
      - "5000:5000"
    environment:
      REDASH_WEB_WORKERS: 4
  scheduler:
    <<: *redash-service
    command: scheduler
    environment:
      QUEUES: "celery"
      WORKERS_COUNT: 1
  scheduled_worker:
    <<: *redash-service
    command: worker
    environment:
      QUEUES: "scheduled_queries,schemas"
      WORKERS_COUNT: 1
  adhoc_worker:
    <<: *redash-service
    command: worker
    environment:
      QUEUES: "queries"
      WORKERS_COUNT: 2
  redis:
    image: redis:5.0-alpine
    restart: always
  postgres:
    image: postgres:9.5-alpine
    env_file: /opt/redash/env
    volumes:
      - /opt/redash/postgres-data:/var/lib/postgresql/data
    restart: always
  nginx:
    image: redash/nginx:latest
    ports:
      - "80:80"
    depends_on:
      - server
    links:
      - server:redash
    restart: always
## 配置数据库
sudo docker-compose run --rm server create_db
## 启动
sudo docker-compose up -d
## 查看
/opt/redash # docker-compose ps                                                                                                                             root@Test-Linux
          Name                         Command               State              Ports           
------------------------------------------------------------------------------------------------
redash_adhoc_worker_1       /app/bin/docker-entrypoint ...   Up      5000/tcp                   
redash_nginx_1              nginx -g daemon off;             Up      443/tcp, 0.0.0.0:80->80/tcp
redash_postgres_1           docker-entrypoint.sh postgres    Up      5432/tcp                   
redash_redis_1              docker-entrypoint.sh redis ...   Up      6379/tcp                   
redash_scheduled_worker_1   /app/bin/docker-entrypoint ...   Up      5000/tcp                   
redash_scheduler_1          /app/bin/docker-entrypoint ...   Up      5000/tcp                   
redash_server_1             /app/bin/docker-entrypoint ...   Up      0.0.0.0:5000->5000/tcp  

## 访问
http://ip

填写用户名,邮箱,密码,名称后即可进入界面

数据来源如下(没有excel)

posted @ 2021-03-23 17:58  哈喽哈喽111111  阅读(827)  评论(0编辑  收藏  举报