redis: get key-value from another computer - redis

Computer B wants key-value from computer A.
Redis-server is on computer A with ip address 192.16.0.2, port 6379.
Computer B with ip address 192.16.0.3 tries to get data from computer A.
I tried
redis-cli -h 192.168.0.2 -h 6379.
But there is no response.
To check connection, ping 192.168.0.2 gets response within 1msec.
However telnet 192.168.0.2 6379 does not get response.
How should I solve this problem?

It looks like you are using the wrong flag to specify the port.
Try using the -p flag for the port:
redis-cli -h 192.168.0.2 -p 6379

Related

Connection to Redis through SSH tunnel: reset by peer

My Redis instance is installed and run at VIRTUAL_MACHINE. I connect to VIRTUAL_MACHINE via SSH tunnel through TUNNEL_SERVER to work from my local machine.
Tunnel string is the following:
ssh -L 0.0.0.0:10011:VIRTUAL_MACHINE:22 -L 0.0.0.0:10004:VIRTUAL_MACHINE:6379 -o ExitOnForwardFailure=yes -o ServerAliveInterval=15 -o ServerAliveCountMax=3 username#TUNNEL_SERVER
The issue is I can't connect to Redis instance from the local machine:
redis-cli -h 0.0.0.0 -p 10004
0.0.0.0:10004> ping
Error: Connection reset by peer
telnet 0.0.0.0 10004
Trying 0.0.0.0...
Connected to 0.0.0.0.
Escape character is '^]'.
Connection closed by foreign host.
On the remote machine (VIRTUAL MACHINE):
redis-cli -h localhost -p 6379
localhost:6379> ping
PONG
netstat -an | grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
redis.conf
bind 127.0.0.1
bind 0.0.0.0
protected-mode no
port 6379
timeout 60
tcp-keepalive 600
daemonize no
Because of Redis, I can't also connect to Flower (Celery).
If you have any idea about possible reasons, please help me to figure it out.
Thanks!
Only just saw this,
Can you SSH to 0.0.0.0:10011 and have access to the VIRTUAL_MACHINE?
Also are your auth creds for the TUNNEL_SERVER the same as for the VIRTUAL_MACHINE?
Forgive me if you already have, but, I would get SSH working to the VIRTUAL_MACHINE first via the TUNNEL_SERVER and then rework that to tunnel REDIS

Making a PATCH request from one machine to another

I currently have a python app running on a RPi connected to laptop #1. I used
ssh -Nf -L localhost:9999:localhost:5000 pi#raspberrypi.local
to forward any requests from laptop #1 to the RPi and can successfully make PATCH requests in the form of
curl -X PATCH "http://localhost:9999/pins/1" -H "Content-Type: application/json" -d "{\"state\": \"on\"}"
(This just turns a LED pin on)
Anyways, I want to make the same request but from another laptop, laptop #2 (and hopefully any other machine so that the lights can be changed from anywhere). I tried just switching the localhost to laptop #1's IP address, but that did not work. I believe the port 9999 is open for listening, when I use
netstat -a | grep -i "listen"
I get back:
ssh 16551 joshwh 8u IPv6 0x37a4856739271d0d 0t0 TCP [::1]:distinct (LISTEN)
ssh 16551 joshwh 9u IPv4 0x37a4856735b5ec1d 0t0 TCP 127.0.0.1:distinct (LISTEN)
Any ideas would be greatly appreciated.

Vagrant/Redis - Cannot connect from host

Still getting the hang of Vagrant/Redis/Linux. Please help! The issue is I cannot connect to redis server running on VM.
Host: Macbook
Vagrantfile:
config.vm.box = "laravel/homestead"
config.vm.hostname="redis-test"
config.vm.network "forwarded_port", guest: 6379, host: 6379, id: "redis"
Guest: laravel/homestead Vagrant box.
/etc/redis/redis.conf
bind 0.0.0.0
After changing redis.conf, I also restarted the service
sudo /etc/init.d/redis-server restart
(AND also) sudo service redis-server restart
Also made sure ufw is disabled
sudo ufw disable
sudo ufw status
Status: inactive
If I run redis-cli -h redis-test ping, I get pong, and can access redis as usual (on the guest VM)
Now back on the host machine (macbook), I cannot access redis-server.
redis-cli -h redis-test ping
Could not connect to Redis at redis-test:6379: nodename nor servname
provided, or not known
Can someone help me connect to redis-server on vagrant box, please? Any help is greatly appreciated!
You forwarded redis port 6379 from host machine to redis-test VM, but host machine knows nothing about redis-test domain you are trying to connect to.
You can connect redis on redis-test VM from host machine in two ways:
1.
connect to localhost, because redis port is already forwarded to redis on redis-test VM:
redis-cli -h localhost ping
2.
add redis-test to /etc/hosts:
echo '127.0.0.1 redis-test' >> /etc/hosts
and you can connect redis the way you used:
redis-cli -h redis-test ping

How to connect my local postgresql with my local ip address

My question is, I install the postgresql in my Mac, then I want to connect my postgresql with my local IP address.
For example, my local IP address is: 10.xxx.xxx.xxx, I want to command aspsql -U username -d dbname -h 10.xxx.xxx.xxx to instand of command psql -U username -d dbname -h 127.0.0.1.
I has added my IP address to pg_hba.conf, and changed listen_address in postgresql.conf to listen_address = '*', but not worked.
Thanks for answer.
Add your local IP in /etc/hosts file and then try again. Like below:
127.0.0.1 localhost
10.xxx.xxx.xxx localhost
if you run both and postgres and grafan from containers you have to check
$docker network inspect bridge
In my case there should be ip:172.17.0.4 and port: 16 instead of lochalhost and 5432. Those ip and port docker assigns automatically while makes the bridge between containers I guess.

How to connect to remote Redis server?

I have URL and PORT of remote Redis server. I am able to write into Redis from Scala. However I want to connect to remote Redis via terminal using redis-server or something similar in order to make several call of hget, get, etc. (I can do it with my locally installed Redis without any problem).
redis-cli -h XXX.XXX.XXX.XXX -p YYYY
xxx.xxx.xxx.xxx is the IP address and yyyy is the port
EXAMPLE from my dev environment
redis-cli -h 10.144.62.3 -p 30000
REDIS CLI COMMANDS
Host, port, password and database By default redis-cli connects to the
server at 127.0.0.1 port 6379. As you can guess, you can easily change
this using command line options. To specify a different host name or
an IP address, use -h. In order to set a different port, use -p.
redis-cli -h redis15.localnet.org -p 6390 ping
There are two ways to connect remote redis server using redis-cli:
1. Using host & port individually as options in command
redis-cli -h host -p port
If your instance is password protected
redis-cli -h host -p port -a password
e.g. if my-web.cache.amazonaws.com is the host url and 6379 is the port
Then this will be the command:
redis-cli -h my-web.cache.amazonaws.com -p 6379
if 92.101.91.8 is the host IP address and 6379 is the port:
redis-cli -h 92.101.91.8 -p 6379
command if the instance is protected with password pass123:
redis-cli -h my-web.cache.amazonaws.com -p 6379 -a pass123
2. Using single uri option in command
redis-cli -u redis://password#host:port
command in a single uri form with username & password
redis-cli -u redis://username:password#host:port
e.g. for the same above host - port configuration command would be
redis-cli -u redis://pass123#my-web.cache.amazonaws.com:6379
command if username is also provided user123
redis-cli -u redis://user123:pass123#my-web.cache.amazonaws.com:6379
This detailed answer was for those who wants to check all options.
For more information check documentation: Redis command line usage
In Case of password also we need to pass one more parameter
redis-cli -h host -p port -a password
One thing that confused me a little bit with this command is that if redis-cli fails to connect using the passed connection string it will still put you in the redis-cli shell, i.e:
redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
You'll then need to exit to get yourself out of the shell. I wasn't paying much attention here and kept passing in new redis-cli commands wondering why the command wasn't using my passed connection string.
if you got Error: Server closed the connection
try with --tls switch:
redis-cli --tls -h my-redis.redis.cache.windows.net -p 6379 -a myRedisPassword
h 👉 hostname
p 👉 port
a 👉 password