Creating a Basic Google Cloud Compute Redis Instance

I use Redis for many different purposes. Sometimes, I need a large amount of RAM so Redis can act as a key store for megabytes or gigabytes of key values. Sometime I just need distributed locking and small-scale caching. Either way, setting up a Redis instance is a task I find myself performing from time to time.

Regardless of the size of the compute instance, I tend to perform the same steps: Create an Instance, select the machine type, and then under Advanced options > Automation I use a script like this:

sudo apt-get update
sudo apt-get remove man-db -y
sudo apt-get autoremove -y
sudo apt-get install -y redis-server
sudo sed -r -i 's/^bind\s+(.+?)$/# bind \1/' /etc/redis/redis.conf
sudo sed -r -i 's/^protected-mode yes$/protected-mode no/' /etc/redis/redis.conf

The basic idea is this clears out man-db and any unused packages, installs Redis, and then modifies /etc/redis.conf for my purposes. And, yes, I tend to remove man-db on my GCP instances, it really speeds up any package updating later on, especially on the smaller machine types.