0

I'm using Memcached on each of my EC2 web server instances. I am not sure how to configure the various hostnames for the memcache nodes at the server level.

Consider the following example:

<?php 
$mc = new Memcached() 
$mc->addServer('node1', 11211); 
$mc->addServer('node2', 11211); 
$mc->addServer('node3', 11211);

How are node1, node2, node3 configured?

I've read about a few setups to configure the instance with hostname and update /etc/host with these entries. However, I'm not familiar enough with configuring such things.

I'm looking for a solution that scales - handles adding and removing instances - and automatic.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
  • Is this something that might be dynamic with a set number of hosts, or something elastic with a variable number of hosts? If you intent to be variable with the number of hosts, which system are you using to manage the host scaling? – datasage Feb 19 '13 at 23:19
  • Ideally elastic. Although I won't have anything *managing* the auto-scaling. Unless you could AWS and ELB. Nonetheless, I would like when I create a new instance not to have to configure server + memcached + code. – Jason McCreary Feb 19 '13 at 23:28

1 Answers1

0

The difficulty with this is keeping an updated list of hosts within your application. When hosts could be added and removed, keeping this list up to date may be a challenge. You may be able to use some sort of proxy which would help by giving you a constant endpoint for your application.

If you can't use a proxy, I have a couple ideas.

  1. If the list of hosts is static, assign an elastic ip to each memcached host. Within ec2 region, this will resolve to the local IP address of the host its associated with. With this idea, you have a constant list of hosts that your application can use.

  2. If you are going to add/remote hosts on a regular basis, you need to be able dynamically update the lists of hosts your application will use. You can query the EC2 api for instances with a certain tag, then get the IP addresses for all of those instances. Cache the list in memory or on disk and load it with your application. If you run this every minute, any host changes should propagate within 1 minute, unless the EC2 api is being slow to update.

datasage
  • 19,153
  • 2
  • 48
  • 54
  • I don't want to buy several static IPs. Could you elaborate on option #2 about the tagging and how I might go about setting the hostname of the instance to something other than *ec2-ip-xxx-xxx-xxx*? – Jason McCreary Feb 19 '13 at 23:53
  • Elastic IPs wont cost you anything as long as they stay assigned to a host. You are charged for the time they are not assigned. You won need to worry about setting the hostname at all, you will just pull whatever amazon has assigned to it. – datasage Feb 20 '13 at 00:38
  • Aren't ec2 elastic ips public? – U0001 Sep 30 '14 at 22:58