Blog About Contact

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 -

  1. Download either the 32-bit or 64-bit Windows builds of Memcached from NorthScale
  2. Unzip the memcached build into a server folder, say "C:\memcached"
  3. Run memcached.exe and ensure it starts. You should get a blank console window. Ctrl+C will close it, assuming all is well.
  4. To set it up as a native service we will download the Windows Server 2003 Resource Kit
  5. 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.
  6. Open a command prompt and change to your resource kit folder e.g. C:\Program Files\Windows Resource Kits\Tools
  7. At the prompt:
    instsrv Memcached "C:\Program Files\Windows Resource Kits\Tools\SRVANY.EXE"
  8. 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
  9. Save the file as "c:\memcached\configservice.reg"
  10. Double click the file in Windows Explorer and merge the settings into the Registry.
  11. Start the service, e.g. "net start Memcached" at the command prompt
  12. 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.

Follow him on twitter or subscribe by RSS or email.

You might also enjoy reading -


Discuss / Comment

There are 1 comments.

Add a comment

  • {{e.error}}

Thanks for your comment!/

Required.
Valid email address required.
Required.
Posting message, please wait...