Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not connect to cluster from another PC #81

Closed
nbxtruong opened this issue Sep 22, 2019 · 8 comments
Closed

Can not connect to cluster from another PC #81

nbxtruong opened this issue Sep 22, 2019 · 8 comments

Comments

@nbxtruong
Copy link

nbxtruong commented Sep 22, 2019

I have two machines are running on Ubuntu 18.04. First machine (IP: 192.168.1.7) run redis cluster, and second (IP: 192.168.1.8) run nodejs application.

The application can not connect to Redis cluster, I don't know why.

When I check the docker logs. It show "IP After trim: '172.22.0.2'". I use FastoRedis connect to Redis cluster with IP 192.168.1.7 successful. But when I create key-value, It show message "Redirected to slot [11518] located at 172.22.0.2:7002"

I try to set IP: 0.0.0.0 but It does not work.

I use IORedis lib on nodejs application, and this is my config:

[ { port: 7000, host: '192.168.1.7' }, { port: 7001, host: '192.168.1.7' }, { port: 7002, host: '192.168.1.7' }, { port: 7003, host: '192.168.1.7' }, { port: 7004, host: '192.168.1.7' }, { port: 7005, host: '192.168.1.7' } ]

Please help me, thank you.

@nbxtruong
Copy link
Author

But, when I setup all of them on same machine. Everything work fine.

@nbxtruong
Copy link
Author

nbxtruong commented Sep 22, 2019

docker run -e "IP=0.0.0.0" -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 grokzen/redis-cluster:latest

I did try with this, but It only worked with same machine.

@Grokzen
Copy link
Owner

Grokzen commented Sep 22, 2019

It is not intended to be used from a different machine. The 0.0.0.0 binding just makes it possible for your client to connect from your local machine to you redis cluster. You have to use some other mechanism or bind the internal IP to another IP or make a mesh network between the machines to enable access between servers. This is something you have to do yourself to make it work.

@Grokzen Grokzen closed this as completed Sep 22, 2019
@Nikunja6
Copy link

Then what is the solution? any fork repo which we can use to connect to cluster from another PC

@Grokzen
Copy link
Owner

Grokzen commented Apr 16, 2020

@Nikunja6 I dont think there is any good solution really. I have been thinking about adding option for some kind of generic translation mechanism, but that has not yet materialized in any way. That would just allow you to say some basic stuff like, if you see ip x.y.z.w then remap it to a.b.c.d and for port or for dns name etc during the initialize step. This is a known and old problem, and i dont know if there is any other good way around it. I have always considered that the IP is a problem for the user of redis server itself and not this lib, you need to fix that in some way, and i have often said that redis-server itself needs to have some kind of mechanism to function much better inside a container envrionment where the internal data attributes like IP and port is either possible to explicitly map or dynamically set through some mechanism, it should not in reality be up to the client lib to sort out for you. Yes the client lib can, but i think that is the wrong way to solve it from a principal pov.

@Grokzen
Copy link
Owner

Grokzen commented Apr 16, 2020

Hmm, i think i wrote the last part from the wrong pov and i wrote it from a clients pov... But what i mean is that one bit is that this container is not really desined to be used from another computer, i am sure that you can find other container builds that is more built towards running inside a k8s cluster, or inside a compose cluster, or swarm or what have you. The intention of this container is what is specified in the README file. I personally have no interest in fixing or changing the container to suite some other solution right now as this container suits my needs and what the container is intended for. However, as it also says in there, i have no issue with reviewing and merging some solution that would bridge any further functionality into this container if anyone has any ideas of how to make it work in more scenarios.

But in the end, the point from my prev post still stands that it is a problem that is combined with docker + redis-server + redis client at the same time that makes it fubared. You need all 3 parts playing well with eachother and that is not happening right now sadly and i dont really know of have any good generic solution that will suite all use-cases or everyones choices in how they want to run this.

In theory, what is needed is for redis to be able to map other IP:s internally when working inside a docker container to allow for the redis cluster to report the correct IP:s when inside a docker container. If that is solved, then all of the things would work out.

The other solution i have been contemplating is to acctually split the cluster into different containers instead of running it inside one container, that might just solve the problem, but i have not experimented with that solution yet to see if it helps or not.

@mlixytz
Copy link

mlixytz commented Dec 10, 2020

Then what is the solution? any fork repo which we can use to connect to cluster from another PC

try
network_mode: "host"

@Grokzen
Copy link
Owner

Grokzen commented Dec 10, 2020

Yes like @mlixytz wrote, network_mode: host is the general solution for this to get the ports exposed to your host that you can then connect to from a remote machine, but there is no guarantee that the internal IP:s tracked inside your cluster will work out with a client lib so you have to test it out a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants