简体   繁体   English

Google Cloud Compute Instance + WordPress

[英]Google Cloud Compute Instance + WordPress

I've recently setup and deployed two standard WordPress installations using Google Cloud Compute VM Instance. 我最近使用Google Cloud Compute VM Instance设置并部署了两个标准的WordPress安装。

The issue that I am having is that when the site is idle for a few hours or a couple of days, there is an error establishing a connection to the database. 我遇到的问题是,当网站闲置几个小时或几天时,建立与数据库的连接时出错。

If I reset the server, everything works fine. 如果我重置服务器,一切正常。

I'm the furthest thing away from being an expert on Cloud based servers, any advice would be greatly appreciated! 我是远离基于云的服务器专家的最远的事情,任何建议将不胜感激!

I also posted this question in the Google GCE Group. 我还在Google GCE Group中发布了这个问题。

https://groups.google.com/forum/#!topic/gce-discussion/8knQumfLsBY https://groups.google.com/forum/#!topic/gce-discussion/8knQumfLsBY

Credit to George from Google Support, the fix was rather simple. 感谢来自Google支持的George,修复非常简单。

On GCE idle TCP connections are disconnected after 10 minutes. 在GCE上,空闲的TCP连接在10分钟后断开连接。 If your instance initiates or accepts long-lived connections with an external host, you can adjust TCP keep-alive settings to prevent these timeouts from dropping connections. 如果您的实例启动或接受与外部主机的长期连接,则可以调整TCP保持活动设置以防止这些超时丢弃连接。 You can configure the keep-alive settings on the Compute Engine instance, your external client, or both, depending on the host that typically initiates the connection. 您可以在Compute Engine实例,外部客户端或两者上配置保持活动设置,具体取决于通常启动连接的主机。 You should set the keep-alives to less than 600 seconds to ensure that connections are refreshed before the timeout occurs. 您应该将keep-alives设置为小于600秒,以确保在超时发生之前刷新连接。 You can do that by running the following command: 您可以通过运行以下命令来执行此操作:

sudo /sbin/sysctl -w net.ipv4.tcp_keepalive_time=60 net.ipv4.tcp_keepalive_intvl=60 net.ipv4.tcp_keepalive_probes=5

You will oly be able to run the command as root. 您将能够以root身份运行该命令。 So sudo su to switch to root. 所以sudo su切换到root。

To ensure that the settings survive a reboot, add the settings to your /etc/sysctl.conf file. 要确保设置在重新启动后仍然存在,请将设置添加到/etc/sysctl.conf文件中。

This option is only available from the command line on the instance itself. 此选项仅可从实例本身的命令行获得。 In order to have the changes added to the " /etc/sysctl.conf " you can access the file using any of your preferred editors (vi, nano...) and add the following: 为了将更改添加到“/etc/sysctl.conf”,您可以使用任何首选编辑器(vi,nano ...)访问该文件,并添加以下内容:

# increase the time default value for connections to keep alive
net.ipv4.tcp_keepalive_time = 60
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 60

This solution is a confirmed fix to my problem, hope it helps someone else. 这个解决方案是我的问题的确认修复,希望它能帮助别人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM