Setting Up Memcached As A Windows Service
Published Fri, 27 Aug 2010 • 1 comments
Memcached is an in-memory, distributed key-value store for random pieces of application data. It is useful for clustering and distributed caching and it (and similar tools) are becoming an increasingly common feature of large Web-based apps.
I don't like Windows any more than the next guy when it comes to using it as a Server OS, but sometimes you've got no choice - maybe you work in an environment where Windows Server is the only option. sigh
Memcached is not something that you would generally install on Windows, (not for production anyhow), but it is possible to have it running happily as a native Windows service.
Here's how -
- Download either the 32-bit or 64-bit Windows builds of Memcached from NorthScale
- Unzip the memcached build into a server folder, say "C:\memcached"
- Run memcached.exe and ensure it starts. You should get a blank console window. Ctrl+C will close it, assuming all is well.
- To set it up as a native service we will download the Windows Server 2003 Resource Kit
- Install the Windows Resource Kit. For clarity I'll refer to the install location as "C:\Program Files\Windows Resource Kits\Tools", in reality it may be different. Substitute your install location as needed.
- Open a command prompt and change to your resource kit folder e.g. C:\Program Files\Windows Resource Kits\Tools
- At the prompt:
instsrv Memcached "C:\Program Files\Windows Resource Kits\Tools\SRVANY.EXE"
- Open Notepad and paste the following into it -
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Memcached\Parameters] "Application"="c:\\memcached\\memcached.exe" "AppParameters"="-m 1024"Adjust the path as necessary. You can add (or remove) memcached command line options with the "AppParameters" option. The "-m 1024" creates 1024MB (1 GB) memcache. You can get a list of other options with "memcached -h" or on memcached.org
- Save the file as "c:\memcached\configservice.reg"
- Double click the file in Windows Explorer and merge the settings into the Registry.
- Start the service, e.g. "net start Memcached" at the command prompt
- You're done!
Also, there is an alternative option - you can use the Java based clone of memcached, (the intuitively/unimaginatively) named jmemcached.
This can be used in conjunction with Java Service Wrapper to create Java-based Windows service which operates like the native memcached.
About the Author
Richard Nichols is an Australian software engineer with a passion for making things.
You might also enjoy reading -
- 5 Minute Guide to Clustering - Java Web Apps in Tomcat
- 1 Minute Guide - Installing Redmine on Windows
- Quick Tip - Make Anything A Windows Service
- Use Hudson (now Jenkins) to restart a Windows service...
- Can't change the font in Netbeans Output Window?