Skip to content

Instantly share code, notes, and snippets.

@khelll
Last active March 12, 2024 08:33
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save khelll/ff9461bfda8ebfdc488e to your computer and use it in GitHub Desktop.
Save khelll/ff9461bfda8ebfdc488e to your computer and use it in GitHub Desktop.
Installing Redis on Amazon Linux
#!/bin/bash
###############################################
# To use:
# chmod +x install-redis.sh
# ./install-redis.sh
###############################################
version=3.2.0
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 $version"
echo "*****************************************"
cd /usr/local/src
sudo wget "http://download.redis.io/releases/redis-$version.tar.gz"
sudo tar xzf redis-$version.tar.gz
sudo rm redis-$version.tar.gz -f
cd redis-$version
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-$version/src/redis-cli"
echo " redis> set foo bar"
echo " OK"
echo " redis> get foo"
echo " bar"
echo "*****************************************"
read -p "Press [Enter] to continue..."
@iainlbc
Copy link

iainlbc commented Jan 6, 2017

Thanks, needed up something up quickly for hackathon and this came in handy 👍

@adityamertia
Copy link

Hi,
I used version=4.0.6 the latest version.
Ran this script and the compilation was done smoothly, however while service starting it was stuck at a point listed below. If i check the redis server was up and running but im not sure why i had to CTRL-C to exit the program. I did not see "Press [ENTER] to continue..."

=============================================
Location: https://raw.githubusercontent.com/saxenap/install-redis-amazon-linux-centos/master/redis-server [following]
--2018-01-11 11:31:36-- https://raw.githubusercontent.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.32.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.32.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2025 (2.0K) [text/plain]
Saving to: ‘redis-server’

100%[==================================================================================>] 2,025 --.-K/s in 0s

2018-01-11 11:31:36 (36.1 MB/s) - ‘redis-server’ saved [2025/2025]


  1. Move and Configure Redis-Server


  1. Auto-Enable Redis-Server


  1. Start Redis Server

Starting redis-server (via systemctl):
^C

This is where its stuck and i had to press CTRL-C to come out. Am i missing something?

@dleber
Copy link

dleber commented Jun 17, 2018

Thanks for the script.

Just a couple tips in case it helps others.

I was using version 4.0.1 & Amazon Linux, and found redis-cli located at:
/usr/local/src/redis-$version/src/redis-cli
Instead of (line 62)
/usr/local/redis-$version/src/redis-cli

I also adjusted $PATH by adding the following in the ~/.bashrc file:
export PATH="$PATH:/usr/local/src/redis-4.0.1/src"
And finally I refreshed the change with
source ~/.bashrc

Now I can start the client any time with
redis-cli

@jpickwell
Copy link

@dleber, you don't need that since redis-server and redis-cli are copied to /usr/local/bin which should already be on your PATH. I don't know why the test text refers to the source directory. It should just say redis-cli without any path.

@JustDoItGit
Copy link

thank you very much.
非常感谢。

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