Linux中安装Redis
官网:https://redis.io/download
http://www.jianshu.com/p/cc403be7f80d(如果出现错误请见)
下载redis:
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
解压
tar -zxvf redis-4.0.8.tar.gz -C /usr/local/
进入redis目录
cd /usr/local/redis-4.0.8
编译
make
安装(PREFIX安装指定目录 否则安装到/usr/local/bin里面了)
make install PREFIX=/usr/local/redis
复制redis配置文件到安装目录
cp /usr/local/redis-4.0.8/redis.conf /usr/local/redis/
启动redis服务
进入目录
cd /usr/local/redis
启动服务、连接服务
./bin/redis-server
./bin/redis-cli
redis设置开机自启脚本
vi /etc/init.d/redis
粘贴以下内容(修改路径)
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
# redis端口号
REDISPORT=6379
# redis-server所在目录的绝对路径
EXEC=/usr/local/redis/bin/redis-server
# redis-cli所在目录的绝对路径
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis.pid
# redis.conf所在目录的绝对路径
CONF="/usr/local/redis/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed."
else
echo "Starting Redis server..."
nohup $EXEC $CONF >/dev/null 2>&1 &
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE exists, process is not running."
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
sleep 2
while [ -x $PIDFILE ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
##将redis做成服务、给定执行权限、设置开机自启
chmod 755 /etc/init.d/redis
chkconfig --add redis
chkconfig --level 2345 redis on
chkconfig --list redis