Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Install Redis on Amazon EC2 AMI
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
#sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
#sudo yum -y install gcc gcc-c++ make
echo "*****************************************"
echo " 2. Download, Untar and Make Redis 2.6"
echo "*****************************************"
cd /usr/local/src
sudo wget http://redis.googlecode.com/files/redis-2.6.0-rc5.tar.gz
sudo tar xzf redis-2.6.0-rc5.tar.gz
sudo rm redis-2.6.0-rc5.tar.gz -f
cd redis-2.6.0-rc5
sudo make
echo "*****************************************"
echo " 3. Create Directories and Copy Redis Files"
echo "*****************************************"
sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
echo "*****************************************"
echo " 4. Configure Redis.Conf"
echo "*****************************************"
echo " Edit redis.conf as follows:"
echo " 1: ... daemonize yes"
echo " 2: ... bind 127.0.0.1"
echo " 3: ... dir /var/lib/redis"
echo " 4: ... loglevel notice"
echo " 5: ... logfile /var/log/redis.log"
echo "*****************************************"
sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf > /etc/redis/redis.conf
echo "*****************************************"
echo " 5. Download init Script"
echo "*****************************************"
wget https://raw.github.com/gist/2777433/e64b4b8ad7d38676f7e7f70b24f3f004b4f10b74/redis-server
echo "*****************************************"
echo " 6. Move and Configure Redis-Server"
echo "*****************************************"
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
echo "*****************************************"
echo " 7. Auto-Enable Redis-Server"
echo "*****************************************"
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
echo "*****************************************"
echo " 8. Start Redis Server"
echo "*****************************************"
sudo service redis-server start
echo "*****************************************"
echo " Complete!"
echo " You can test your redis installation using the redis console:"
echo " $ src/redis-cli"
echo " redis> set foo bar"
echo " OK"
echo " redis> get foo"
echo " bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."
@trueshot

This comment has been minimized.

Show comment Hide comment
@trueshot

trueshot Jan 17, 2013

This was really helpful to me. The "sed" line (40) doesn't work for me giving me an access denied error.

If I manually create the redis.conf file, everything else works.

This was really helpful to me. The "sed" line (40) doesn't work for me giving me an access denied error.

If I manually create the redis.conf file, everything else works.

@obrientimothya

This comment has been minimized.

Show comment Hide comment
@obrientimothya

obrientimothya Mar 14, 2013

Nice script - two bugs then it's perfect:

Line 40: Fails due to sudo not giving elevation to redirections. Try this instead:

sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf | sudo tee /etc/redis/redis.conf

Line 44: pwd is still /usr/local/src/redis-2.6.0-rc5 Needs sudo to write. Example:

sudo wget https://raw.github.com/gist/2777433/e64b4b8ad7d38676f7e7f70b24f3f004b4f10b74/redis-server

Thanks :-)

Nice script - two bugs then it's perfect:

Line 40: Fails due to sudo not giving elevation to redirections. Try this instead:

sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf | sudo tee /etc/redis/redis.conf

Line 44: pwd is still /usr/local/src/redis-2.6.0-rc5 Needs sudo to write. Example:

sudo wget https://raw.github.com/gist/2777433/e64b4b8ad7d38676f7e7f70b24f3f004b4f10b74/redis-server

Thanks :-)

@lordkada

This comment has been minimized.

Show comment Hide comment
@lordkada

lordkada Apr 22, 2013

Should update to the latest stable... (2.6.12) ;-)

Should update to the latest stable... (2.6.12) ;-)

@amooij

This comment has been minimized.

Show comment Hide comment
@amooij

amooij Aug 29, 2013

Thank you for this.

amooij commented Aug 29, 2013

Thank you for this.

@nefilim

This comment has been minimized.

Show comment Hide comment
@nefilim

nefilim Nov 13, 2013

here's an updated version with the latest version, fixes above and some minor improvements

#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use: 
# <<!!!!!!!!!!!!!!!!!!! FIX ME !!!!!!!!!!!!!!!!!!!!!!!!> wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
#sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
#sudo yum -y install gcc gcc-c++ make 
echo "*****************************************"
echo " 2. Download, Untar and Make Redis 2.6"
echo "*****************************************"
cd /usr/local/src
sudo wget http://download.redis.io/releases/redis-2.6.16.tar.gz
sudo tar xzf redis-2.6.16.tar.gz
sudo rm redis-2.6.16.tar.gz -f
cd redis-2.6.16
sudo make distclean
sudo make
echo "*****************************************"
echo " 3. Create Directories and Copy Redis Files"
echo "*****************************************"
sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
echo "*****************************************"
echo " 4. Configure Redis.Conf"
echo "*****************************************"
echo " Edit redis.conf as follows:"
echo " 1: ... daemonize yes"
echo " 2: ... bind 127.0.0.1"
echo " 3: ... dir /var/lib/redis"
echo " 4: ... loglevel notice"
echo " 5: ... logfile /var/log/redis.log"
echo "*****************************************"
sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf | sudo tee /etc/redis/redis.conf
echo "*****************************************"
echo " 5. Download init Script"
echo "*****************************************"
sudo wget https://raw.github.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
echo "*****************************************"
echo " 6. Move and Configure Redis-Server"
echo "*****************************************"
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
echo "*****************************************"
echo " 7. Auto-Enable Redis-Server"
echo "*****************************************"
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
echo "*****************************************"
echo " 8. Start Redis Server"
echo "*****************************************"
sudo service redis-server start
echo "*****************************************"
echo " Complete!"
echo " You can test your redis installation using the redis console:"
echo "   $ /usr/local/redis-2.6.16/src/redis-cli"
echo "   redis> set foo bar"
echo "   OK"
echo "   redis> get foo"
echo "   bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."

nefilim commented Nov 13, 2013

here's an updated version with the latest version, fixes above and some minor improvements

#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use: 
# <<!!!!!!!!!!!!!!!!!!! FIX ME !!!!!!!!!!!!!!!!!!!!!!!!> wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
#sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
#sudo yum -y install gcc gcc-c++ make 
echo "*****************************************"
echo " 2. Download, Untar and Make Redis 2.6"
echo "*****************************************"
cd /usr/local/src
sudo wget http://download.redis.io/releases/redis-2.6.16.tar.gz
sudo tar xzf redis-2.6.16.tar.gz
sudo rm redis-2.6.16.tar.gz -f
cd redis-2.6.16
sudo make distclean
sudo make
echo "*****************************************"
echo " 3. Create Directories and Copy Redis Files"
echo "*****************************************"
sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
echo "*****************************************"
echo " 4. Configure Redis.Conf"
echo "*****************************************"
echo " Edit redis.conf as follows:"
echo " 1: ... daemonize yes"
echo " 2: ... bind 127.0.0.1"
echo " 3: ... dir /var/lib/redis"
echo " 4: ... loglevel notice"
echo " 5: ... logfile /var/log/redis.log"
echo "*****************************************"
sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf | sudo tee /etc/redis/redis.conf
echo "*****************************************"
echo " 5. Download init Script"
echo "*****************************************"
sudo wget https://raw.github.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
echo "*****************************************"
echo " 6. Move and Configure Redis-Server"
echo "*****************************************"
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
echo "*****************************************"
echo " 7. Auto-Enable Redis-Server"
echo "*****************************************"
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
echo "*****************************************"
echo " 8. Start Redis Server"
echo "*****************************************"
sudo service redis-server start
echo "*****************************************"
echo " Complete!"
echo " You can test your redis installation using the redis console:"
echo "   $ /usr/local/redis-2.6.16/src/redis-cli"
echo "   redis> set foo bar"
echo "   OK"
echo "   redis> get foo"
echo "   bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."
@JodyAndrews

This comment has been minimized.

Show comment Hide comment
@JodyAndrews

JodyAndrews Nov 29, 2013

Exceptional! Thanks guys

Exceptional! Thanks guys

@buholzer

This comment has been minimized.

Show comment Hide comment
@buholzer

buholzer Feb 6, 2014

Fantastic! Thanks!

buholzer commented Feb 6, 2014

Fantastic! Thanks!

@scaryguy

This comment has been minimized.

Show comment Hide comment
@scaryguy

scaryguy Feb 25, 2014

Hi, nice job BUT https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server seems to be death and because of this this script is currently does not work.

Hi, nice job BUT https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server seems to be death and because of this this script is currently does not work.

@lucianosousa

This comment has been minimized.

Show comment Hide comment
@lucianosousa

lucianosousa Apr 10, 2014

@nefilim thanks the update! ;)

@dstroot thanks for all.

@nefilim thanks the update! ;)

@dstroot thanks for all.

@sardaukar

This comment has been minimized.

Show comment Hide comment
@sardaukar

sardaukar Apr 11, 2014

thanks for this!

thanks for this!

@sameg14

This comment has been minimized.

Show comment Hide comment
@sameg14

sameg14 Jul 18, 2014

Thank you all for this!

sameg14 commented Jul 18, 2014

Thank you all for this!

@winny-

This comment has been minimized.

Show comment Hide comment
@winny-

winny- Jul 23, 2014

Hi, this saved me a lot of time :-), however https://raw.github.com/gist/2777433/e64b4b8ad7d38676f7e7f70b24f3f004b4f10b74/redis-server is a dead link again! Can still run redis-server of course.

winny- commented Jul 23, 2014

Hi, this saved me a lot of time :-), however https://raw.github.com/gist/2777433/e64b4b8ad7d38676f7e7f70b24f3f004b4f10b74/redis-server is a dead link again! Can still run redis-server of course.

@josephmo

This comment has been minimized.

Show comment Hide comment
@josephmo

josephmo Jul 24, 2014

Why don't you use:
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
this guarantees the latest stable release.

Why don't you use:
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
this guarantees the latest stable release.

@bahout

This comment has been minimized.

Show comment Hide comment
@bahout

bahout Aug 10, 2014

Voilà, with redis stable

# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
sudo yum -y install gcc gcc-c++ make
echo "*****************************************"
echo " 2. Download, Untar and Make Redis stable"
echo "*****************************************"
cd /usr/local/src
sudo wget http://download.redis.io/redis-stable.tar.gz
sudo tar xzf redis-stable.tar.gz
sudo rm redis-stable.tar.gz -f
cd redis-stable
sudo make distclean
sudo make
echo "*****************************************"
echo " 3. Create Directories and Copy Redis Files"
echo "*****************************************"
sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
echo "*****************************************"
echo " 4. Configure Redis.Conf"
echo "*****************************************"
echo " Edit redis.conf as follows:"
echo " 1: ... daemonize yes"
echo " 2: ... bind 127.0.0.1"
echo " 3: ... dir /var/lib/redis"
echo " 4: ... loglevel notice"
echo " 5: ... logfile /var/log/redis.log"
echo "*****************************************"
sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf | sudo tee /etc/redis/redis.conf
echo "*****************************************"
echo " 5. Download init Script"
echo "*****************************************"
sudo wget https://raw.github.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
echo "*****************************************"
echo " 6. Move and Configure Redis-Server"
echo "*****************************************"
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
echo "*****************************************"
echo " 7. Auto-Enable Redis-Server"
echo "*****************************************"
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
echo "*****************************************"
echo " 8. Start Redis Server"
echo "*****************************************"
sudo service redis-server start
echo "*****************************************"
echo " Complete!"
echo " You can test your redis installation using the redis console:"
echo "   $ /usr/local/redis-2.6.16/src/redis-cli"
echo "   redis> set foo bar"
echo "   OK"
echo "   redis> get foo"
echo "   bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."

bahout commented Aug 10, 2014

Voilà, with redis stable

# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
sudo yum -y install gcc gcc-c++ make
echo "*****************************************"
echo " 2. Download, Untar and Make Redis stable"
echo "*****************************************"
cd /usr/local/src
sudo wget http://download.redis.io/redis-stable.tar.gz
sudo tar xzf redis-stable.tar.gz
sudo rm redis-stable.tar.gz -f
cd redis-stable
sudo make distclean
sudo make
echo "*****************************************"
echo " 3. Create Directories and Copy Redis Files"
echo "*****************************************"
sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
echo "*****************************************"
echo " 4. Configure Redis.Conf"
echo "*****************************************"
echo " Edit redis.conf as follows:"
echo " 1: ... daemonize yes"
echo " 2: ... bind 127.0.0.1"
echo " 3: ... dir /var/lib/redis"
echo " 4: ... loglevel notice"
echo " 5: ... logfile /var/log/redis.log"
echo "*****************************************"
sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf | sudo tee /etc/redis/redis.conf
echo "*****************************************"
echo " 5. Download init Script"
echo "*****************************************"
sudo wget https://raw.github.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
echo "*****************************************"
echo " 6. Move and Configure Redis-Server"
echo "*****************************************"
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
echo "*****************************************"
echo " 7. Auto-Enable Redis-Server"
echo "*****************************************"
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
echo "*****************************************"
echo " 8. Start Redis Server"
echo "*****************************************"
sudo service redis-server start
echo "*****************************************"
echo " Complete!"
echo " You can test your redis installation using the redis console:"
echo "   $ /usr/local/redis-2.6.16/src/redis-cli"
echo "   redis> set foo bar"
echo "   OK"
echo "   redis> get foo"
echo "   bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."
@picman

This comment has been minimized.

Show comment Hide comment
@picman

picman Sep 7, 2014

At the end:

echo " You can test your redis installation using the redis console:"
echo " $/usr/local/bin/redis-cli"

or just:

echo " $ redis-cli"

picman commented Sep 7, 2014

At the end:

echo " You can test your redis installation using the redis console:"
echo " $/usr/local/bin/redis-cli"

or just:

echo " $ redis-cli"

@justinseesdragons

This comment has been minimized.

Show comment Hide comment
@justinseesdragons

justinseesdragons Sep 13, 2014

Thank You VERY much... you just saved me much time and frustration!

Thank You VERY much... you just saved me much time and frustration!

@fertobar

This comment has been minimized.

Show comment Hide comment
@fertobar

fertobar Mar 2, 2015

works like a charm! thanks for share!

fertobar commented Mar 2, 2015

works like a charm! thanks for share!

@four43

This comment has been minimized.

Show comment Hide comment
@four43

four43 Mar 12, 2015

Updated version with all the comments and best practices mentioned here. I'll try to keep this version up to date as best I can. Feel free to leave a comment if you find something new.

https://gist.github.com/four43/e00d01ca084c5972f229

four43 commented Mar 12, 2015

Updated version with all the comments and best practices mentioned here. I'll try to keep this version up to date as best I can. Feel free to leave a comment if you find something new.

https://gist.github.com/four43/e00d01ca084c5972f229

@tdondich

This comment has been minimized.

Show comment Hide comment
@tdondich

tdondich Dec 30, 2016

You can also just enable the epel repo on amazon ami.
yum --enablerepo=epel install redis

However, do note that this may not install the latest and greatest redis. Also, it is disabled at all runlevels by default. Use chkconfig to enable.

You can also just enable the epel repo on amazon ami.
yum --enablerepo=epel install redis

However, do note that this may not install the latest and greatest redis. Also, it is disabled at all runlevels by default. Use chkconfig to enable.

@tushard-iprogrammer

This comment has been minimized.

Show comment Hide comment
@tushard-iprogrammer

tushard-iprogrammer Oct 12, 2017

And used the Redis stable version as suggested by @josephmo

Faced the 301 moved permanently error at Step 5. Download init script
so here is the latest URL,
https://gist.githubusercontent.com/dstroot/2777433/raw/061ceb203dc7b002b073f28880f63cfa3ef9b5d2/redis-server

The final script goes as follows:


#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use: 
# wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
#sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
#sudo yum -y install gcc gcc-c++ make 
echo "*****************************************"
echo " 2. Download, Untar and Make Redis 2.6"
echo "*****************************************"
cd /usr/local/src
sudo wget http://download.redis.io/redis-stable.tar.gz 
sudo tar xvzf redis-stable.tar.gz
sudo rm redis-stable.tar -f
cd redis-stable
sudo make
echo "*****************************************"
echo " 3. Create Directories and Copy Redis Files"
echo "*****************************************"
sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
echo "*****************************************"
echo " 4. Configure Redis.Conf"
echo "*****************************************"
echo " Edit redis.conf as follows:"
echo " 1: ... daemonize yes"
echo " 2: ... bind 127.0.0.1"
echo " 3: ... dir /var/lib/redis"
echo " 4: ... loglevel notice"
echo " 5: ... logfile /var/log/redis.log"
echo "*****************************************"
sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf > /etc/redis/redis.conf
echo "*****************************************"
echo " 5. Download init Script"
echo "*****************************************"
wget https://gist.githubusercontent.com/dstroot/2777433/raw/061ceb203dc7b002b073f28880f63cfa3ef9b5d2/redis-server
echo "*****************************************"
echo " 6. Move and Configure Redis-Server"
echo "*****************************************"
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
echo "*****************************************"
echo " 7. Auto-Enable Redis-Server"
echo "*****************************************"
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
echo "*****************************************"
echo " 8. Start Redis Server"
echo "*****************************************"
sudo service redis-server start
echo "*****************************************"
echo " Complete!"
echo " You can test your redis installation using the redis console:"
echo "   $ src/redis-cli"
echo "   redis> set foo bar"
echo "   OK"
echo "   redis> get foo"
echo "   bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."

tushard-iprogrammer commented Oct 12, 2017

And used the Redis stable version as suggested by @josephmo

Faced the 301 moved permanently error at Step 5. Download init script
so here is the latest URL,
https://gist.githubusercontent.com/dstroot/2777433/raw/061ceb203dc7b002b073f28880f63cfa3ef9b5d2/redis-server

The final script goes as follows:


#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use: 
# wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make"
echo "*****************************************"
#sudo yum -y update
#sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles \/etc/localtime
#sudo yum -y install gcc gcc-c++ make 
echo "*****************************************"
echo " 2. Download, Untar and Make Redis 2.6"
echo "*****************************************"
cd /usr/local/src
sudo wget http://download.redis.io/redis-stable.tar.gz 
sudo tar xvzf redis-stable.tar.gz
sudo rm redis-stable.tar -f
cd redis-stable
sudo make
echo "*****************************************"
echo " 3. Create Directories and Copy Redis Files"
echo "*****************************************"
sudo mkdir /etc/redis /var/lib/redis
sudo cp src/redis-server src/redis-cli /usr/local/bin
echo "*****************************************"
echo " 4. Configure Redis.Conf"
echo "*****************************************"
echo " Edit redis.conf as follows:"
echo " 1: ... daemonize yes"
echo " 2: ... bind 127.0.0.1"
echo " 3: ... dir /var/lib/redis"
echo " 4: ... loglevel notice"
echo " 5: ... logfile /var/log/redis.log"
echo "*****************************************"
sudo sed -e "s/^daemonize no$/daemonize yes/" -e "s/^# bind 127.0.0.1$/bind 127.0.0.1/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel verbose$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf > /etc/redis/redis.conf
echo "*****************************************"
echo " 5. Download init Script"
echo "*****************************************"
wget https://gist.githubusercontent.com/dstroot/2777433/raw/061ceb203dc7b002b073f28880f63cfa3ef9b5d2/redis-server
echo "*****************************************"
echo " 6. Move and Configure Redis-Server"
echo "*****************************************"
sudo mv redis-server /etc/init.d
sudo chmod 755 /etc/init.d/redis-server
echo "*****************************************"
echo " 7. Auto-Enable Redis-Server"
echo "*****************************************"
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
echo "*****************************************"
echo " 8. Start Redis Server"
echo "*****************************************"
sudo service redis-server start
echo "*****************************************"
echo " Complete!"
echo " You can test your redis installation using the redis console:"
echo "   $ src/redis-cli"
echo "   redis> set foo bar"
echo "   OK"
echo "   redis> get foo"
echo "   bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."

@jeetendra-choudhary

This comment has been minimized.

Show comment Hide comment
@jeetendra-choudhary

jeetendra-choudhary Feb 23, 2018

is there an ubuntu version of this as well?

jeetendra-choudhary commented Feb 23, 2018

is there an ubuntu version of this as well?

@Dev-Dipesh

This comment has been minimized.

Show comment Hide comment
@Dev-Dipesh

Dev-Dipesh Mar 2, 2018

@tushard-iprogrammer

You forgot copying redis.conf file in step 3

sudo cp redis.conf /etc/redis/redis.conf

@tushard-iprogrammer

You forgot copying redis.conf file in step 3

sudo cp redis.conf /etc/redis/redis.conf
@douglasdeodato

This comment has been minimized.

Show comment Hide comment
@douglasdeodato

douglasdeodato Apr 18, 2018

@four43

it is that version the updated one?
thanks all for the script.

https://gist.github.com/four43/e00d01ca084c5972f229

@four43

it is that version the updated one?
thanks all for the script.

https://gist.github.com/four43/e00d01ca084c5972f229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment