3

我无法通过初始化脚本关闭我的 redis 服务器。当我这样做时,这会产生巨大的副作用,即挂起我的机器sudo reboot

我使用规范指南新安装了 redis ,将其配置为接受 unix 套接字上的连接,现在正尝试停止服务器,以便我可以恢复以前保存的 .rdb 转储。

但我不断收到以下信息:

Could not connect to Redis at 127.0.0.1:0: Connection refused
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...

我使用的命令是sudo /etc/init.d/redis-server stop. 请注意,shutdown连接到 后我仍然可以发出问题redis-cli -s /var/run/redis.sock,但我需要初始化脚本才能工作。

为什么redis不会关闭,我该如何解决这种情况?版本是Redis server v=4.0.2 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=8ddba2e6a24ce078


我很自然地port 0在配置文件中设置了unixsocket /var/run/redis.sockunixsocketperm 755.

此外,脚本文件的内容是:

!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=0
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/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
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

注意REDISPORT=0,应该如此。目前,这并不真正支持停止和启动 redis 服务器。

4

1 回答 1

0

我对问题中发布的初始化脚本进行了自定义。我不得不让 redis 的初始化脚本支持基于 unix 套接字的关闭。它不支持该 OOTB。

这是我的脚本最终的样子:

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=0
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

REDISSOCKET="/var/run/redis.sock"

PIDFILE=/var/run/redis.pid
CONF="/etc/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
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                echo "Stopping ..."
                PID=$(cat $PIDFILE)
                if [ $REDISPORT -eq 0 ] && [ -n "$REDISSOCKET" ]
                then
                        $CLIEXEC -s $REDISSOCKET shutdown
                else
                        $CLIEXEC -p $REDISPORT shutdown
                fi
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

更改脚本后,尝试发布sudo service redis-server stop. 如果 redis-server 被添加到必要的运行级别,它应该可以工作。

否则就试试吧sudo /etc/init.d/redis-server stop


注意:这里解决了类似的问题:https ://groups.google.com/forum/#!topic/redis-db/o-fC_B-fjPs

于 2017-10-04T21:34:42.147 回答