安装包下载地址

下载安装包至安装目录

  1. wget http://download.redis.io/releases/redis-5.0.7.tar.gz

解压安装包

  1. tar -zxvf redis-5.0.7.tar.gz

编译

  1. cd redis-5.0.7
  2. make
  3. cd src
  4. make install

创建服务目录

  1. mkdir /usr/local/redis
  2. mkdir /usr/local/redis/bin
  3. mkdir /usr/local/redis/conf

复制文件

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

修改配置文件 redis.conf

  1. # 注释掉,允许远程访问
  2. #bind 127.0.0.1
  3. # 关闭保护模式,允许远程访问
  4. protected-mode no
  5. # 启用守护进程
  6. daemonize yes
  7. # 密码
  8. requirepass 123456

配置为系统服务

目录/etc/init.d/redis

  1. #!/bin/sh
  2. # chkconfig: 2345 90 10
  3. # Simple Redis init.d script conceived to work on Linux systems
  4. # as it does use of the /proc filesystem.
  5. REDISPORT=6379
  6. EXEC=/usr/local/redis/bin/redis-server
  7. CLIEXEC=/usr/local/redis/bin/redis-cli
  8. PIDFILE=/usr/local/redis/redis.pid
  9. CONF="/usr/local/redis/conf/redis.conf"
  10. case "$1" in
  11. start)
  12. if [ -f $PIDFILE ]
  13. then
  14. echo "$PIDFILE exists, process is already running or crashed"
  15. else
  16. echo "Starting Redis server..."
  17. $EXEC $CONF &
  18. fi
  19. ;;
  20. stop)
  21. if [ ! -f $PIDFILE ]
  22. then
  23. echo "$PIDFILE does not exist, process is not running"
  24. else
  25. PID=$(cat $PIDFILE)
  26. echo "Stopping ..."
  27. $CLIEXEC -p $REDISPORT shutdown
  28. while [ -x /proc/${PID} ]
  29. do
  30. echo "Waiting for Redis to shutdown ..."
  31. sleep 1
  32. done
  33. echo "Redis stopped"
  34. fi
  35. ;;
  36. *)
  37. echo "Please use start or stop as first argument"
  38. ;;
  39. esac

配置生效

  1. chkconfig --add redis

启动

  1. service redis start