Centos下配置Redis开机启动

前端之家收集整理的这篇文章主要介绍了Centos下配置Redis开机启动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、设置redis.conf中daemonize为yes,确保守护进程开启。

2、编写开机自启动脚本

vi /etc/init.d/redis

脚本内容如下:

  1. #!/bin/bash
    #chkconfig: 2345 80 90
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem.
    # description: Start and Stop redis
  2. PATH=/usr/local/bin:/sbin:/usr/bin:/bin
  3. #redis端口号
  4. REDISPORT=6379
  5. #redis-server所在目录的绝对路径
  6. EXEC=/usr/apk/redis-2.8.17/redis-server
  7. #redis-cli所在目录的绝对路径
  8. REDIS_CLI=/usr/apk/redis-2.8.17/redis-cli
  9. PIDFILE=/var/run/redis.pid
  10. #redis.conf所在目录的绝对路径
  11. CONF="/usr/apk/redis-2.8.17/redis.conf"
  12. AUTH="Nginx"
  13. case"$1"in
  14. start)
  15. if[-f$PIDFILE]
  16. then
  17. echo"$PIDFILEexists,processisalreadyrunningorcrashed."
  18. else
  19. echo"StartingRedisserver..."
  20. $EXEC$CONF
  21. fi
  22. if["$?"="0"]
  23. then
  24. echo"Redisisrunning..."
  25. ;;
  26. stop)
  27. if[!-f$PIDFILE]
  28. echo"$PIDFILEexists,processisnotrunning."
  29. else
  30. PID=$(cat$PIDFILE)
  31. echo"Stopping..."
  32. $REDIS_CLI-p$REDISPORTSHUTDOWN
  33. sleep2
  34. while[-x$PIDFILE]
  35. do
  36. echo"WaitingforRedistoshutdown..."
  37. sleep1
  38. done
  39. echo"Redisstopped"
  40. fi
  41. ;;
  42. restart|force-reload)
  43. ${0}stop
  44. ${0}start
  45. *)
  46. echo"Usage:/etc/init.d/redis{start|stop|restart|force-reload}">&2
  47. exit1
  48. esac

写完后保存退出VI

3、设置权限

chmod 755 /etc/init.d/redis

4,设定开机启动服务
[html] view plain copy
  1. sudochkconfigredison
5,启动,停止redis

启动成功会提示如下信息:

@H_296_403@Starting Redis server... Redis is running...

使用redis-cli测试:

[root@rk ~]# /usr/redisbin/redis-@H_296_403@cli 127.0.0.1:6379> set@H_296_403@ foo bar OK get@H_296_403@ foo "bar" 6379> exit

6、关机重启测试

reboot

然后在用redis-cli测试即可。

猜你在找的CentOS相关文章