Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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. –  jamieb Dec 17 '12 at 18:38
1  
@jamieb RDS has its downsides, though. I like more control over the infrastructure than it gives me. –  ceejayoz Dec 17 '12 at 18:50
    
@ceejayoz What downsides? –  jamieb Dec 17 '12 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. –  ceejayoz Dec 17 '12 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. –  chris Dec 17 '12 at 20:17
show 3 more comments

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.