Set up Redis on GCP Virtual Machine

Why on VM instead of using GCP Memorystore?

We can create Redis instance via Memorystore but with Memorystore we cannot connect to redis instance from outside ip address.

Follow tutorial to create VM on google cloud platform.

By default external ip address of a VM is changed from time to time. We need to set it statically.

In order for VM to be accessed from outside world we need to set firewall rule. Go to GCP firewall rules, then enable it to be accessed from all ip addresses (You can limit it access by some specific ip addresses). By default redis connection via port 6379.

SSH into VM and install redis via docker (you need to install docker if you don’t pre install it during VM setting up):

docker pull redis
docker run -d -p 6379:6379 --name redis-name redis

To access redis command line interface:

redis-cli -h vm_external_ip_address -p 6379

Set require pass:

config set requirepass mypass

After that every redis command would require pass to execute. In command line interface session, to authorize access, use command:

AUTH mypass

It is better to set require pass via redis configuration file, because every time vm is restarted we might lost setting require pass.

To list all containers:

docker ps -a OR docker container ls -a 

To list all container images:

docker image list

To sh into container:

docker exec -it container_id sh

How to set up Redis slave and master replication:



Very passionate about writing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store