Accessing GCP Memorystore from local machines

坚强是说给别人听的谎言 提交于 2020-01-09 10:03:12

问题


Whats the best way to access Memorystore from Local Machines during development? Is there something like Cloud SQL Proxy that I can use to set up a tunnel?


回答1:


You can spin up a Compute Engine instance and use port forwarding to connect to your Redis machine.

For example if your Redis machine has internal IP address 10.0.0.3 you'd do:

gcloud compute instances create redis-forwarder --machine-type=f1-micro
gcloud compute ssh redis-forwarder -- -N -L 6379:10.0.0.3:6379

As long as you keep the ssh tunnel open you can connect to localhost:6379




回答2:


I created a vm on google cloud

gcloud compute instances create redis-forwarder --machine-type=f1-micro

then ssh into it and installed haproxy

sudo su
apt-get install haproxy

then updated the config file

/etc/haproxy/haproxy.cfg

....existing file contents
frontend redis_frontend
  bind *:6379
  mode tcp
  option tcplog
  timeout client  1m
  default_backend redis_backend

 backend redis_backend
   mode tcp
   option tcplog
   option log-health-checks
   option redispatch
   log global
   balance roundrobin
   timeout connect 10s
   timeout server 1m
   server redis_server [MEMORYSTORE IP]:6379 check

restart haproxy

/etc/init.d/haproxy restart

I was then able to connect to memory store from my local machine for development




回答3:


You can spin up a Compute Engine instance and setup an haproxy using the following docker image haproxy docker image then haproxy will forward your tcp requests to memorystore.

For example i want to access memorystore instance with ip 10.0.0.12 so added the following haproxy configs:

frontend redis_frontend
   bind *:6379
   mode tcp
   option tcplog
   timeout client  1m
   default_backend redis_backend

backend redis_backend
   mode tcp
   option tcplog
   option log-health-checks
   option redispatch
   log global
   balance roundrobin
   timeout connect 10s
   timeout server 1m
   server redis_server 10.0.0.12:6379 check

So now you can access memorystore from your local machine using the following command:

redis-cli -h <your-haproxy-public-ipaddress> -p 6379

Note: replace with you actual haproxy ip address.

Hope that can help you to solve your problem.



来源:https://stackoverflow.com/questions/50281492/accessing-gcp-memorystore-from-local-machines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!