"Connection refused"尝试从部署在App Engine Standard上的Symfony应用程序连接到Cloud SQL时出现



我已经将Symfony演示应用程序配置从SQLite更改为MySQL。在本地,它对我来说很好,但如果我试图在谷歌应用引擎标准环境中部署它,它就不起作用。

如果数据库在Google Cloud SQL中,我不清楚应该如何放置连接字符串。目前,该项目的.env文件包含以下内容:

DATABASE_URL="mysql://dbname=THEDATABASENAME;unix_socket=PROJECTNAME:ZONE:INSTANCENAME"

我不确定它是否正确,或者是否缺少什么,或者我是否需要在Symfony或谷歌云控制台中配置其他东西。

当我部署并浏览到该网站时,我会出现错误500。

错误日志显示:

2022-11-02 14:41:00 default[20221102t151407]  "GET / HTTP/1.1" 302
2022-11-02 14:41:01 default[20221102t151407]  nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3
2022-11-02 14:41:03 default[20221102t151407]  "GET /es HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/app.c5bd2611.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/runtime.725dd7e0.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/755.5a8586e9.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/95.1ed6b32f.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/app.17316efd.css HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/fonts/fa-solid-900.1551f4f6.woff2 HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/fonts/fa-regular-400.7a333762.woff2 HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/95.22c66ae4.css HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/823.168b723b.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/31.46aa6824.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/fonts/lato-bold.21b3848a.woff2 HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407]  "GET /build/fonts/lato-normal.75614cfc.woff2 HTTP/1.1" 200
2022-11-02 14:41:08 default[20221102t151407]  "GET /es/blog/ HTTP/1.1" 500
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Matched route "blog_index".","context":{"route":"blog_index","route_parameters":{"_route":"blog_index","page":"1","_format":"html","_controller":"App\Controller\BlogController::index","_locale":"es"},"request_uri":"https://testMYPROJECT.uc.r.appspot.com/es/blog/","method":"GET"},"level":200,"level_name":"INFO","channel":"request","datetime":"2022-11-02T14:41:08.499913+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Checking for authenticator support.","context":{"firewall_name":"main","authenticators":1},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2022-11-02T14:41:08.500353+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Checking support on authenticator.","context":{"firewall_name":"main","authenticator":"Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2022-11-02T14:41:08.500361+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Authenticator does not support the request.","context":{"firewall_name":"main","authenticator":"Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2022-11-02T14:41:08.500367+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key "App%5CController%5CBlogController" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"App%5CController%5CBlogController","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\Component\Cache\Adapter\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:08.528050+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key "ea12799f***********" of type Doctrine\ORM\Query\ParserResult: fopen(/workspace/var/cache/prod/pools/system/16ctGUzn1Q/774b86986a15): Failed to open stream: No such file or directory","context":{"key":"ea12799f**********","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/16ctGU**********): Failed to open stream: No such file or directory","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\Component\Cache\Adapter\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.092063+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused" at /workspace/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php line 101","context":{"exception":{"class":"Doctrine\DBAL\Exception\ConnectionException","message":"An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused","code":2002,"file":"/workspace/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:101","previous":{"class":"Doctrine\DBAL\Driver\PDO\Exception","message":"SQLSTATE[HY000] [2002] Connection refused","code":2002,"file":"/workspace/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:28","previous":{"class":"PDOException","message":"SQLSTATE[HY000] [2002] Connection refused","code":2002,"file":"/workspace/vendor/doctrine/dbal/src/Driver/PDO/MySQL/Driver.php:28"}}}},"level":500,"level_name":"CRITICAL","chann"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "el":"request","datetime":"2022-11-02T14:41:09.173672+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key "Symfony%5CComponent%5CHttpKernel%5CController%5CErrorController" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony%5CComponent%5CHttpKernel%5CController%5CErrorController","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\Component\Cache\Adapter\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.191792+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key "Symfony%5CComponent%5CHttpKernel%5CController%5CErrorController%23__invoke" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony%5CComponent%5CHttpKernel%5CController%5CErrorController%23__invoke","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\Component\Cache\Adapter\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.192185+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key "Symfony%5CBundle%5CFrameworkBundle%5CController%5CTemplateController" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony%5CBundle%5CFrameworkBundle%5CController%5CTemplateController","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\Component\Cache\Adapter\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.700565+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key "Symfony%5CBundle%5CFrameworkBundle%5CController%5CTemplateController%23templateAction" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony%5CBundle%5CFrameworkBundle%5CController%5CTemplateController%23templateAction","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\Component\Cache\Adapter\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.701047+00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407]  "GET /build/fonts/fa-brands-400.d878b0a6.woff2 HTTP/1.1" 200
2022-11-02 14:41:09 default[20221102t151407]  "GET /build/css/app.4aa95248.css HTTP/1.1" 404

用于连接到云SQL的谷歌应用程序引擎(标准(文档注意:

正确配置后,您可以通过以下路径将服务连接到云SQL实例在环境文件系统上访问的Unix域套接字:/cloudsql/instance_CONNECTION_NAME

您上面的unix_socket值应该是:

/cloudsql/project:region:instance-id

而不仅仅是

project:region:instance-id

还要注意,它应该是区域,而不是区域,即northamerica-northeast1而不是northamerica-northeast1-a。如果有疑问,您可以验证连接名称:

  • 在控制台中的目标SQL实例的概览页面上
  • 通过运行gcloud sql instances describe INSTANCE_NAME

最后,您可能还需要验证:

  • 应用程序引擎服务的服务帐户在托管SQL实例的项目和托管应用程序引擎的项目中具有Cloud SQL Client角色
  • 在承载SQL实例的项目和承载应用程序引擎服务的项目上启用云SQL管理API(sqladmin.googleapis.com

相关内容

最新更新