2014-01-30 63 views
0

我在一个GCE实例的开发服务器上设置PrestaShop安装,并将Cloud SQL用作数据库服务器。除了一件事以外,一切正常:只要网站长时间处于非活动状态,加载后的第一页始终会给我这个错误:首先从Prestashop连接到Google Cloud SQL总是失败

无法建立到数据库的链接:SQLSTATE [HY000] [2003]

如果我刷新页面,错误消失,直到我停止使用该网站一个小时左右,才再次出现。它几乎看起来像数据库实例正在进入睡眠模式或类似的东西。

我之前提到过Prestashop的原因是,我从来没有在使用Adminer或从MySQL控制台客户端连接到数据库时出现此错误。

+0

我补充说,通过wget的坪的网站每5分钟一个cron作业,但似乎并没有帮助。 – Damir

回答

2

通过使用计费模式,在15分钟超时后,实例会自动关闭以节省您的资金。然后,当下次访问时,他们需要几秒钟时间才能启动。这可能是Prestashop在这些第一次请求中超时(尽管我对该应用程序没有经验)。

试着改变你的实例包计费,其中有12个小时的超时时间,看看这有助于

https://developers.google.com/cloud-sql/faq#how_usage_calculated

1

GCE documentation

Once a connection has been established with an instance, traffic is permitted in both directions over that connection, until the connection times out after 10 minutes of inactivity

我怀疑这可能是原因。为了解决它,你可以尝试lower the tcp keepalive time

1

参考这里:https://cloud.google.com/sql/docs/compute-engine-access

To keep long-lived unused connections alive, you can set the TCP keepalive. The following commands set the TCP keepalive value to one minute and make the configuration permanent across instance reboots.

# Display the current tcp_keepalive_time value. 
$ cat /proc/sys/net/ipv4/tcp_keepalive_time 

# Set tcp_keepalive_time to 60 seconds and make it permanent across reboots. 
$ echo 'net.ipv4.tcp_keepalive_time = 60' | sudo tee -a /etc/sysctl.conf 

# Apply the change. 
$ sudo /sbin/sysctl --load=/etc/sysctl.conf 

# Display the tcp_keepalive_time value to verify the change was applied. 
$ cat /proc/sys/net/ipv4/tcp_keepalive_time