In this step-by-step guide i’ll show you how to install Redis on AWS (Amazon Linux AMI).
I’ll assume you’re performing steps below as a su (sudo -s).
- First thing you need is to have following tools installed:
> gcc
> gcc-c++
> makeyum -y install gcc gcc-c++ make
_
- Download Redis:
cd /usr/local/src wget http://download.redis.io/releases/redis-2.8.12.tar.gz tar xzf redis-2.8.12.tar.gz rm -f redis-2.8.12.tar.gz
_
- Build it:
cd redis-2.8.12 make distclean make
_
- Create following directories and copy binaries:
mkdir /etc/redis /var/redis cp src/redis-server src/redis-cli /usr/local/bin
_
- Copy Redis template configuration file into /etc/redis/ (using Redis port number instance as its name (according to best practices mentioned on Redis site)):
cp redis.conf /etc/redis/6379.conf
_
- Create directory inside /var/redis that will act as working/data directory for this Redis instance:
mkdir /var/redis/6379
_
- Edit Redis config file to make necessary changes:
nano /etc/redis/6379.conf
_
- Make following changes to 6379.conf
> Set daemonize to yes (by default it is set to no).
> Set pidfile to /var/run/redis.pid
> Set preferred loglevel
> Set logfile to /var/log/redis_6379.log
> Set dir to /var/redis/6379_
- Don’t copy the standard Redis init script from utils directory into /etc/init.d (as it’s not Amazon Linux AMI/chkconfig compliant), instead download the following:
wget https://raw.githubusercontent.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
_
- Move and chmod downloaded redis init script:
mv redis-server /etc/init.d chmod 755 /etc/init.d/redis-server
_
- Edit redis-server init script and change redis conf file name as following:
> REDIS_CONF_FILE=”/etc/redis/6379.conf”nano /etc/init.d/redis-server
_
- Auto-enable Redis instance:
chkconfig --add redis-server chkconfig --level 345 redis-server on
_
- Start Redis:
service redis-server start
_
- (optional) Add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf (otherwise background save may fail under low memory condition – according to info on Redis site):
> vm.overcommit_memory = 1nano /etc/sysctl.conf
_
- Activate the new sysctl change:
sysctl vm.overcommit_memory=1
_
- Try pinging your instance with redis-cli:
/usr/local/bin/redis-cli ping
_
- Do few tests with redis-cli and check that the dump file is correctly stored into /var/redis/6379/ (you should find a file called dump.rdb):
/usr/local/bin/redis-cli >set testkey testval >get testkey >del testkey >exit
_
- Check that your Redis instance is correctly logging in the log file:
cat /var/log/redis_6379.log
_
And that would be basically it. Cheers.
Tagged: Amazon AWS, Redis
wow !! the documentation is very clean. none of the steps errored out .. and redis was running all good .. Thanks
I’ve made a scripted version: https://gist.github.com/ffabreti/0512fb5705926ae7f5ee34536a0e28db