Redash Docker 安装问题:sqlalchemy.exc.OperationalError: (psycopg2.OperationalError)

问题描述 投票:0回答:2

我正在尝试在 Ubuntu 20.04.1 上安装 Redash

  1. 我使用的是这种安装方法:https://github.com/getredash/setup
  2. 我下载了文件
  3. 我 cd 进入该文件夹
  4. 我运行“sudo ./setup.sh”
  5. 我收到以下错误:
Traceback (most recent call last):
File “/app/manage.py”, line 9, in
manager()
File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python2.7/site-packages/flask/cli.py”, line 380, in main
return AppGroup.main(self, *args, **kwargs)
File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/usr/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/usr/local/lib/python2.7/site-packages/flask/cli.py”, line 257, in decorator
return __ctx.invoke(f, *args, **kwargs)
File “/usr/local/lib/python2.7/site-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/app/redash/cli/database.py”, line 31, in create_tables
db.create_all()
File “/usr/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py”, line 963, in create_all
self._execute_for_all_tables(app, bind, ‘create_all’)
File “/usr/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py”, line 955, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/schema.py”, line 4005, in create_all
tables=tables)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py”, line 1939, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn:
File “/usr/local/lib/python2.7/contextlib.py”, line 17, in enter
return self.gen.next()
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py”, line 1932, in _optional_conn_ctx_manager
with self.contextual_connect() as conn:
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py”, line 2123, in contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py”, line 2162, in _wrap_pool_connect
e, dialect, self)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py”, line 1476, in _handle_dbapi_exception_noconnection
exc_info
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py”, line 265, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py”, line 2158, in _wrap_pool_connect
return fn()
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 400, in connect
return _ConnectionFairy._checkout(self)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 788, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 529, in checkout
rec = pool._do_get()
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 1193, in _do_get
self._dec_overflow()
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py”, line 66, in exit
compat.reraise(exc_type, exc_value, exc_tb)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 1190, in _do_get
return self._create_connection()
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 347, in _create_connection
return _ConnectionRecord(self)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 474, in init
self.__connect(first_connect_check=True)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/pool.py”, line 671, in __connect
connection = pool._invoke_creator(self)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py”, line 106, in connect
return dialect.connect(*cargs, **cparams)
File “/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py”, line 412, in connect
return self.dbapi.connect(*cargs, **cparams)
File “/usr/local/lib/python2.7/site-packages/psycopg2/init.py”, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: password authentication failed for user “postgres”
(Background on this error at: http://sqlalche.me/e/e3q8)

显然与 psycopg2 有关,它试图连接到 SQL 服务器。不知道如何解决它,谷歌搜索也没有帮助。

奇怪的是,当我第一次这样做时,这个完全相同的方法对我来说效果很好。由于某些奇怪的原因,我想要全新安装,并用 prune 清理了 docker 中的所有内容。然而它不起作用。

有什么建议吗?

以下是 setup.sh 中的代码

#!/usr/bin/env bash
# This script setups dockerized Redash on Ubuntu 18.04.
set -eu

REDASH_BASE_PATH=/opt/redash

install_docker(){
    # Install Docker
    export DEBIAN_FRONTEND=noninteractive
    sudo apt-get -qqy update
    DEBIAN_FRONTEND=noninteractive sudo -E apt-get -qqy -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade 
    sudo apt-get -yy install apt-transport-https ca-certificates curl software-properties-common wget pwgen
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update && sudo apt-get -y install docker-ce

    # Install Docker Compose
    sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose

    # Allow current user to run Docker commands
    sudo usermod -aG docker $USER
}

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
}

setup_compose() {
    REQUESTED_CHANNEL=stable
    LATEST_VERSION=`curl -s "https://version.redash.io/api/releases?channel=$REQUESTED_CHANNEL"  | json_pp  | grep "docker_image" | head -n 1 | awk 'BEGIN{FS=":"}{print $3}' | awk 'BEGIN{FS="\""}{print $1}'`

    cd $REDASH_BASE_PATH
    GIT_BRANCH="${REDASH_BRANCH:-master}" # Default branch/version to master if not specified in REDASH_BRANCH env var
    wget https://raw.githubusercontent.com/getredash/setup/${GIT_BRANCH}/data/docker-compose.yml
    sed -ri "s/image: redash\/redash:([A-Za-z0-9.-]*)/image: redash\/redash:$LATEST_VERSION/" docker-compose.yml
    echo "export COMPOSE_PROJECT_NAME=redash" >> ~/.profile
    echo "export COMPOSE_FILE=/opt/redash/docker-compose.yml" >> ~/.profile
    export COMPOSE_PROJECT_NAME=redash
    export COMPOSE_FILE=/opt/redash/docker-compose.yml
    sudo docker-compose run --rm server create_db
    sudo docker-compose up -d
}

install_docker
create_directories
create_config
setup_compose

还有 docker-compose.yml

version: "2"
x-redash-service: &redash-service
  image: redash/redash:8.0.0.b32245
  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.6-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
linux docker installation psycopg2 redash
2个回答
0
投票

跑步

docker-compose run --rm server create_db
后尝试
docker-compose up -d

redash % docker-compose up -d
Docker Compose is now in the Docker CLI, try `docker compose up`

Creating network "redash_default" with the default driver
Creating redash_postgres_1 ... done
Creating redash_redis_1    ... done
Creating redash_server_1   ... done
Creating redash_worker_1    ... done
Creating redash_scheduler_1 ... done
redash % docker-compose run --rm server create_db
Creating redash_server_run ... done
[2021-11-03 14:49:12,282][PID:1][INFO][alembic.runtime.migration] Context impl PostgresqlImpl.
[2021-11-03 14:49:12,282][PID:1][INFO][alembic.runtime.migration] Will assume transactional DDL.
[2021-11-03 14:49:12,353][PID:1][INFO][alembic.runtime.migration] Running stamp_revision  -> 89bc7873a3e0
redash % 

以下卷曲结果显示的是设置网页:

% curl --verbose http://localhost:5000/setup
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 5000 (#0)
> GET /setup HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.64.1
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 2808
< X-Frame-Options: deny
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'; font-src 'self' data:; img-src 'self' http: https: data: blob:; object-src 'none'; frame-ancestors 'none'; frame-src redash.io;  
< X-Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'; font-src 'self' data:; img-src 'self' http: https: data: blob:; object-src 'none'; frame-ancestors 'none'; frame-src redash.io;  
< Referrer-Policy: strict-origin-when-cross-origin
< Set-Cookie: csrf_token=IjMxMWFlZWNjYTMwNDQ1YjA4MmM2MGVmZmU4OGYzZjhhNWUyNDNjYTQi.YYK1Cg.gcRo-T2uBFdn2SicRGZbjlA5nEw; Path=/
< Vary: Cookie
< Set-Cookie: session=eyJfcGVybWFuZW50Ijp0cnVlLCJjc3JmX3Rva2VuIjoiMzExYWVlY2NhMzA0NDViMDgyYzYwZWZmZTg4ZjNmOGE1ZTI0M2NhNCJ9.YYK1Cg.7EuH8tslclwcW5nvW8_0k0xi4Aw; Expires=Wed, 03-Nov-2021 22:12:58 GMT; HttpOnly; Path=/
< Server: Werkzeug/0.16.1 Python/3.7.12
< Date: Wed, 03 Nov 2021 16:12:58 GMT
< 
<!DOCTYPE html>
<html class="no-js">
<head>
  <title>Redash Initial Setup</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <link rel="stylesheet" href="/static/server.css">

  <link rel="icon" type="image/png" sizes="32x32" href="/static/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="96x96" href="/static/images/favicon-96x96.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/static/images/favicon-16x16.png">
  
</head>
<body class="d-flex flex-column justify-content-center align-items-center signed-out">

  <div>
    <div class="header">
      <div class="text-center m-b-15">
        <a href="/"><img src="/static/images/redash_icon_small.png"></a>
      </div>
      
        <h3 class="text-center m-t-0 m-b-25">Redash Initial Setup</h3>
      
    </div>
    
<div class="fixed-width-page">
  <div class="bg-white tiled">
    <h4 class="m-t-0">Welcome to Redash!</h4>
    <div>Before you can use your instance, you need to do a quick setup.</div>


    <form role="form" method="post" name="create_account">
      <input type="hidden" name="csrf_token" value="IjMxMWFlZWNjYTMwNDQ1YjA4MmM2MGVmZmU4OGYzZjhhNWUyNDNjYTQi.YYK1Cg.gcRo-T2uBFdn2SicRGZbjlA5nEw"/>
      <h4 class="m-t-25">Admin User</h4>
      <div class="form-group ">
    <label for="name">Name</label>
    <input class="form-control" id="name" name="name" required type="text" value="">
    
    
  </div>
      <div class="form-group ">
    <label for="email">Email Address</label>
    <input class="form-control" id="email" name="email" type="email" value="">
    
    
  </div>
      <div class="form-group ">
    <label for="password">Password</label>
    <input class="form-control" id="password" name="password" type="password" value="">
    
    
  </div>

      <div class="checkbox">
        <label>
          <input checked id="security_notifications" name="security_notifications" type="checkbox" value="y">
          Subscribe to Security Notifications
        </label>
      </div>

      <div class="checkbox">
        <label>
          <input checked id="newsletter" name="newsletter" type="checkbox" value="y">
          Subscribe to newsletter (version updates, no more than once a month)
        </label>
      </div>

      <h4 class="m-t-25">General</h4>

      <div class="form-group ">
    <label for="org_name">Organization Name</label>
    <input class="form-control" id="org_name" name="org_name" required type="text" value="">
    
        <p class="help-block">Used in email notifications and the UI.</p>
    
    
  </div>

      <button type="submit" class="btn btn-primary btn-block m-t-25">Setup</button>
    </form>
  </div>
</div>

  </div>





</body>
* Closing connection 0
</html>

0
投票

就我而言,这是因为我多次重新运行设置。至少在这种情况下,您可以尝试:

切换到 redash-dir

cd /opt/redash/

关闭当前正在运行的东西

docker-compose down
docker-compose rm -sfv postgres

删除 postgres-data 和配置(应该没问题,因为应用程序尚未运行)

rm -r postgres-data/

重新启动:

docker-compose up -d
docker-compose run --rm  server create_db

最终应该带你去

[+] Creating 2/0
 ✔ Container redash-redis-1     Running                                                                                                                                                                                                                                                0.0s 
 ✔ Container redash-postgres-1  Running                                                                                                                                                                                                                                                0.0s 
[2023-08-09 10:05:26,891][PID:1][INFO][alembic.runtime.migration] Context impl PostgresqlImpl.
[2023-08-09 10:05:26,892][PID:1][INFO][alembic.runtime.migration] Will assume transactional DDL.
[2023-08-09 10:05:26,951][PID:1][INFO][alembic.runtime.migration] Running stamp_revision  -> e5c7a4e2df4d

您可以使用

检查当前的配置参数
cat /opt/redash/env
© www.soinside.com 2019 - 2024. All rights reserved.