• 配置Redis集群为开机自启动


    vim /etc/init.d/redisc

    将下方脚本写入redisc文件中

    #!/bin/sh
    # chkconfig: 2345 80 90
    #
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem.
    ​
    REDISPORT1=7001
    REDISPORT2=7002
    REDISPORT3=7003
    REDISPORT4=7004
    REDISPORT5=7005
    REDISPORT6=7006
    EXEC=/export/servers/redis-5.0.4/bin/redis-server
    CLIEXEC=/export/servers/redis-5.0.4/bin/redis-cli
    ​
    PIDFILE=/var/run/redis_${REDISPORT1}.pid
    ​
    CONF1="/export/servers/redis-5.0.4/cluster/${REDISPORT1}/${REDISPORT1}.conf"
    CONF2="/export/servers/redis-5.0.4/cluster/${REDISPORT2}/${REDISPORT2}.conf"
    CONF3="/export/servers/redis-5.0.4/cluster/${REDISPORT3}/${REDISPORT3}.conf"
    CONF4="/export/servers/redis-5.0.4/cluster/${REDISPORT4}/${REDISPORT4}.conf"
    CONF5="/export/servers/redis-5.0.4/cluster/${REDISPORT5}/${REDISPORT5}.conf"
    CONF6="/export/servers/redis-5.0.4/cluster/${REDISPORT6}/${REDISPORT6}.conf"
    ​
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                    echo "$PIDFILE exists, process is already running or crashed"
            else
                    echo "Starting Redis cluster server..."
                    $EXEC $CONF1 &
                    $EXEC $CONF2 &
                    $EXEC $CONF3 &
                    $EXEC $CONF4 &
                    $EXEC $CONF5 &
                    $EXEC $CONF6 &
                    echo "启动成功..."
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                    echo "$PIDFILE does not exist, process is not running"
            else
                    PID=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $CLIEXEC -p $REDISPORT1 shutdown
                    $CLIEXEC -p $REDISPORT2 shutdown
                    $CLIEXEC -p $REDISPORT3 shutdown
                    $CLIEXEC -p $REDISPORT4 shutdown
                    $CLIEXEC -p $REDISPORT5 shutdown
                    $CLIEXEC -p $REDISPORT6 shutdown
                    while [ -x /proc/${PID} ]
                    do
                        echo "Waiting for Redis cluster to shutdown ..."
                        sleep 1
                    done
                    echo "Redis cluster stopped"
            fi
            ;;
        *)
            echo "Please use start or stop as first argument"
            ;;
    esac
    

    注册为系统服务

    chkconfig --add redisc

    以后可以使用命令来控制Redis的启动和关闭

    启动:service redisc start

    关闭:service redisc stop

    配置为开机自启动

    chkconfig redisc on
    

      

  • 相关阅读:
    使用SuperWebSocket 构建实时 Web 应用
    slam for Windows 库安装及应用libfreenect2
    《SLAM十四讲》g2o_custombundle在windows轻松调通
    windows下命令行查看库依赖
    zend studio控制台中文乱码
    http协议转
    mysql 字段 增删改
    PHP内部函数
    分层设计
    SecureCRT上传和下载
  • 原文地址:https://www.cnblogs.com/alexzhang92/p/11008102.html
Copyright © 2020-2023  润新知