在这篇文章中,我们将带领您了解从本地主机应用程序连接到GoogleCloud上的MySQL数据库的全貌,同时,我们还将为您介绍有关GKEOFBizpod未连接到GoogleCloudSQL数据库、Go
在这篇文章中,我们将带领您了解从本地主机应用程序连接到 Google Cloud 上的 MySQL 数据库的全貌,同时,我们还将为您介绍有关GKE OFBiz pod 未连接到 Google Cloud SQL 数据库、Google API 的 Google OAuth 2.0 范围与 Google Cloud 上的 IAM 中的角色和权限有何不同? OAuth范围IAM遗产?、Google Cloud Code 的 Cloud Run 扩展将 Docker 镜像存储在 Cloud Storage 而不是 Artifact Registry、Google Cloud SQL 中哪些安全功能不适用于 Firebase 数据库?的知识,以帮助您更好地理解这个主题。
本文目录一览:- 从本地主机应用程序连接到 Google Cloud 上的 MySQL 数据库
- GKE OFBiz pod 未连接到 Google Cloud SQL 数据库
- Google API 的 Google OAuth 2.0 范围与 Google Cloud 上的 IAM 中的角色和权限有何不同? OAuth范围IAM遗产?
- Google Cloud Code 的 Cloud Run 扩展将 Docker 镜像存储在 Cloud Storage 而不是 Artifact Registry
- Google Cloud SQL 中哪些安全功能不适用于 Firebase 数据库?
从本地主机应用程序连接到 Google Cloud 上的 MySQL 数据库
如何解决从本地主机应用程序连接到 Google Cloud 上的 MySQL 数据库
我最近在 Google Cloud 上设置了一个 MysqL 数据库。我已将我的 IP 地址列入白名单,并且可以使用 MysqL Workbench 毫无问题地连接到它。
我正在开发一个 PHP 应用程序,它在 localhost:8000 上运行。当我连接到本地 MysqL 实例时一切正常,但是在尝试连接到 Google Cloud 实例时遇到了问题。
似乎正在建立连接(我故意尝试使用错误的主机名进行连接,并收到“没有这样的主机是已知的”错误)。使用 IP 地址:Google Cloud 实例的端口号,我遇到无法识别表的问题,我认为这意味着我已连接到主机,但无法正确获取架构。
我想知道这个问题是否是因为连接是从本地主机调用的,我需要在 Google Cloud 上设置一些东西来允许这个。
谁能告诉我
(1) 如果这很可能是问题所在,如果是,
(2) 如何在 Google 上允许从本地主机访问?
有关更多信息,我使用连接
pdo = new PDO($dsn,"root",<password>,$options);
哪里
$dsn = "MysqL:host=<ip-address>:<port>;dbname=<schema-name>;"
和
$options = [
PDO::ATTR_PERSISTENT => false,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::sqlSRV_ATTR_FETCHES_NUMERIC_TYPE => true,PDO::ATTR_STRINGIFY_FETCHES => false
];
以下在本地实例上运行良好:
$dsn = "MysqL:host=localhost:3306;dbname=<schema-name>;"
提前致谢!
解决方法
玩了一会后,我发现我的问题与我从本地主机调用数据库这一事实无关。事实上,这是因为 Google 平台对表名区分大小写,而我的本地版本的 MySQL 不区分大小写。
所以我的问题的答案是,这与在本地主机上运行应用程序无关。
GKE OFBiz pod 未连接到 Google Cloud SQL 数据库
如何解决GKE OFBiz pod 未连接到 Google Cloud SQL 数据库
按照 this tutorial 将 OFBiz 连接到 MysqL 数据库。
我正在尝试创建一个带有持久存储的 OFBiz 部署,新的 Pod 将在其中存储和检索 MysqL 中的数据。
用于 OFBiz pod 的 Dockerfile
FROM openjdk:8
RUN apt-get update && \\
apt-get install -y gradle unzip wget vim
RUN wget https://downloads.apache.org/ofbiz/apache-ofbiz-17.12.05.zip && \\
unzip apache-ofbiz-17.12.05
workdir apache-ofbiz-17.12.05
RUN gradle wrapper && \\
./gradlew cleanAll loadAll
# Allowing URL $URL
RUN sed -i -e ''s/host-headers-allowed=/host-headers-allowed=$URL,/g'' /apache-ofbiz-17.12.05/framework/security/config/security.properties
copY entityengine.xml /apache-ofbiz-17.12.05/framework/entity/config/
CMD ["/apache-ofbiz-17.12.05/gradlew","ofbiz"]
我在 GCP 上使用 OFBiz 在 GKE 上运行的 pod 中托管所有内容,并使用 Google Cloud sql 作为托管 MysqL 服务。我在 34.75.32.160 处设置了 Cloud sql,使用公共 IP。
初步 sql 命令 在启动 OFBiz 之前,我在我的数据库上运行了以下命令。
create database ofbiz;
create database ofbizolap;
create database ofbiztenant;
use MysqL;
select database();
create user ofbiz@localhost;
create user ofbizolap@localhost;
create user ofbiztenant@localhost;
update user set password=PASSWORD("FAKEPASSWORD") where User=''ofbiz'';
update user set password=PASSWORD("FAKEPASSWORD") where User=''ofbizolap'';
update user set password=PASSWORD("FAKEPASSWORD") where User=''ofbiztenant'';
grant all privileges on *.* to ''ofbiz''@localhost identified by ''ofbiz'';
grant all privileges on *.* to ''ofbizolap''@localhost identified by ''ofbizolap'';
grant all privileges on *.* to ''ofbiztenant''@localhost identified by ''ofbiztenant'';
OFBiz 配置与 entityengine.xml
ofbiz 的数据后端配置在文件 entityengine.xml
中,我已按以下方式配置了该文件:
数据源声明 我声明了三个不同的数据源 localMysqL
、localMysqLolap
和 localMysqLtenant
,每个数据源都通过 JDBC 连接到我的 Cloud sql 服务器。
<datasource name="localMysqL"
helper-field-type-name="MysqL"
check-on-start="true"
add-missing-on-start="true"
check-pks-on-start="false"
use-foreign-keys="true"
join-alias-view-columns="false"
drop-fk-use-foreign-key-keyword="true"
table-type="InnoDB"
character-set="utf8"
collate="utf8_general_ci">
<read-data reader-name="tenant"/>
<read-data reader-name="seed"/>
<read-data reader-name="seed-initial"/>
<read-data reader-name="demo"/>
<read-data reader-name="ext"/>
<read-data reader-name="ext-test"/>
<read-data reader-name="ext-demo"/>
<inline-jdbc
jdbc-driver="com.MysqL.jdbc.Driver"
jdbc-uri="jdbc:MysqL://34.75.32.160/ofbiz?autoReconnect=true&characterEncoding=UTF-8"
jdbc-username="ofbiz"
jdbc-password="<password>"
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"
time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MysqL
and had to set it to -1 in order to avoid this issue.
For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MysqLDataSource" isolation-level="Serializable"/> -->
</datasource>
<datasource name="localMysqLolap"
helper-field-type-name="MysqL"
check-on-start="true"
add-missing-on-start="true"
check-pks-on-start="false"
use-foreign-keys="true"
join-alias-view-columns="false"
drop-fk-use-foreign-key-keyword="true"
table-type="InnoDB"
character-set="utf8"
collate="utf8_general_ci">
<read-data reader-name="tenant"/>
<read-data reader-name="seed"/>
<read-data reader-name="seed-initial"/>
<read-data reader-name="demo"/>
<read-data reader-name="ext"/>
<read-data reader-name="ext-test"/>
<read-data reader-name="ext-demo"/>
<inline-jdbc
jdbc-driver="com.MysqL.jdbc.Driver"
jdbc-uri="jdbc:MysqL://34.75.32.160/ofbizolap?autoReconnect=true&characterEncoding=UTF-8"
jdbc-username="ofbizolap"
jdbc-password="<password>"
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"
time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MysqL
and had to set it to -1 in order to avoid this issue.
For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MysqLDataSource" isolation-level="Serializable"/> -->
</datasource>
<datasource name="localMysqLtenant"
helper-field-type-name="MysqL"
check-on-start="true"
add-missing-on-start="true"
check-pks-on-start="false"
use-foreign-keys="true"
join-alias-view-columns="false"
drop-fk-use-foreign-key-keyword="true"
table-type="InnoDB"
character-set="utf8"
collate="utf8_general_ci">
<read-data reader-name="tenant"/>
<read-data reader-name="seed"/>
<read-data reader-name="seed-initial"/>
<read-data reader-name="demo"/>
<read-data reader-name="ext"/>
<read-data reader-name="ext-test"/>
<read-data reader-name="ext-demo"/>
<inline-jdbc
jdbc-driver="com.MysqL.jdbc.Driver"
jdbc-uri="jdbc:MysqL://34.75.32.160/ofbiztenant?autoReconnect=true&characterEncoding=UTF-8"
jdbc-username="ofbiztenant"
jdbc-password="<password>"
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"
time-between-eviction-runs-millis="600000"/><!-- Please note that at least one person has experienced a problem with this value with MysqL
and had to set it to -1 in order to avoid this issue.
For more look at http://markmail.org/thread/5sivpykv7xkl66px and http://commons.apache.org/dbcp/configuration.html-->
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MysqLDataSource" isolation-level="Serializable"/> -->
</datasource>
委托人 委托人告诉 OFBiz 将哪个数据源用于哪些功能(在这种情况下:功能是 normal、olap 和租户)。 我们可以运行 OFBiz 的不同方式有一个条目:default
、default-no-eca
和 test
。
我在这里设置它以使用我在上面定义的 MysqL 数据源。
<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
<group-map group-name="org.apache.ofbiz" datasource-name="localMysqL"/>
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localMysqLolap"/>
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localsqltenant"/>
</delegator>
<!-- May be used when you create a service that manages many data for massive imports,this for performance reason or to escape functional cases -->
<delegator name="default-no-eca" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" entity-eca-enabled="false" distributed-cache-clear-enabled="false">
<group-map group-name="org.apache.ofbiz" datasource-name="localMysqL"/>
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localMysqLolap"/>
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localMysqLtenant"/>
</delegator>
<!-- Be sure that your default delegator (or the one you use) uses the same datasource for test. You must run "gradlew loadAll" before running "gradlew testIntegration" -->
<delegator name="test" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main">
<group-map group-name="org.apache.ofbiz" datasource-name="localMysqL"/>
<group-map group-name="org.apache.ofbiz.olap" datasource-name="localMysqLolap"/>
<group-map group-name="org.apache.ofbiz.tenant" datasource-name="localMysqLtenant"/>
</delegator>
错误 当我使用此配置运行 OFBiz 时,我收到以下 HTTP 500
错误:
java.lang.IllegalArgumentException: Could not get next sequenced ID for sequence name: Visit
org.apache.ofbiz.entity.GenericDelegator.getNextSeqId(GenericDelegator.java:2280)
org.apache.ofbiz.entity.GenericDelegator.getNextSeqId(GenericDelegator.java:2268)
org.apache.ofbiz.entity.GenericEntity.setNextSeqId(GenericEntity.java:657)
org.apache.ofbiz.entity.GenericDelegator.createSetNextSeqId(GenericDelegator.java:771)
org.apache.ofbiz.webapp.stats.VisitHandler.getVisit(VisitHandler.java:187)
org.apache.ofbiz.webapp.stats.VisitHandler.getVisitId(VisitHandler.java:100)
org.apache.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:686)
javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
org.apache.ofbiz.webapp.control.SameSiteFilter.doFilter(SameSiteFilter.java:44)
org.apache.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:191)
org.apache.ofbiz.webapp.control.ControlFilter.doFilter(ControlFilter.java:157)
org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
Kubernetes 错误日志 使用 kubectl logs $POD,这是显示的错误之一。所有的错误似乎都与 jdbc 驱动程序有关。
2021-03-27 23:33:50,408 |OFBiz-JobPoller |DBCPConnectionFactory |E| null
java.lang.classNotFoundException: com.MysqL.jdbc.Driver
at java.net.urlclassloader.findClass(urlclassloader.java:382) ~[?:1.8.0_282]
at java.lang.classLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_282]
at java.lang.classLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_282]
at java.lang.class.forName0(Native Method) ~[?:1.8.0_282]
at java.lang.class.forName(Class.java:348) ~[?:1.8.0_282]
at org.apache.ofbiz.entity.connection.DBCPConnectionFactory.getConnection(DBCPConnectionFactory.java:90) [ofbiz.jar:?]
at org.apache.ofbiz.entity.transaction.GeronimoTransactionFactory.getConnection(GeronimoTransactionFactory.java:79) [ofbiz.jar:?]
at org.apache.ofbiz.entity.jdbc.sqlProcessor.getConnection(sqlProcessor.java:261) [ofbiz.jar:?]
at org.apache.ofbiz.entity.jdbc.sqlProcessor.prepareStatement(sqlProcessor.java:367) [ofbiz.jar:?]
at org.apache.ofbiz.entity.datasource.GenericDAO.selectCountByCondition(GenericDAO.java:1049) [ofbiz.jar:?]
at org.apache.ofbiz.entity.datasource.GenericHelperDAO.findCountByCondition(GenericHelperDAO.java:157) [ofbiz.jar:?]
at org.apache.ofbiz.entity.GenericDelegator.findCountByCondition(GenericDelegator.java:1694) [ofbiz.jar:?]
at org.apache.ofbiz.entity.GenericDelegator.findCountByCondition(GenericDelegator.java:1653) [ofbiz.jar:?]
at org.apache.ofbiz.service.job.JobManager.isAvailable(JobManager.java:154) [ofbiz.jar:?]
at org.apache.ofbiz.service.job.JobPoller$JobManagerPoller.run(JobPoller.java:223) [ofbiz.jar:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_282]```
解决方法
${ofbiz install dir}/framework/entity/lib/jdbc
;在那里更换旧的或不正确版本的驱动程序
用于 MySQL 的 JDBC 驱动程序(连接器/J):https://www.mysql.com/products/connector/
在 https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=7045252#ApacheOFBizTechnicalProductionSetupGuide-DatabaseSetup 阅读更多
Google API 的 Google OAuth 2.0 范围与 Google Cloud 上的 IAM 中的角色和权限有何不同? OAuth范围IAM遗产?
如何解决Google API 的 Google OAuth 2.0 范围与 Google Cloud 上的 IAM 中的角色和权限有何不同? OAuth范围IAM遗产?
我正在尝试解读来自 Error: Could not load the default credentials. context: firebase login:ci AND firebase auth:export 的以下错误消息中“范围”的含义:
[2021-04-27T20:48:23.188Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2021-04-27T20:48:26.208Z] Error: Could not load the default credentials. browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:160:19)
at processticksAndRejections (internal/process/task_queues.js:97:5)
at runNextTicks (internal/process/task_queues.js:66:3)
at listOnTimeout (internal/timers.js:518:9)
at processtimers (internal/timers.js:492:7)
at async GoogleAuth.getClient (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17)
at async GoogleAuth.getAccesstoken (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:524:24)
Error: An unexpected error has occurred.
如果我了解什么是“范围”,我可能会知道在哪里设置它们。到目前为止,我只找到了一个地方可以在 IAM 中为我的用户设置角色和权限。
以下是我能找到的定义:
角色和权限 (source)
角色包含一组允许您执行 对 GCP 资源的具体操作。制作权限 对成员可用,包括用户、组和服务帐户, 您向成员授予角色。
范围(source、source)
访问范围是为您的用户指定权限的传统方法 实例。他们定义了请求中使用的默认 OAuth 范围 gcloud 工具或客户端库。
当我尝试使用由 firebase --debug auth:export
生成并使用 firebase use --token
应用到我的脚本中的 OAuth 令牌运行 firebase login:ci
时出现错误消息。 OAuth 令牌是使用拥有我的 Firebase 项目的 Google 用户 ID 生成的。该用户在 Google Cloud IAM 页面(即 https://console.cloud.google.com/iam-admin/iam)上具有“所有者”角色。
当 Google Cloud IAM 页面只允许您设置角色和权限时,如何为我的 Google 用户 ID 设置所需的范围 ?
解决方法
我不熟悉 Firebase,但我知道这一点:
Error: Could not load the default credentials
这告诉您没有找到(应用程序)默认凭据。您可以通过执行以下操作使用 Google 用户帐户生成默认凭据:
gcloud auth application-default login
还有其他选择。我写了一个完整的blog post on application default credentials,你可能会觉得有趣。
为了回答你的另一个问题,恐怕我会有点罗嗦...
OAuth
Scopes 是 OAuth 的一个术语;范围并非特定于 GCP 甚至 Google。 OAuth 是一种用于授权的协议,在互联网上得到广泛使用。完全理解 OAuth 并非易事。
OAuth 关注的“各方”是:
- 资源(您尝试访问的 GCP 服务),
- 最终用户(你,迈克尔)
- 授权服务器(Google 帐户服务)和
- 客户端(在本例中为 firebase CLI;您要代表您执行的程序)。
OAuth 关注的问题如下:作为最终用户,您有权对资源采取行动。您希望客户能够代表您对资源采取行动。为此,您需要使用授权服务器登录,并为客户端获取一个秘密令牌; OAuth 规范中详细定义了如何具体执行此操作。该资源将拥有此类令牌的任何人识别为代表最终用户“发言”。通过将令牌交给客户,您将您的最终用户权限“委托”给了客户。
范围
无论如何...范围从哪里进来?在上述交互中,您不一定要将您在资源上的所有权限委托给客户端。因此,您可以将“范围”绑定到令牌。范围告诉资源,令牌持有者可能不会代表最终用户执行所有操作,而只能执行某些操作。 OAuth 协议没有定义特定范围的含义。范围是自由格式的字符串,它是应该知道如何解释它们的资源。
IAM
另一方面,IAM 定义了最终用户对资源的权限,也就是说,它定义了 Google 帐户在处理 GCP 资源时可以执行的操作。自然,您的 Google 帐户不能将授权委托给它本身没有的客户,即使它可以创建范围非常广泛的令牌。
如果 Google 收到启动 GCE 实例的请求,它会首先检查该请求是否由具有足够范围的有效、可信令牌签名。如果检查通过,Google 会检查“支持”令牌的最终用户是否确实有权使用 IAM 执行请求的操作。
在上面的示例中:您是所有者,因此您拥有大量 IAM 权限。但是,如果您生成的令牌不包含适当的范围,则该令牌不带有该权限,firebase 向 GCP 发送的请求将不会通过第一次检查。
遗产?
范围的概念不是旧的,而是 GCP 使用范围来调节进程权限的方式。
过去,GCP 上的进程通常使用具有非常广泛 (IAM) 权限的通用身份运行,例如默认计算帐户。进程的权限受到为它们生成的令牌的范围限制。
IAM 更强大,可以在更细粒度的级别定义为范围。如今,我们为不同的进程定义具有最小权限的自定义身份。给定适当的 IAM 权限,我们可以简单地创建具有非常广泛范围的令牌,例如 https://www.googleapis.com/auth/cloud-platform
。
Google Cloud Code 的 Cloud Run 扩展将 Docker 镜像存储在 Cloud Storage 而不是 Artifact Registry
如何解决Google Cloud Code 的 Cloud Run 扩展将 Docker 镜像存储在 Cloud Storage 而不是 Artifact Registry?
为什么当我使用 Visual Studio Code 扩展“Cloud Code”来部署 Cloud Run 服务时,它似乎将图像内容存储在 Cloud Storage(通过 Container Registry)中。
我可以让它将图像存储在 Google Cloud Artifact Registry 中吗?
解决方法
我刚刚尝试了这个场景,它对我有用!遵循这些步骤应该可以帮助您前进。
- 在 https://console.cloud.google.com/artifacts 创建工件注册表存储库,并在您的客户端上设置 docker auth 以使用 gcloud 对存储库进行身份验证。您可以找到执行此操作的详细步骤 here。
- 在 Cloud Code 中部署到 Cloud Run 时,您会发现它默认使用 Container Registry 存储库作为“容器映像 URL”,但您可以在此处轻松使用工件注册表存储库。在这里,您可以粘贴您在上一步中创建的存储库名称,并附加一个图像名称。 Here''s a screenshot 我刚刚测试的示例。
Google Cloud SQL 中哪些安全功能不适用于 Firebase 数据库?
如何解决Google Cloud SQL 中哪些安全功能不适用于 Firebase 数据库?
我正在尝试研究 Firebase 数据库是否具有与自定义设置的 Google Cloud 数据库(Nosql 或 sql)相同的一组安全功能。
如果没有,google cloud sql 提供的额外功能是什么?我拥有的列表(可能是错误的)是:
- db 密码保护,
- 从私有 IP 运行数据库(连接到 K8s),
- 借助可通过后端访问的数据库,您可以编写任何类型的安全规则,而不仅仅是基于用户的规则。
关于从本地主机应用程序连接到 Google Cloud 上的 MySQL 数据库的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于GKE OFBiz pod 未连接到 Google Cloud SQL 数据库、Google API 的 Google OAuth 2.0 范围与 Google Cloud 上的 IAM 中的角色和权限有何不同? OAuth范围IAM遗产?、Google Cloud Code 的 Cloud Run 扩展将 Docker 镜像存储在 Cloud Storage 而不是 Artifact Registry、Google Cloud SQL 中哪些安全功能不适用于 Firebase 数据库?的相关信息,请在本站寻找。
本文标签: