1.安装编译工具(yum -y install make gcc gcc-c++ ncurses-devel)2

2.安装tcl依赖 yum -y install tcl

3.上传redis安装包并解压tar -zxvf redis-stable.tar.gz

4.进入解压后的目录执行make

5.进入src目录执行make test

6.拷贝src目录下文件到指定目录

  1. cp -p redis-server /usr/local/bin
  2. cp -p redis-benchmark /usr/local/bin
  3. cp -p redis-cli /usr/local/bin
  4. cp -p redis-check-dump /usr/local/bin
  5. cp -p redis-check-aof /usr/local/bin
  6. cp -p redis.conf /usr/local/bin

7.设置开机启动,后台启动

  1. vi redis.conf  #编辑
  2. daemonize yes  #设置后台启动redis
  3. :wq! #保存退出
  4. redis-server /etc/redis.conf  #启动redis服务
  5. redis-cli shutdown  #关闭redis

8.添加内核参数(必须,否则MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk.

  vi /etc/sysctl.conf #编辑,在最后一行添加下面代码

  vm.overcommit_memory = 1

  :wq! #保存退出

  sysctl -p #使设置立即生效

9.添加服务

  vi /etc/init.d/redis   #编辑,添加以下代码

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac

  :wq! #保存退出

配置开机启动

redis文件添加

#!/bin/sh

# chkconfig: 2345 90 10

# description: Redis is a persistent key-value database

chkconfig --add redis  #添加开启启动

  #chmod 755 /etc/init.d/redis  #添加脚本执行权限

  

  #chkconfig --level 2345 redis on  #设置启动级别

  #chkconfig --list redis  #查看启动级别

  service redis restart  #重新启动redis

04-28 08:03