简体   繁体   English

在 Amazon ec2 上建立数据库连接时出错

[英]Error establishing a database connection on Amazon ec2

So I've researched this topic and all the other posts thoroughly for the past few months and not permanent solution works.所以我在过去几个月里彻底研究了这个主题和所有其他帖子,而不是永久的解决方案。

I installed Wordpress on an Amazon EC2 server using Putty SSH.我使用 Putty SSH 在 Amazon EC2 服务器上安装了 Wordpress。 My website works wonderfully until I run Facebook and Instagram ads that drive massive traffic to the website (www.ProfRoofs.com).我的网站运行得非常好,直到我运行 Facebook 和 Instagram 广告,这些广告为网站 (www.ProfRoofs.com) 带来了大量流量。 After a few minutes of the ad running, the home page displays..广告运行几分钟后,主页显示..

"Error establishing a database connection" “建立数据库连接时出错”

I tried solutions on here including editing the wp-config.php file to include those suggested FTP credentials.我在这里尝试了解决方案,包括编辑 wp-config.php 文件以包含那些建议的 FTP 凭据。 I read about creating a load balancer but find that inefficient.我阅读了有关创建负载均衡器的内容,但发现效率低下。 The only temporary solution that works is rebooting my instance, but that gets annoying to do all the time.唯一有效的临时解决方案是重新启动我的实例,但这样做总是很烦人。

Should I pay for the $50/month support from Amazon to fix it?我应该支付亚马逊每月 50 美元的支持来修复它吗? I am wondering if it is because I am using the free tier EC2 instance and it is too small/not enough memory?我想知道是不是因为我使用的是免费层 EC2 实例并且它太小/内存不足? I read a post about increasing the memory and I did that to 3GB and that still did nothing.我读了一篇关于增加内存的帖子,我把内存增加到了 3GB,但仍然什么也没做。

Any suggestions?有什么建议? Struggling to get a business running here.努力在这里开展业务。

Your EC2 instance does not have sufficient memory to handle the increased workload.您的 EC2 实例没有足够的内存来处理增加的工作负载。 I have seen this a lot with t2.micro instances running Wordpress and a local MySQL database.我在运行 Wordpress 和本地 MySQL 数据库的 t2.micro 实例中看到了很多。 Performance will be fine until load increases and then database connection errors will start.性能会很好,直到负载增加,然后数据库连接错误才会开始。

You can do one of two things:您可以执行以下两项操作之一:

  1. You can use a larger EC2 instance.您可以使用更大的 EC2 实例。 Through the AWS console, just stop your instance, change its instance type, and start it.通过 AWS 控制台,只需停止您的实例,更改其实例类型,然后启动它。 I would increase the instance type gradually to avoid paying for more than what you need.我会逐渐增加实例类型,以避免支付超出您需要的费用。
  2. You can offload your MySQL database to an RDS instance and remove MySQL from the EC2 instance.您可以将 MySQL 数据库卸载到 RDS 实例并从 EC2 实例中删除 MySQL。 This will definitely be beneficial but it is still possible you will require a larger instance type during times of peak traffic.这肯定是有益的,但在流量高峰期您仍然可能需要更大的实例类型。 RDS is available through the AWS free-tier. RDS 可通过 AWS 免费套餐获得。

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

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