0

I have a web application that uses an EC2 instance to receive uploaded images, resize and store on S3 and update my MySQL database with the image record. This database is hosted outside Amazon Web Services and so obviously involves communication between the EC2 instance and the database. Images are posted to the upload server from a Flash client which receives the IP address of the upload server when it is loaded and so sends images to 1.12.23.34/resize_script.php

This has worked great .. until i started to try and include a load balancer.

Since the ELBs do not use an IP address but a DNS address I am now passing this to Flash. Now when I upload images I get the following response from the server -

Could not connect to MySQL: Lost connection to MySQL server at 'reading initial communication packet', system error: 111

What might be causing the lost connection to MySQL server. Is there any additional steps I need to take to allow my upload servers to be load balanced? I have set the host property of my MySQL privileges for this user to %

any pointers greatly appreciated thanks.

2
  • So the Server is in AWS, the DB is not. What is behind the load balancer, just several EC2 instances? How do they know of the DB, just a hardcoded address on their app layer?
    – Flashman
    Jan 11, 2011 at 19:26
  • Yes that's right the EC2 instances are behind the load balancer, I have hardcoded the database connection details in a separate PHP script on the EC2 instances.
    – undefined
    Jan 11, 2011 at 20:09

2 Answers 2

1

Check both the firewall rules and the MySQL user permissions on the database. Does your database server allow incoming connections from the new ELB ip address?

4
  • Hi thanks for your answer. In the privileges table in mysql I have set the host field for the user that my EC2 instance scripts use to % which I think means should allow any IP address to connect. Since ELB does not use an IP address I cannot add an IP address as a host. Should % not allow it to connect anyway? I will look at firewall rules.
    – undefined
    Jan 13, 2011 at 10:19
  • Thanks - it was the firewall rules they were set to allow only remote access from a single (elastic) IP address. best
    – undefined
    Jan 13, 2011 at 10:57
  • However I still had the same problem when adding the DNS name to the firewall settings. It appears that the way the firewall works is to look up the IP address of the DNS and store that in its settings. AWS elastic load balancers change their IP addresses over time so this is not a very good solution - might have to open up 3306 to the world ... !! or find another way to load balance across multiple EC2 instances and connect to remote MySQL server - though I would have to add each new IP to the firewall ... hmm
    – undefined
    Jan 13, 2011 at 17:40
  • You can pay for an elastic IP, which won't change. Investigate that.
    – blueben
    Jan 15, 2011 at 5:58
0

Assign each one of the EC2 instances an Elastic IP, you won't be charged for the Elastic IP's as long as they're assigned to EC2 instances (be sure to delete them when your done with them, ie don't leave them without an instance assigned because for some reason amazon charge for idle Elastic IP's).

Once each EC2 instance has an IP you need to authorise those IP's to connect to the Database server.

It's not the load balancer that connects to the database server (it's the EC2 instances) so you don't need to worry about the ELB's dns or changing ip.

Hope that helps for anyone else stuck with this

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .