Support: 1-800-961-4454
Sales Chat
1-800-961-2888

Setting up memcached on Cloud Sites

3

By: Adrian Otto

This tutorial explains how to access a memcached server running on (one or more) Cloud Servers from Cloud Sites. Using this approach you can leverage all of the features of the Cloud Sites application platform, and all it’s related scalability while still enjoying the benefits of memcached at the same time. Note that Cloud Sites and Cloud servers are currently provisioned in the same data center together, so network latency will be low which means throughput will be high.

Step 1: Set up memcached on Cloud Servers

Use my tutorial on setting up memcached on cloud servers to complete this step. You can skip step 6. You can also skip step 5 if you want to run a default configuration.

Step 2: Set up a Test Script

I have included an example PHP script for using memcached from Cloud Sites. You can download it, edit the $server_hostname variable in the script to refer to the address of your Cloud Server, rename it to example.php, and upload it to your Cloud Sites account using SFTP or FTP. Once it’s uploaded, you can see how the caching works.

About Security

You must recognize that memcached comes with no security controls. Its possible for a hacker to dump the contents of your cache, or potentially access or change the data in the cache if they know what the address and port of your memcached server are, and what keys you are using. I suggest that you use a non-standard port number for memcached, and prefix all of your keys with a 10+ digit string that you keep secret. If you are highly motivated, you can make a custom version of memcached that has the ‘flush_all’ command disabled.

I can save you a bit of work. Here is a custom patched memcached 1.4.0 x86_64 RPM I wrote that adds a command line option ‘S’ to disable ‘flush_all’ and ‘stats detail on’ . The original 1.4 source, a SPEC file for RHEL5 and CentOS5 and the patch are both included in the SRPM. By disabling these commands with the -S option in /etc/sysconfig/memcached (OPTIONS=”-S”) you can prevent would-be hackers from dropping all your cached items, or finding out what the names are of the keys you are using. The memcached maintainers want to do this a different way, so this patch won’t be included in the base memecahced source tree.

You might also be considering the restriction of access to your memcached instance by IP address. If you plan to use it from Cloud Sites that will be difficult because you won’t know what IP addresses your connections will come from, and they could change without notice. Furthermore, any other user of Cloud Sites would be coming form the same IP address. For this reason, it’s best to simply use the custom memcached version mentioned above and a secret key text that you prepend to all of your keys.

Completion

Congratulations! You’ve set up memcached on your Cloud Sites account! Now it’s time to begin using it in your web application to add speed and scalability to your application and start saving money!

About the Author

This is a post written and contributed by Adrian Otto.

Adrian serves as a Principal Architect for Rackspace, focusing on cloud services. He cares deeply about the future of cloud technology, and important projects like OpenStack. He also is a key contributor for and serves on the editing team for OASIS CAMP, a draft standard for application lifecycle management. He comes from an engineering and software development background, and has made a successful career as a serial entrepreneur.


More
3 Comments

[…] Setting up memcached on Cloud ServersSetting up memcached on Cloud Sites […]

avatar Rackspace Cloud Computing & Hosting |  memcached: More Cache = Less Cash! on August 3, 2009 | Reply

Links to a few of your other blog posts seem broken.

avatar David Beroff on June 9, 2013 | Reply

Hi David,

We were having an issue with some of our hyperlinks. It should be fixed now.

Thank you,
-Andrew

avatar Andrew Hickey [Racker] on June 9, 2013

Leave a New Comment

(Required)


Racker Powered
©2014 Rackspace, US Inc.