Run multiple Redis instances in Ubuntu
March 8, 2019
If you run a Redis instance on your Ubuntu server and would like run an another Redis instance on the server, here’s how you can do so. Download the source code of the version of Redis you wish to install
export REDIS_VERSION="2.8.4"
mkdir -p ~/builds
cd ~/builds
wget http://download.redis.io/releases/redis-${REDIS_VERSION}.tar.gz
Compile it
tar xvzf redis-${REDIS_VERSION}.tar.gz
cd redis-${REDIS_VERSION}
make
Ensure the compiled redis binary works correctly
sudo apt-get update && apt-get install -y tcl8.5
make test
Install redis
sudo mkdir -p /usr/local/Cellar/redis/$REDIS_VERSION/
sudo make PREFIX=/usr/local/Cellar/redis/$REDIS_VERSION/ install
sudo chown -R $USERNAME /usr/local/Cellar/redis/
Symlink the redis-server
and redis-cli
binaries
cd /usr/local/bin
sudo ln -s /usr/local/Cellar/redis/$REDIS_VERSION/bin/redis-server redis-server-${REDIS_VERSION}
sudo ln -s /usr/local/Cellar/redis/$REDIS_VERSION/bin/redis-cli redis-cli-${REDIS_VERSION}
Create the redis config file
sudo mkdir -p /etc/redis
sudo cp ~/builds/redis-${REDIS_VERSION}/redis.conf /etc/redis/redis-${REDIS_VERSION}.conf
and configure redis
sudo vim /etc/redis/redis-${REDIS_VERSION}.conf
Create a systemd unit file to start/stop redis
cd /etc/systemd/system/
sudo wget https://gist.githubusercontent.com/nisanth074/e50927870749b9d825ea831759c11c64/raw/77d14455141e8e5730eef8826236aa95a83965dc/redis-server.service.erb
sudo erb redis-server.service.erb > redis-server-${REDIS_VERSION}.service
sudo rm redis-server.service.erb
In case you’re on a version of Ubuntu that was released prior to Ubuntu’s switch to systemd, create an init script
cd /etc/init.d/
sudo wget https://gist.githubusercontent.com/nisanth074/e50927870749b9d825ea831759c11c64/raw/0dcbee0eb002006f189eebb714d811cee4720482/redis-server.erb
sudo erb redis-server.erb > redis-server-${REDIS_VERSION}
sudo rm redis-server.erb
Start redis
# If Ubuntu 15.04 or newer
sudo systemctl start redis-server-$REDIS_VERSION
# Otherwise
sudo /etc/init.d/redis-sever
Configure Ubuntu to start Redis at boot time
# If Ubuntu 15.04 or newer
sudo systemctl enable redis-server-#{REDIS_VERSION}
# Otherwise
sudo update-rc.d redis-server defaults