Metabase on Google App Engine

浪尽此生 提交于 2019-12-23 09:18:12

问题


I'm trying to set up Metabase on a gcloud engine using Google Cloud SQL (MySQL).

I've got it running using this git and this app.yaml:

runtime: custom
env: flex

# Metabase does not support horizontal scaling
#   https://github.com/metabase/metabase/issues/2754
#   https://cloud.google.com/appengine/docs/flexible/java/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1

env_variables:
 # MB_JETTY_PORT: 8080
  MB_DB_TYPE: mysql
  MB_DB_DBNAME: [db_name]
 # MB_DB_PORT: 5432
  MB_DB_USER: [db_user]
  MB_DB_PASS: [db_password]
 # MB_DB_HOST: 127.0.0.1
  CLOUD_SQL_INSTANCE: [project-id]:[location]:[instance-id]

I have 2 issues:

  1. The Metabase fails in connecting to the Cloud SQL - the Cloud SQL is part of the same project and App Engine is authorized.

  2. After I create my admin user in Metabase, I am only able to login for a few seconds (and only sometimes), but it keeps throwing me to either /setup or /auth/login saying the password doesn't match (when it does).

I hope someone can help - thank you!


回答1:


So, we just got metabase running in Google App Engine with a Cloud SQL instance running PostgreSQL and these are the steps we went through.

First, create a Dockerfile:

FROM gcr.io/google-appengine/openjdk:8

EXPOSE 8080

ENV JAVA_OPTS "-XX:+IgnoreUnrecognizedVMOptions -Dfile.encoding=UTF-8 --add-opens=java.base/java.net=ALL-UNNAMED --add-modules=java.xml.bind"
ENV JAVA_TOOL_OPTIONS "-Xmx1g"

ADD https://downloads.metabase.com/enterprise/v1.1.6/metabase.jar $APP_DESTINATION

We tried pushing the memory further down, but 1 GB seemed to be the sweet spot. On to the app.yaml:

runtime: custom
env: flex

manual_scaling:
  instances: 1

resources:
  cpu: 1
  memory_gb: 1
  disk_size_gb: 10

readiness_check:
  path: "/api/health"
  check_interval_sec: 5
  timeout_sec: 5
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 600

beta_settings:
  cloud_sql_instances: <Instance-Connection-Name>=tcp:5432

env_variables:
  MB_DB_DBNAME: 'metabase'
  MB_DB_TYPE: 'postgres'
  MB_DB_HOST: '172.17.0.1'
  MB_DB_PORT: '5432'
  MB_DB_USER: '<username>'
  MB_DB_PASS: '<password>'
  MB_JETTY_PORT: '8080'

Note the beta_settings field at the bottom, which handles what akilesh raj was doing manually. Also, the trailing =tcp:5432 is required, since metabase does not support unix sockets yet.

Relevant documentation can be found here.




回答2:


Although I am not sure of the reason, I think authorizing the service account of App engine is not enough for accessing cloud SQL.

In order to authorize your App to access your Cloud SQL you can do either of both methods:

  1. Within the app.yaml file, configure an environment variable pointing to a a service account key file with a correct authorization configuration to Cloud SQL :

    env_variables: GOOGLE_APPLICATION_CREDENTIALS=[YOURKEYFILE].json

  2. Your code executes a fetch of an authorized service account key from a bucket, and loads it afterwards with the help of the Cloud storage Client library. Seeing your runtime is custom, the pseudocode which would be translated into the code you use is the following:

    .....




回答3:


It is better to use the Cloud proxy to connect to the SQL instances. This way you do not have to authorize the instances in CloudSQL every time there is a new instance. More on CloudProxy here

As for setting up Metabase in the Google App Engine, I am including the app.yaml and Dockerfile below.

The app.yaml file,

runtime: custom
env: flex

manual_scaling:
instances: 1

env variables:
    MB_DB_TYPE: mysql
    MB_DB_DBNAME: metabase
    MB_DB_PORT: 3306
    MB_DB_USER: root
    MB_DB_PASS: password
    MB_DB_HOST: 127.0.0.1
    METABASE_SQL_INSTANCE: instance_name

The Dockerfile,

FROM gcr.io/google-appengine/openjdk:8

# Set locale to UTF-8
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# Install CloudProxy
ADD https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 ./cloud_sql_proxy
RUN chmod +x ./cloud_sql_proxy

#Download the latest version of Metabase
ADD http://downloads.metabase.com/v0.21.1/metabase.jar ./metabase.jar

CMD nohup ./cloud_sql_proxy -instances=$METABASE_SQL_INSTANCE=tcp:$MB_DB_PORT & java -jar /startup/metabase.jar


来源:https://stackoverflow.com/questions/49778760/metabase-on-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!