#!/bin/bash
read -p 'input the version you want(like 5.0.5):' version
read -p 'input redis password:' password
read -p 'input local ip: ' ip
version=${version:-5.0.5}
password=${password:-"password"}
if [ ! "$ip" ];then
echo 'must input local ip !'
exit 1
fi
# version
VERSION=redis-$version
# download path
LOAD_PATH=/tmp
# install path
INSTALL_PATH=/apps/redis
if [ ! -d $INSTALL_PATH ];then
mkdir -p $INSTALL_PATH
fi
cd /tmp
# download source package
wget http://download.redis.io/releases/$VERSION.tar.gz
# decompression
tar -xf $VERSION.tar.gz
# compile and install
cd $VERSION
make && make install PREFIX=$INSTALL_PATH
cd $INSTALL_PATH
mkdir conf
cp /tmp/$VERSION/redis.conf ./conf
#sed -i 's/logfile ""/logfile "access.log"/' conf/redis.conf
sed -i "s/# requirepass foobared/requirepass $password/" conf/redis.conf
sed -i 's/appendonly no/appendonly yes/' conf/redis.conf
sed -i 's/protected-mode no/protected-mode yes/' conf/redis.conf
sed -i "s/bind 127.0.0.1/bind 127.0.0.1 $ip/" conf/redis.conf
sed -i 's/daemonize no/daemonize yes/' conf/redis.conf
useradd redis
chown -R redis.redis $INSTALL_PATH
su - redis cd $INSTALL_PATH/bin ./redis-server ../conf/redis.conf