| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Memcache</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Memcache</b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | <b>What is Memcache?</b><br> |
| 15 | <a href="http://memcached.org/">Memcache</a> (or "memcached") is an open-source, |
| 16 | high performance memory object caching system. A simple (and effective) |
| 17 | key/value store accessible, efficiently, over the network. |
| 18 | |
| 19 | <p> |
| 20 | <b>How Can Memcache Be Useful for ProFTPD?</b><br> |
| 21 | Like any high-performance object store, <code>memcached</code> offers several |
| 22 | possibilities to a server like <code>proftpd</code>. Many sites use |
| 23 | <code>memcached</code> for caching; it can <i>also</i> be used as an efficient |
| 24 | shared storage mechanism, for sharing data among many different servers. And |
| 25 | for ProFTPD specifically, the shared storage aspect is what is most useful. |
| 26 | Things like SSL/TLS sessions can be cached and shared across a pool of |
| 27 | <code>proftpd</code> servers, as can ban lists for badly-behaved clients. |
| 28 | |
| 29 | <p> |
| 30 | <b>Enabling Memcache Support for ProFTPD</b><br> |
| 31 | OK, so you are interested enough in the possibilities that |
| 32 | <code>memcached</code> offers that you want to try it out. Excellent! To |
| 33 | do this, you will first need to make sure to build your <code>proftpd</code> |
| 34 | executable using the <code>--enable-memcache</code> configure option. The |
| 35 | <code>--enable-memcache</code> configure option automatically adds the |
| 36 | <code><a href="../modules/mod_memcache.html">mod_memcache</a></code> module to |
| 37 | your <code>proftpd</code> build. |
| 38 | |
| 39 | <p> |
| 40 | The <code>mod_memcache</code> module uses the <code><a href="http://libmemcached.org/libMemcached.html">libmemcached</a></code> library for talking to |
| 41 | <code>memcached</code> servers. If your <code>libmemcached</code> library is |
| 42 | installed in a non-standard location, you may need to tell the ProFTPD build |
| 43 | system where to find the <code>libmemcached</code> header files and libraries |
| 44 | using the <code>--with-includes</code> and <code>--with-libraries</code> |
| 45 | configure options. |
| 46 | |
| 47 | <p> |
| 48 | There are other modules which make use of memcached support when available, |
| 49 | such as |
| 50 | <code><a href="../contrib/mod_tls_memcache.html">mod_tls_memcache</a></code>. |
| 51 | Thus to take advantage of modules like this, putting everything together, your |
| 52 | configure command might look like this: |
| 53 | <pre> |
| 54 | $ ./configure --enable-memcache \ |
| 55 | --with-modules=...:mod_tls_memcache:... \ |
| 56 | --with-includes=/path/to/libmemcached/include \ |
| 57 | --with-libraries=/path/to/libmemcached/lib |
| 58 | </pre> |
| 59 | |
| 60 | <p> |
| 61 | <b>Configuring <code>mod_memcache</code></b><br> |
| 62 | Now that you have compiled <code>proftpd</code> with the |
| 63 | <code>mod_memcache</code> module, you need to add the necessary |
| 64 | <code>mod_memcache</code> directives to your <code>proftpd.conf</code>. |
| 65 | The following example demonstrates this: |
| 66 | <pre> |
| 67 | <IfModule mod_memcache.c> |
| 68 | # Enable mod_memcache |
| 69 | MemcacheEngine on |
| 70 | |
| 71 | # Tell mod_memcache where to log its messages |
| 72 | MemcacheLog /path/to/proftpd/memcache.log |
| 73 | |
| 74 | # Tell mod_memcache where to find the memcached servers |
| 75 | MemcacheServers 192.168.0.10:11211 192.168.0.11:11211 |
| 76 | </IfModule> |
| 77 | </pre> |
| 78 | If you wish to see more detailed logging, at least while you are setting |
| 79 | up your memcached servers for ProFTPD, you can enable trace logging for the |
| 80 | <code>memcache</code> trace channel using <i>e.g.</i>: |
| 81 | <pre> |
| 82 | TraceLog /path/to/proftpd/trace.log |
| 83 | Trace DEFAULT:10 memcache:20 |
| 84 | </pre> |
| 85 | |
| 86 | <p> |
| 87 | <b>Using Memcache for Shared Storage</b><br> |
| 88 | You have now compiled support for memcached into ProFTPD, and you have told the |
| 89 | <code>mod_memcache</code> module where to find your <code>memcached</code> |
| 90 | servers. Is that all you need to do? No. Now you need to tell |
| 91 | <code>proftpd</code> modules which bits of data to store in your |
| 92 | <code>memcached</code> servers. |
| 93 | |
| 94 | <p> |
| 95 | Currently, only two modules can take advantage of <code>memcached</code> |
| 96 | support: <code><a href="../contrib/mod_ban.html">mod_ban</a></code> and |
| 97 | <code><a href="../contrib/mod_tls_memcache.html">mod_tls_memcache</a></code>. |
| 98 | |
| 99 | <p> |
| 100 | First, let us examine <code>mod_ban</code> and how it would use |
| 101 | <code>memcached</code>. The <code>mod_ban</code> module manages ban lists, |
| 102 | lists of clients/users which have been banned for various reasons. These |
| 103 | lists are stored in shared memory by default; this works for a single |
| 104 | <code>proftpd</code> server, but if a badly behaved client is banned by one |
| 105 | <code>proftpd</code> server in pool of servers, that client can then connect to |
| 106 | a different server which might not have a ban for that client -- and the client |
| 107 | then gets another chance to be naughty. To configure <code>mod_ban</code> so |
| 108 | that it stores its ban lists in <code>memcached</code>, simply use the following |
| 109 | in your <code>proftpd.conf</code>: |
| 110 | <pre> |
| 111 | <IfModule mod_ban.c> |
| 112 | BanEngine on |
| 113 | |
| 114 | # ...other mod_ban directives... |
| 115 | |
| 116 | # Tell mod_ban to store its ban lists using memcache |
| 117 | BanCache memcache |
| 118 | </IfModule> |
| 119 | </pre> |
| 120 | With this, <code>mod_ban</code> will use <code>memcached</code> (as well as |
| 121 | shared memory) for reading/writing its ban lists. And this, in turn, means |
| 122 | that other <code>proftpd</code> servers' <code>mod_ban</code> modules can see |
| 123 | those bans, and reject the badly behaved clients across the pool/cluster. |
| 124 | |
| 125 | <p> |
| 126 | The <code>mod_tls_memcache</code> module uses <code>memcached</code> servers |
| 127 | for storing SSL/TLS sessions; SSL/TLS session caching can greatly improve |
| 128 | SSL/TLS session handshake times, particularly for data transfers using |
| 129 | SSL/TLS. If you have a pool of <code>proftpd</code> servers, and you have |
| 130 | FTPS clients which may connect to a different node every time, caching the |
| 131 | SSL/TLS session data in a shared storage mechanism like <code>memcached</code> |
| 132 | can be quite beneficial. |
| 133 | |
| 134 | <p> |
| 135 | To use <code>memcached</code> for SSL/TLS session caching, then, you use the |
| 136 | <a href="../contrib/mod_tls.html#TLSSessionCache"><code>TLSSessionCache</code></a> directive of the <code>mod_tls</code> module, using something like this |
| 137 | in your <code>proftpd.conf</code>: |
| 138 | <pre> |
| 139 | <IfModule mod_tls.c> |
| 140 | TLSEngine on |
| 141 | |
| 142 | # ...other mod_tls directives... |
| 143 | |
| 144 | <IfModule mod_tls_memcache.c> |
| 145 | # Tell mod_tls to cache sessions using memcached |
| 146 | TLSSessionCache memcache: |
| 147 | </IfModule> |
| 148 | </IfModule> |
| 149 | </pre> |
| 150 | That's it. The <code>mod_tls</code> module now knows to give the SSL/TLS |
| 151 | session data to <code>mod_tls_memcache</code>, and <code>mod_tls_memcache</code> |
| 152 | knows how to talk to the <code>memcached</code> servers using |
| 153 | <code>mod_memcache</code>. |
| 154 | |
| 155 | <p><a name="FAQ"> |
| 156 | <b>Frequently Asked Questions</b><br> |
| 157 | <font color=red>Question</font>: If I don't use memcache, are there other |
| 158 | ways for sharing data (such as ban lists) among different <code>proftpd</code> |
| 159 | instances?<br> |
| 160 | <font color=blue>Answer</font>: It might be possible using <code>mod_sql</code> |
| 161 | and some <code>SQLLogInfo</code> directives, but that would only work for very |
| 162 | specific information. For sharing things like ban lists and SSL/TLS sessions |
| 163 | across a cluster of <code>proftpd</code> servers, Memcache (or |
| 164 | <a href="Redis.html">Redis</a>) support is <em>recommended</em>. |
| 165 | |
| 166 | <p> |
| 167 | <font color=red>Question</font>: Can I use <code>mod_memcache</code> to cache frequently accessed files, similar to <code><a href="http://wiki.nginx.org/HttpMemcachedModule">nginx+memcache</a></code>?<br> |
| 168 | <font color=blue>Answer</font>: No. And in reality, caching of files like that |
| 169 | will probably not give you the same performance gain for FTP transfers as it |
| 170 | can for HTTP transfers. |
| 171 | |
| 172 | <p> |
| 173 | Why not? Many HTTP transfers are for dynamically generated pages; the cost of |
| 174 | generating each page is expensive, and the generated content may not change |
| 175 | that frequently (relative to the rate of requests). FTP transfers, by contrast, |
| 176 | are for <b>static</b> files; FTP servers do not (usually) dynamically generate |
| 177 | the bytes of the files being downloaded. The cost of reading files from disk |
| 178 | is probably <i>less</i> than reading files from <code>memcached</code> over |
| 179 | the network, even a LAN. |
| 180 | |
| 181 | <p> |
| 182 | Now the above may not be true in <b>all</b> cases -- there may be FTP servers |
| 183 | serving files from network-mounted filesystems (<i>e.g.</i> NFS, CIFS |
| 184 | <i>et al</i>). And for these very specific cases, having a cache of frequently |
| 185 | access files on closer storage such as local disk (or <code>memcached</code>) |
| 186 | could make a big difference; please contact the ProFTPD Project if you find |
| 187 | yourself in this situation, and we will see what can be done to help. |
| 188 | |
| 189 | <p> |
| 190 | <font color=red>Question</font>: Why do I see the following error when |
| 191 | <code>proftpd</code> starts up?<br> |
| 192 | <pre> |
| 193 | mod_tls_memcache/0.1: notice: unable to register 'memcache' SSL session cache: Memcache support not enabled |
| 194 | </pre> |
| 195 | <font color=blue>Answer</font>: This message means that your |
| 196 | <code>proftpd</code> server has <code>mod_tls_memcache</code> built and |
| 197 | loaded, <b>but</b> your <code>proftpd</code> server was <b>not</b> built |
| 198 | with memcache support (<i>i.e.</i> the <code>--enable-memcache</code> configure |
| 199 | option was not used when compiling <code>proftpd</code>). |
| 200 | |
| 201 | <p> |
| 202 | The above is not a fatal or worrisome error; it is merely pointing out that |
| 203 | some of your modules want to use a feature that was not enabled. |
| 204 | |
| 205 | <p> |
| 206 | <hr> |
| 207 | <font size=2><b><i> |
| 208 | © Copyright 2017 The ProFTPD Project<br> |
| 209 | All Rights Reserved<br> |
| 210 | </i></b></font> |
| 211 | <hr> |
| 212 | |
| 213 | </body> |
| 214 | </html> |