skip to Main Content

I am trying to connect to my Redis instance from my from my local machine by following this guide, where you create a Compute Engine instance to use for port forwarding to the Redis instance.

I was able to create the Compute Engine instance using:
gcloud compute instances create redis-port-forward-vm --machine-type=f1-micro --zone=us-east1-d.

When I try to create an SSH tunnel that port forwards traffic through the Compute Engine VM using:
gcloud compute ssh redis-port-forward-vm --zone=us-east1-d -- -N -L 6379:REDIS_INSTANCE_IP_ADDRESS:6379.

I get the following error:
channel 2: open failed: connect failed: Connection timed out.

I don’t understand what could be the issue, I am able to successfully SSH into the Compute Engine instance, but port forwarding is not working.

2

Answers


  1. I assume you’re replacing REDIS_INSTANCE_IP_ADDRESS with the value.

    You can also pass --ssh-flag to gcloud directly.

    Does this work?

    gcloud compute ssh redis-port-forward-vm 
    --zone=us-east1-d 
    --ssh-flag="-L 6379:localhost:6379"
    

    NOTE Generally it works with localhost rather than the remote host’s IP too

    Login or Signup to reply.
  2. Follow the below steps,

    1. Install redis-cli on the Compute Engine VM by running the following command from the redis-port-forward-vm SSH terminal:
      sudo apt-get install redis-server
    2. Create a Redis instance if not created already and check the port number of the Redis instance you created (it is 6379 by default but for me it was 6378).
    3. Run the following commands on your local machine terminal
      gcloud compute ssh redis-port-forward-vm --zone=us-east1-d
      redis-cli -h REDIS INSTANCE IP -p PORT NUMBER
    4. To test the connection, open a new terminal window and run the following command:
      redis-cli ping
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search