为什么 google 云 shell 1 小时后自动断开连接

Why google cloud shell auto disconnect after 1 hours

我在实例上使用 Google Cloud Shell to run Jupyter Notebook,但在 1 hours 之后连接断开。

然后我重新连接到实例,没有任何东西,与重置实例相同。

So, please tell me how to set up ,make the connection of cloud shell keep connect.

谢谢!

The virtual machine instance that backs your Cloud Shell session is not permanently allocated to a Cloud Shell session and terminates if the session is inactive for an hour.

https://cloud.google.com/shell/docs/limitations

我来晚了,但如果还没有,请尝试一下。打开 sysctl.conf 并添加以下行。

grep keep /etc/sysctl.conf  
sudo vi /etc/sysctl.conf

net.ipv4.tcp_keepalive_time=60  
net.ipv4.tcp_keepalive_intvl=60  
net.ipv4.tcp_keepalive_probes=5  

停止并启动您的实例。

Google Cloud Shell 自动断开连接,因为您没有在 Cloudshell 的终端中执行任何操作!所以要保持cloudshell会话存活,可以在浏览器的javascript控制台

输入以下javascript代码
setInterval(function() {document.elementFromPoint(500, 500).click();}, 30000);

这就是诀窍!

P/S:如果你想使用Jupyter Notebook,为什么不使用Google Colab呢?它有一个预装的 Jupyter Notebook 以及更多 CPU 和 ram。您可以为 Colab 使用相同的 js!