RedisLabs / redis-cluster-proxy

A proxy for Redis clusters.
GNU Affero General Public License v3.0
994 stars 129 forks source link

Ability to bind to 0.0.0.0 instead of localhost #16

Closed bsergean closed 4 years ago

bsergean commented 4 years ago

So I'm trying to setup redis-cluster-proxy in openshift, but to have the server reachable from a different machine I had to use 0.0.0.0 in anetTcp6Server and anetTcp4Server.

-------------------------------- src/proxy.c ---------------------------------
index b2df63e..cbcd6f7 100644
@@ -2174,14 +2174,14 @@ void onClusterNodeDisconnection(clusterNode *node) {
 static int listen(void) {
     int fd_idx = 0;
     /* Try to use both IPv6 and IPv4 */
-    proxy.fds[fd_idx] = anetTcp6Server(proxy.neterr, config.port, NULL,
+    proxy.fds[fd_idx] = anetTcp6Server(proxy.neterr, config.port, "0.0.0.0",
                                        proxy.tcp_backlog);
     if (proxy.fds[fd_idx] != ANET_ERR)
         anetNonBlock(NULL, proxy.fds[fd_idx++]);
     else if (errno == EAFNOSUPPORT)
         proxyLogWarn("Not listening to IPv6: unsupported\n");

-    proxy.fds[fd_idx] = anetTcpServer(proxy.neterr, config.port, NULL,
+    proxy.fds[fd_idx] = anetTcpServer(proxy.neterr, config.port, "0.0.0.0",
                                       proxy.tcp_backlog);
     if (proxy.fds[fd_idx] != ANET_ERR)
         anetNonBlock(NULL, proxy.fds[fd_idx++]);

Shouldn't this be a config option ? I didn't see this in regular redis so now I'm all confused. All the server I ran on a different box usually have the option to bind on a different address (usually 0.0.0.0).

artix75 commented 4 years ago

The --bind option will be implemented soon, maybe today or in the next days.

bsergean commented 4 years ago

Ah great. No rush I found my way around it. If I can find the time I would love to make a PR but don't trust me.

As a side note I was curious about the PING command, and whether it could 'ping the cluster, or get the status of the cluster to compute the answer (extract the part that give the status of the cluster in the CLUSTER INFO response)

On Jan 16, 2020, at 2:45 AM, artix notifications@github.com wrote:

The --bind option will be implemented soon, maybe today or in the next days.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/artix75/redis-cluster-proxy/issues/16?email_source=notifications&email_token=AC2O6UJTLISA4PFUHEZTC33Q6A3C7A5CNFSM4KHM4ZM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJDTUJQ#issuecomment-575093286, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2O6UKM5KWNOHHGFQ7OMFTQ6A3C7ANCNFSM4KHM4ZMQ.

artix75 commented 4 years ago

@bsergean The PING command actually pings the proxy, not the cluster. Pinging the cluster would result in a multiple replies, and this would break the original Redis design of the command. Probably I'll add something like PROXY CLUSTER CALL , that would return an array such as: [node1, reply1, node2, reply2] and so on.

artix75 commented 4 years ago

@bsergean I added support for the --bind option. See commit 53bdfd29578adfa3b015975b3b90aac130de4e30.

bsergean commented 4 years ago

Awesome let me try it out.

For the ping thing, maybe ping could be ran on all the masters of the cluster, and if all the master reply with PONG we're good and the proxy reply PONG. That could be added on top of your PROXY CLUSTER CALL idea.

On Jan 16, 2020, at 9:08 AM, artix notifications@github.com wrote:

@bsergean https://github.com/bsergean I added support for the --bind option. See commit 53bdfd2 https://github.com/artix75/redis-cluster-proxy/commit/53bdfd29578adfa3b015975b3b90aac130de4e30.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/artix75/redis-cluster-proxy/issues/16?email_source=notifications&email_token=AC2O6UPYKDEKH2L2NABJ3LTQ6CH7JA5CNFSM4KHM4ZM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJE2AYA#issuecomment-575250528, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2O6UJAK2RKEN7WQMRNEE3Q6CH7JANCNFSM4KHM4ZMQ.