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测试即可











    
    
  • 相关阅读:
    ZOJ 1002 Fire Net
    Uva 12889 One-Two-Three
    URAL 1881 Long problem statement
    URAL 1880 Psych Up's Eigenvalues
    URAL 1877 Bicycle Codes
    URAL 1876 Centipede's Morning
    URAL 1873. GOV Chronicles
    Uva 839 Not so Mobile
    Uva 679 Dropping Balls
    An ac a day,keep wa away
  • 原文地址:https://www.cnblogs.com/clubs/p/10223775.html
Copyright © 2011-2022 走看看