LoginSignup
0
1

More than 3 years have passed since last update.

GCEに起動したredashでpythonを利用できるようにするまで

Last updated at Posted at 2021-04-27

GCEで起動

gcloud compute images create "redash-8-0-0" --source-uri gs://redash-images/redash.8.0.0-b32245-1.tar.gz
gcloud compute instances create redash --image redash-8-0-0  --zone asia-northeast1-a

GCEでHTTPアクセスを許可

VM インスタンスの詳細 > 編集 > HTTPトラフィックを許可する

(ここまででIPにアクセスするとredashが開きます。)

pythonの設定

サーバーにSSHして、以下を実行
(/opt/redashdocker-compose.ymlやenvファイルが配置されています)

sudo -s
cd /opt/redash
echo 'REDASH_ADDITIONAL_QUERY_RUNNERS=redash.query_runner.python' >> env
docker-compose up -d

以上でpythonを利用できる状態になります。

Googleアカウントでのログイン

※ DNSでredashのIPにドメインを割り当てておく必要があります

以下の設定でGoogleログインができるようになります。

cd /opt/redash
# 上記で作成したID/SECRETをenvに書き込んでrestart
echo 'REDASH_GOOGLE_CLIENT_ID=XXX' >> env
echo 'REDASH_GOOGLE_CLIENT_SECRET=XXX' >> env
docker-compose up -d server

スクリーンショット 2021-05-12 14.57.10.png

許可するアカウントのドメイン指定

setting の Allowed Google Apps Domains で指定します。
例えばここに example.com を指定すると user@example.com というようなexample.comのgoogleアカウントはログインできるようになります。
初回ログイン時に、redashユーザーがdefaultグループで新規に作成されます。

スクリーンショット 2021-05-12 22.47.46.png

その他

python外部モジュールの追加

  1. 以下コマンドでworkerにインストール
  2. データソースのModules to import prior to running the scriptにカンマ区切りで追記(e.g. json,urllib,sys)
# 開発環境
docker-compose exec worker pip install {{package}} 
docker-compose restart 

# GCE環境
docker-compose exec adhoc_worker pip install {{package}} --user
docker-compose exec scheduled_worker pip install {{package}} --user 
docker-compose restart 

データのバックアップ、リストア

backup

docker-compose exec postgres pg_dump -U postgres > backup_redash_postgres.sql

restore

cat ~/backup_redash_postgres.sql | docker exec -i redash_postgres_1 psql -U postgres

localからのファイルアップロード

ブラウザからのsshでファイルをuploadできます

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1