1. 下载上传解压

1.1下载

image.png

1.2 上传

  1. $ rz redis-5.0.14.tar.gz

image.png

1.3 解压编译安装

  1. $ tar -zvxf redis-5.0.14.tar.gz
  1. $ cd redis-5.0.14
  2. $ make
  1. $ make PREFIX=/usr/local/redis/redis-5.0.14 install

2. 启动

  1. $ cd redis-5.0.14
  2. $ ./bin/redis-server& ./redis.conf

image.png

3. 配置

  1. 编辑redis.conf配置文件

image.png
image.png

3.1 配置环境变量

  1. $ vim /etc/profile
  1. export PATH=$PATH:/usr/local/redis/redis-5.0.14/src
  1. $ source /etc/profile

在任意地方 输入 redis-server 或 redis-cli 即可使用redis

3.2 开启守护线程

  1. daemonize 改为 yes ;

3.3 允许远程访问

  1. protected-mode 改为 no
  2. bind 127.0.0.1 改为 bind *

4. 端口开放

  1. $ firewall-cmd --add-port=6379/tcp --permanent
  2. $ firewall-cmd --reload

5. 作为服务启动

定位到redis的tar包所在位置,将redis中的utils中的redis_init_script复制到/etc/rc.d/init.d中,重命名为redis

  1. cp /{redis解压包所在目录}/utils/redis_init_script /etc/rc.d/init.d/redis
  1. vi /etc/rc.d/init.d/redis
  1. #!/bin/sh
  2. #
  3. # Simple Redis init.d script conceived to work on Linux systems
  4. # as it does use of the /proc filesystem.
  5. ### BEGIN INIT INFO
  6. # Provides: redis_6379
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Redis data structure server
  10. # Description: Redis data structure server. See https://redis.io
  11. ### END INIT INFO
  12. REDISPORT=6379
  13. EXEC=/home/flying/program/redis-5.0.14/bin/redis-server #实际环境而定
  14. CLIEXEC=/home/flying/program/redis-5.0.14/bin/redis-cli #实际环境而定
  15. PIDFILE=/var/run/redis_${REDISPORT}.pid
  16. CONF="/home/flying/download/redis-5.0.14/redis.conf" #实际环境而定
  17. case "$1" in
  18. start)
  19. if [ -f $PIDFILE ]
  20. then
  21. echo "$PIDFILE exists, process is already running or crashed"
  22. else
  23. echo "Starting Redis server..."
  24. $EXEC $CONF
  25. fi
  26. ;;
  27. stop)
  28. if [ ! -f $PIDFILE ]
  29. then
  30. echo "$PIDFILE does not exist, process is not running"
  31. else
  32. PID=$(cat $PIDFILE)
  33. echo "Stopping ..."
  34. $CLIEXEC -p $REDISPORT shutdown
  35. while [ -x /proc/${PID} ]
  36. do
  37. echo "Waiting for Redis to shutdown ..."
  38. sleep 1
  39. done
  40. echo "Redis stopped"
  41. fi
  42. ;;
  43. *)
  44. echo "Please use start or stop as first argument"
  45. ;;
  46. esac
  1. $ chmod 755 /etc/init.d/redis
  2. $ chkconfig redis on # 开启服务自启动
  3. $ service redis start #启动redis
  4. $ service redis stop #关闭redis
  5. $ reboot
  6. $ ps -fe | grep redis #检查是否启动