我显然有一个redis-server实例正在运行,因为当我试图通过输入redis-server启动一个新服务器时,我受到以下欢迎:
Opening port: bind: Address already in use
我不知道如何停止这个服务器,并启动一个新的。
当我在CLI中输入时,是否有任何命令可以附加到redis-server ?
我的操作系统是Ubuntu 10.04。
我显然有一个redis-server实例正在运行,因为当我试图通过输入redis-server启动一个新服务器时,我受到以下欢迎:
Opening port: bind: Address already in use
我不知道如何停止这个服务器,并启动一个新的。
当我在CLI中输入时,是否有任何命令可以附加到redis-server ?
我的操作系统是Ubuntu 10.04。
当前回答
要优雅地使用密码关闭特定实例,而不诉诸于暴力杀死命令,请使用:
Redis-cli -p <port> -a <pass> shutdown
root@machine:~# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 105 0.1 0.0 60552 10772 ? Ssl 23:27 0:02 redis-server 127.0.0.1:10002
root 111 0.1 0.0 60552 10900 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10003
root 117 0.1 0.0 60552 10872 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10004
root@machine:~# redis-cli -p 10002 -a mypassword shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
root@machine:~# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 111 0.1 0.0 60552 10900 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10003
root 117 0.1 0.0 60552 10872 ? Ssl 23:28 0:02 redis-server 127.0.0.1:10004
root@machine:~#
如果有大量的实例,就需要编写一个批处理脚本来循环遍历所有实例,以便主关机。
其他回答
试试杀死所有redis-server。您还可以使用ps aux来查找服务器的名称和pid,然后使用kill -9 here_pid_number终止它。
我不知道redis的具体情况,但对于一般的服务器来说:
什么操作系统或发行版?通常会有一个stop或/etc/init.d/…命令,该命令能够在pid文件中查找现有的pid。
您可以使用sudo netstat -nlpt (linux options;其他netstat口味会有所不同),并发出停止的信号。我不会在运行中的服务器上使用kill -9,除非真的没有其他信号或方法来关闭它。
在CLI中输入SHUTDOWN
or
如果你不关心内存中的数据,你也可以输入SHUTDOWN NOSAVE来强制关闭服务器。
Redis有配置参数pidfile(例如/etc/redis.conf -检查Redis源代码),例如:
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
pidfile /var/run/redis.pid
如果它已经设置或可以设置,可以使用ps + grep来搜索进程id (pid),而不是像这样使用:
kill $(cat /var/run/redis.pid)
如果需要,一个可以使redis停止脚本像这样(改编默认redis 5.0初始化。D脚本在redis源代码):
PIDFILE=/var/run/redis.pid
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
kill $PID
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
选项1:进入redis安装目录并导航到src,在我的情况下:
/opt/redis3/src/redis-cli -p 6379 shutdown
其中6379为默认端口。
选项2:查找redis进程并杀死
ps aux | grep redis-server
t6b3fg 22292 0.0 0.0 106360 1588 pts/0 S+ 01:19 0:00 /bin/sh /sbin/service redis start
t6b3fg 22299 0.0 0.0 11340 1200 pts/0 S+ 01:19 0:00 /bin/sh /etc/init.d/redis start
然后启动kill:
kill -9 22292
kill -9 22299
我使用的是Centos 6.7, x86_64
希望能有所帮助