zoukankan      html  css  js  c++  java
  • Linux下Redis开机自启(Centos6)

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

      查找redis配置文件redis.conf

    [root@localhost /]# find / -name redis.conf
    /usr/local/redis/redis.conf

      编辑redis配置文件

    [root@localhost ~]# vim /usr/local/redis/redis.conf

    命令行模式下输入 /daemonize 查找

    将配置文件中daemonize为yes

    2、编写开机自启动脚本

    vi /etc/init.d/redis
    # chkconfig: 2345 10 90  
    # description: Start and Stop redis   
      
    PATH=/usr/local/bin:/sbin:/usr/bin:/bin   
    REDISPORT=6379  

      EXEC=/usr/local/redis/redis-server
      REDIS_CLI=/usr/local/redis/redis-cli

     PIDFILE=/var/run/redis.pid
      CONF="/usr/local/redis/redis.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   
                    if [ "$?"="0" ]   
                    then   
                            echo "Redis is running..."  
                    fi   
                    ;;   
            stop)   
                    if [ ! -f $PIDFILE ]   
                    then   
                            echo "$PIDFILE exists, process is not running."  
                    else  
                            PID=$(cat $PIDFILE)   
                            echo "Stopping..."  
                           $REDIS_CLI -p $REDISPORT  SHUTDOWN    
                            sleep 2  
                           while [ -x $PIDFILE ]   
                           do  
                                    echo "Waiting for Redis to shutdown..."  
                                   sleep 1  
                            done   
                            echo "Redis stopped"  
                    fi   
                    ;;   
            restart|force-reload)   
                    ${0} stop   
                    ${0} start   
                    ;;   
            *)   
                   echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
                    exit 1  
    esac

    3、写完后保存退出VI

    4、设置权限

    [root@localhost init.d]# chmod 777 /etc/init.d/redis

    5、启动测试

    /etc/init.d/redis start

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

    [root@localhost init.d]# /etc/init.d/redis start
    /etc/init.d/redis: line 1: kconfig:: command not found
    Starting Redis server...
    4046:C 05 Jan 2019 12:00:02.611 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    4046:C 05 Jan 2019 12:00:02.611 # Redis version=5.0.0, bits=32, commit=00000000, modified=0, pid=4046, just started
    4046:C 05 Jan 2019 12:00:02.611 # Configuration loaded
    Redis is running...

    使用redis-cli测试:(可能会出现auth认证问题,应该是设置了认证密码,输入密码既可以啦

    [root@localhost init.d]# redis-cli
    127.0.0.1:6379> set fgf 123456
    (error) NOAUTH Authentication required.
    127.0.0.1:6379> auth 123456
    OK
    127.0.0.1:6379> set fgf 123
    OK
    127.0.0.1:6379> get fgf
    "123"
    127.0.0.1:6379> 

    6、设置开机自启动

    [root@localhost init.d]# chkconfig redis on

    7、关机重启测试

    reboot

    然后在用redis-cli测试即可











    
    
  • 相关阅读:
    onkeypress事件.onkeydown事件.onkeyup事件
    汉诺塔递归算法拙见
    《编写可读代码的艺术》读后总结
    select下拉菜单反显不可改动,且submit能够提交数据
    Freemarker list 的简单使用
    Freemarker导出带格式的word的使用
    Freemarker导出word的简单使用
    Freemarker取list集合中数据(将模板填充数据后写到客户端HTML)
    struts2在配置文件与JSP中用OGNL获取Action属性
    Web下文件上传下载的路径问题
  • 原文地址:https://www.cnblogs.com/clubs/p/10223775.html
Copyright © 2011-2022 走看看