Install Redis v3.2 on AWS EC2 Instance
The latest Redis release, v3.2, has new GEO commands that I was excited to test. These commands save the longitude and latitude for points of interest in a special sorted set, search for points in a radius, or tell the distance between two points, for example. For a full list of updates, click here.
To see it in action, check out a sample app we built. Just try the guest view.
If you want to build and deploy an app using Redis 3.2, you will need to install it manually into an Amazon Web Services EC2 instance. If you want to test it on your local machine, follow the steps on the Redis site.
How to Install on EC2
Prior to following the steps I am providing, you will need to do a few things:
- Sign up for an Amazon Web Services account.
- Set up an EC2 instance (10 minutes). Be sure to select the Amazon Linux AMI.
- Leave the AWS Dashboard open in your browser.
- Use SSH to connect to your instance, as shown on Step 3.c.
You should now be at the Linux command line of your EC2 instance, and ready to begin installing Redis.
First, we will update server and install the toolchain.
sudo yum -y update
sudo yum -y install gcc make
Download and install Redis 3.2. Double check Redis for the latest link. If you get an error, use command “ls” to check the file name.
sudo wget http://download.redis.io/releases/redis-3.2.0.tar.gz
sudo tar xzf redis-3.2.0.tar.gz
sudo rm -f 3.2.0.tar.gz
sudo make distclean
Install tcl and Test Redis Installation
sudo yum install -y tcl
sudo make test
Make directories & copy files
sudo mkdir -p /etc/redis /var/lib/redis /var/redis/6379
sudo cp src/redis-server src/redis-cli /usr/local/bin
sudo cp redis.conf /etc/redis/6379.conf
You will need some vim basics for this part.
- pressing “:set number” will show the line numbers
- pressing “i” will allow you to insert text (edit)
- pressing “esc” will stop inserting and allow other vim commands
- pressing “:wq” followed by enter will write then quit vim
Open the config file
sudo vi /etc/redis/6379.conf
Edit the file, using vim, and confirm the options are set as shown. Line numbers may be shown in the bottom right hand side of the vim window. Don’t include the line numbers as you edit!
bind 127.0.0.1 //line 61
daemonize yes //line 127
logfile "/var/log/redis_6379.log" //line 162
dir /var/redis/6379 //line 246
Download and install the init script
sudo wget https://raw.githubusercontent.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
Open the Redis server init script with vim
sudo vi /etc/init.d/redis-server
Edit the config file reference to match
REDIS_CONF_FILE="/etc/redis/6379.conf" //line 26
Auto-enable and start the Redis server
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
sudo service redis-server start
Open the system controller config file with vim.
sudo vi /etc/systctl.conf
Add the following lines to ensure background saves and fix low-memory issue. This is a new file.
# ensure redis background save issue
vm.overcommit_memory = 1
Test Redis Server
The response should be PONG. If not, something went wrong.
A special thank you to Sean for testing this process.
I will be doing a follow up post explaining the GEO commands.