2

最近在尝试升级在云运行服务中运行craft cms 的docker 文件的php 版本时,我开始收到CloudSQL 连接错误。

日志示例。

2019-08-08T06:58:25.612096Z POST200 474 B 38 ms Chrome 75 /index.php?p=mangomin/actions/install/validate-db
2019-08-08T07:00:12.134410Z CloudSQL connection failed. Please see https://cloud.google.com/functions/docs/sql#troubleshooting for additional details: Post https://www.googleapis.com/sql/v1beta4/projects/c3gatsby-workflow-420fc457/instances/master-sql-f47f6b/createEphemeral?alt=json&prettyPrint=false: context deadline exceeded
2019-08-08T07:00:12.141939Z 169.254.8.129 - - [08/Aug/2019:07:00:02 +0000] "GET / HTTP/1.1" 503 52611 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
2019-08-08T07:00:12.144019Z GET503 51.4 KB 10 s Chrome 75 / 
2019-08-08T07:01:34.189448Z CloudSQL connection failed. Please see https://cloud.google.com/functions/docs/sql#troubleshooting for additional details: Post https://www.googleapis.com/sql/v1beta4/projects/c3gatsby-workflow-420fc457/instances/master-sql-f47f6b/createEphemeral?alt=json&prettyPrint=false: context deadline exceeded
2019-08-08T07:01:34.200976Z GET503 51.4 KB 10 s Chrome 75 / 

这开始发生在今天早上“2019 年 8 月 8 日”。最初我以为只是我升级的 php 版本与 unix 套接字或类似版本不兼容,所以我降级了。那没有用。所以我继续回溯到昨天的修订版(相同的 env 和 docker sha)问题仍然存在,然后我回溯到一个稳定的 docker 版本,我知道它正在开发一个姊妹云运行服务。没有骰子。

简而言之,我尝试更新的唯一内容是 docker 文件及其构建方式。(尝试启用 opcache,我发现它可以在本地工作以加快请求速度)旧

FROM php:7.1-apache

# Enable Reqrite and Headers for .htaccess
RUN a2enmod rewrite
RUN a2enmod headers

# Ensure UTF-8
RUN echo "AddDefaultCharset UTF-8" > /var/www/html/.htaccess

# Install linux dependencies
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
  && apt-get update --fix-missing \
  && apt-get install -y ssl-cert libmagickwand-dev libpq-dev zlib1g \
  && rm -rf /var/lib/apt/lists/*

# Install imagick
RUN pecl install imagick-3.4.3

# Install php extentions for docker
RUN docker-php-ext-enable imagick \
  && docker-php-ext-install pdo pdo_mysql zip

# Enable SSL apache2
RUN a2ensite default-ssl \
  && a2enmod ssl

# Replace the default served file to /web
RUN sed -i 's%/var/www/html%/var/www/html/web%g' /etc/apache2/sites-enabled/*.conf

# Use the PORT environment variable in Apache configuration files.
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf

# Replace with production mode
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Up the upload file size limit, memory limit and max-execution time
RUN sed -i "s/max_input_time = 30/max_input_time = 120/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 5M/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/max_execution_time = 30/max_execution_time = 120/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/memory_limit = 128M/memory_limit = 256M/g" "$PHP_INI_DIR/php.ini"

新的

FROM php:7.3-apache-stretch

# Enable Reqrite and Headers for .htaccess
RUN a2enmod rewrite
RUN a2enmod headers

# Ensure UTF-8
RUN echo "AddDefaultCharset UTF-8" > /var/www/html/.htaccess

RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS"

# Install linux dependencies
RUN apt-get update --fix-missing \
  && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev \
  libpng-dev libbz2-dev \
  libssl-dev autoconf \
  ca-certificates curl g++ libicu-dev mysql-client \
  ssl-cert libmagickwand-dev libpq-dev zlib1g libzip-dev \
  && rm -rf /var/lib/apt/lists/*

# Install imagick
RUN pecl install imagick-3.4.3

# Install php extentions for docker
RUN docker-php-ext-enable imagick

RUN docker-php-ext-install bcmath bz2 exif \
  gd gettext mbstring opcache

RUN docker-php-ext-install shmop sockets sysvmsg sysvsem sysvshm \
  zip iconv pdo_mysql intl

# Enable SSL apache2
RUN a2ensite default-ssl \
  && a2enmod ssl

COPY php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
  PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \
  PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
  PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"

# Replace the default served file to /web
RUN sed -i 's%/var/www/html%/var/www/html/web%g' /etc/apache2/sites-enabled/*.conf

# Use the PORT environment variable in Apache configuration files.
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf

# Replace with production mode
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Up the upload file size limit, memory limit and max-execution time
RUN sed -i "s/max_input_time = 30/max_input_time = 120/g" "$PHP_INI_DIR/php.ini" && \
  sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 10M/g" "$PHP_INI_DIR/php.ini" && \
  sed -i "s/max_execution_time = 30/max_execution_time = 120/g" "$PHP_INI_DIR/php.ini" && \
  sed -i "s/memory_limit = 128M/memory_limit = 512M/g" "$PHP_INI_DIR/php.ini"

对于发布整个文件,我深表歉意。

预期结果和实际结果已经说明。

我发现的一些观察结果是超时正好是 10 秒,如果这与某事有关。

任何帮助将不胜感激。

先感谢您。

4

1 回答 1

4

检查以确保您的 Cloud SQL 实例启用了公共 IP 连接。如果不启用,Cloud SQL 代理将无法工作。

于 2019-09-27T12:09:52.100 回答