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.
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.
I have included anfor 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.
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.
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!