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