2

I am trying to set up a mysql master/slave configuration in two EC2 instances.

However, every time I reboot an instance, the IP address (and hostname) changes. I could assign an Elastic IP address, but would prefer to use the internal IP address.

I can't be the first person to do this, but I can't seem to find a solution. There are a lot of "getting started" guides, but none of them mention how to handle changing IP addresses. So what are the best practices to manage master/slave replication in EC2?

8
  • 1
    Using a VPC (as recommended by ceejayoz) is the only sane way to do this if you must do you own replication. However, you really should consider using a multi-AZ RDS instance if at all possible. It uses hardware-level, synchronous replication between the new nodes. Commented Dec 17, 2012 at 18:38
  • 1
    @jamieb RDS has its downsides, though. I like more control over the infrastructure than it gives me. Commented Dec 17, 2012 at 18:50
  • @ceejayoz What downsides? Commented Dec 17, 2012 at 19:18
  • @jamieb You don't get SUPER access, which means you're unable to replicate to (for example) a different region or non-AWS datacenter. Filesystem and underlying EC2 instance are out of your control, as well, so some troubleshooting/optimization steps aren't available to you. Commented Dec 17, 2012 at 19:54
  • @ceejayoz: we are trying to duplicate an existing configuration, so moving to RDS isn't in the immediate future. I guess I need to read up on setting up VPC. Commented Dec 17, 2012 at 20:17

2 Answers 2

2

Use an elastic IP address. Make sure to refer to the server by the elastic IP address's public hostname, not the actual IP address.

Elastic IP addresses will resolve to the internal IP address when the resolution request comes from the availability zone's internal network. Otherwise, it will resolve to the public IP address.

So when one EC2 instance resolves the elastic IP address's public hostname of another instance that is in the same Availability Zone, it will use the internal address.

2

Use a VPC, where instances retain their internal IPs through reboots.

Or, create a script on your DB instances that adjusts a Route53 DNS record with their internal IP on bootup, and use that DNS record to connect.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.