Install Redis 7 on Amazon EC2 Linux
Redis is an in-memory data store that can be used for a variety of purposes, including caching, messaging, and leaderboards.
Steps to install
- Connect to your EC2 instance
- Install gcc
gcc, or the GNU Compiler Collection, is a set of compiler programs that we’ll need to compile Redis from source. To install gcc, run the following command on your EC2 instance:
sudo yum install gcc
Enter ‘y’ at the confirmation prompt.
3. Download and build redis-server
Redis is typically installed by compiling the source code. We’ll download the latest stable version of Redis from the official website and then compile it.
First, use wget to download the compressed tar archive of the Redis source code:
wget http://download.redis.io/redis-stable.tar.gz
Next, extract the contents of the archive using tar:
tar xvzf redis-stable.tar.gz
This will create a directory called redis-stable
. Navigate into this directory:
cd redis-stable
Finally, compile the Redis source code using make:
make
This will build the Redis server executable.
4. Create a Default Configuration File
Redis provides a sample configuration file (redis.conf
) in the source directory. You can copy and use it as the default
sudo mkdir -p /etc/redis
sudo cp redis-stable/redis.conf /etc/redis/6379.conf
5. Update the Configuration File
Edit the copied configuration file as needed.
sudo nano /etc/redis/6379.conf
Set Redis to run as a daemon:
daemonize yes
6. Setup Redis as a service
- Copy the
redis-server
binary to/usr/local/bin
:
sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/
- Use an init script or systemd service. Redis provides a sample init script in the
utils
folder:
sudo cp utils/redis_init_script /etc/init.d/redis
sudo chmod +x /etc/init.d/redis
sudo update-rc.d redis defaults
7. Start redis
sudo service redis start