Install the built-in proxy

Install the built-in proxy

The Memcached built-in proxy is available only if you activate a specific configuration option while compiling Memcached. For this reason, you can run the proxy only if you build Memcached from source. This page guides you through through the following tasks:

  • Build and install Memcached with its proxy features enabled.
  • Download the Lua library that the proxy requires for common tasks.

For a general overview of the proxy, see Built-in proxy. For a hands-on tutorial that guides you through compiling and running the proxy with a simple configuration, see Built-in Proxy Quickstart.

Before you begin

Make sure that your machine has the necessary development tools and libraries to build Memcached from source. These requirements are probably available from your operating system’s package manager.

For example, on Debian, you can satisfy these requirements by having the following packages installed:

  • gcc
  • make
  • libevent-dev

The steps on this page guide you though launching three Memcached servers on TCP ports 11211, 11212, and 11213. If you already have Memcached services running on those ports and you don’t want to disrupt them, then you should take either of these additional steps:

  • Substitute different port numbers for this tutorial.
  • Run this tutorial as written on a different machine that isn’t running Memcached.

Download and build the proxy

To download and compile Memcached with its proxy features enabled, follow these steps:

  1. Download the latest Memcached release tarball:

    wget https://memcached.org/latest
    
  2. Unzip and untar the tarball, then change your working directory to the source directory:

    tar xzvf memcached-VERSION.tar.gz
    
    cd memcached-VERSION
    

    Replace VERSION with the version number in the tarball that you downloaded in the previous step.

  3. Configure the Memcached build process to enable the built-in proxy:

    ./configure --enable-proxy OTHER_OPTIONS
    

    Replace OTHER_OPTIONS with a list of any other options for the configure command that you wish to enable. For a complete list of these options, run the command ./configure --help.

  4. Build and test Memcached:

    make
    
    make test
    

    If you encounter errors related to missing tools or libraries, make sure that your system has the development packages that you need to build Memcached from source. For more information, see Before you begin.

  5. Install the proxy-enabled Memcached on your system.

    sudo make install
    
  6. Leave the source directory:

    cd ..
    
  7. Confirm that you have installed Memcached with proxy features enabled:

    memcached --help | grep proxy
    

    The output resembles the following:

    - proxy_config:        path to lua library file. separate with ':' for multiple files
    - proxy_arg:           string to pass to lua library
  8. Download the route library:

    wget https://raw.githubusercontent.com/memcached/memcached-proxylibs/main/lib/routelib/routelib.lua
    
  9. Move the routelib.lua file that you downloaded in the previous step to some permanent place on your file system, and take note of it. You will need to refer to its path when you run the Memcached proxy.