当前位置:   article > 正文

Linux下安装redis并修改配置文件,并设置开机自启_redis备份一份config并且修改启动

redis备份一份config并且修改启动

1.拷贝安装包到/home/redis文件夹

.

2.解压安装包 tar -zxvf 安装包

3.编译解压redis文件到指定文件夹/usr/redis下

4.复制配置文件信息到编译文件夹下

5.编辑配置文件redis.conf     vi redis.conf

6.修改配置文件,默认后台启动

7.配置redis的密码

8.配置允许外界访问

9.关闭防火墙

10.根据配置启动redis

11.测试连接 

2.设置redis开机自启

1.创建开机自启文件 redis-auto ,修改REDISPATH , 填入自己的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. #配置自己安装的redis根目录
  14. REDISPATH=/usr/redis/bin
  15. EXEC=${REDISPATH}/redis-server
  16. CLIEXEC=${REDISPATH}/redis-cli
  17. PIDFILE=/var/run/redis_${REDISPORT}.pid
  18. CONF="${REDISPATH}/redis.conf"
  19. case "$1" in
  20. start)
  21. if [ -f $PIDFILE ]
  22. then
  23. echo "$PIDFILE exists, process is already running or crashed"
  24. else
  25. echo "Starting Redis server..."
  26. $EXEC $CONF
  27. fi
  28. ;;
  29. stop)
  30. if [ ! -f $PIDFILE ]
  31. then
  32. echo "$PIDFILE does not exist, process is not running"
  33. else
  34. PID=$(cat $PIDFILE)
  35. echo "Stopping ..."
  36. $CLIEXEC -p $REDISPORT shutdown
  37. while [ -x /proc/${PID} ]
  38. do
  39. echo "Waiting for Redis to shutdown ..."
  40. sleep 1
  41. done
  42. echo "Redis stopped"
  43. fi
  44. ;;
  45. *)
  46. echo "Please use start or stop as first argument"
  47. ;;
  48. esac

2.将开机自启文件放到  /etc/init.d/ 目录下

3.设置文件redis-auto的权限,让Linux可以执行

chmod 755 /etc/init.d/redis-auto  

4.设置开机自启动,即:

chkconfig redis-auto on

5.远程连接需要关闭防火墙服务

systemctl disable firewalld

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/547380
推荐阅读
相关标签
  

闽ICP备14008679号