如何停止服务器?

时间:2021-04-29 18:30:24

I apparently have a redis-server instance running because when I try to start a new server by entering redis-server, I'm greeted with the following:

显然,我有一个redisserver实例运行,因为当我试图通过输入redis-server启动一个新服务器时,我遇到以下问题:

Opening port: bind: Address already in use

I can't figure out how to stop this server and start a new one.

我不知道如何停止这个服务器并启动一个新的服务器。

Is there any command I can append to redis-server when I'm typing in the CLI?

当我在CLI中输入时,是否有任何命令可以添加到redisserver ?

My OS is Ubuntu 10.04.

我的操作系统是Ubuntu 10.04。

18 个解决方案

#1


291  

Either connect to node instance and use shutdown command or if you are on ubuntu you can try to restart redis server through init.d:

要么连接到节点实例,要么使用关机命令,或者如果你在ubuntu上,你可以尝试重新启动redis服务器。

/etc/init.d/redis-server restart

or stop/start it:

或停止/启动它:

/etc/init.d/redis-server stop
/etc/init.d/redis-server start

On Mac

在Mac

redis-cli shutdown

#2


177  

A cleaner, more reliable way is to go into redis-cli and then type shutdown

更干净、更可靠的方法是进入redis-cli,然后输入关闭。

In redis-cli, type help @server and you will see this near the bottom of the list:

在redis-cli中,键入help @server,您将在列表底部看到以下内容:

SHUTDOWN - summary: Synchronously save the dataset to disk and then shut down the server since: 0.07

关闭-概要:同步将数据集保存到磁盘,然后自:0.07开始关闭服务器。

And if you have a redis-server instance running in a terminal, you'll see this:

如果你有一个在终端运行的redis-server实例,你会看到:

User requested shutdown...
[6716] 02 Aug 15:48:44 * Saving the final RDB snapshot before exiting.
[6716] 02 Aug 15:48:44 * DB saved on disk
[6716] 02 Aug 15:48:44 # Redis is now ready to exit, bye bye...

#3


119  

redis-cli shutdown is most effective. The accepted answer does not work for me (OSX Lion). Thanks, @JesseBuesking.

关闭-cli关闭是最有效的。公认的答案对我不起作用(OSX Lion)。谢谢,@JesseBuesking。

#4


22  

For osx I created the following aliases for starting and stopping redis (redis installed with homebrew):

对于osx,我创建了以下别名来启动和停止redis (redis安装了homebrew):

alias redstart='redis-server /usr/local/etc/redis/6379.conf'

alias redstop='redis-cli -h 127.0.0.1 -p 6379 shutdown'

This has worked great for me for local development.

这对我当地的发展很有帮助。

#5


22  

Type SHUTDOWN in the CLI

在CLI中类型关闭。

or

if your don't care about your data in memory, you may also type SHUTDOWN NOSAVE to force shutdown the server.

如果您不关心内存中的数据,那么您也可以输入SHUTDOWN NOSAVE以强制关闭服务器。

#6


14  

Try killall redis-server. You may also use ps aux to find the name and pid of your server, and then kill it with kill -9 here_pid_number.

killall redis-server试试。您也可以使用ps来查找服务器的名称和pid,然后用kill -9“here_pid_number”杀死它。

#7


11  

Option 1: go to redis installation directory and navigate to src , in my case :

选项1:转到redis安装目录并导航到src,在我的例子中:

/opt/redis3/src/redis-cli -p 6379 shutdown

where 6379 is the default port.

其中6379是默认端口。

Option 2: find redis process and kill

选项2:找到redis进程和kill。

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

And Then initiate kill:

然后开始杀:

kill -9 22292

kill -9 22299

I'm using Centos 6.7 , x86_64

我用的是Centos 6.7, x86_64。

hope it helps

希望它能帮助

#8


10  

Another way could be:

另一种可能是:

ps -ef | grep -i 'redis-server'
kill -9 PID owned by redis

Works on *NIX & OSX

在*NIX & OSX上工作。

#9


5  

If you know on what port it would be running(by default it would be 6379), you can use below command to get the pid of the process using that port and then can execute kill command for the same pid.

如果您知道它将运行哪个端口(默认情况下是6379),您可以使用下面的命令来获得使用该端口的进程的pid,然后可以执行kill命令以获得相同的pid。

sudo lsof -i : <port> | awk '{print $2}'

the above command will give you pid.

上面的命令会给你pid。

kill <pid>;

杀死< pid >;

This would shutdown your server.

这将关闭您的服务器。

#10


4  

MacOSX - It Worked :)

MacOSX -成功了:

Step 1 : Find the previously Running Redis Server

步骤1:找到之前运行的Redis服务器。

ps auxx | grep redis-server

Step 2 : Kill the specific process by finding PID (Process ID) - Redis Sever

步骤2:通过寻找PID(进程ID)来杀死特定的进程。

kill -9 PID

#11


4  

stop the redis server type in terminal with root user

在终端与根用户停止redis服务器类型。

sudo service redis-server stop

the message will be display after stop the redis-server

该消息将在停止redisserver后显示。

Stopping redis-server: redis-server.

if you want to start the redis-server type

如果您想启动redis-server类型。

sudo service redis-server start

if you want to restart the server type

如果您想重新启动服务器类型。

sudo service redis-server restart

#12


3  

In my case it was:

我的情况是:

/etc/init.d/redismaster stop
/etc/init.d/redismaster start

To find out what is your service name, you can run:

要知道您的服务名称是什么,您可以运行:

sudo updatedb
locate redis

And it will show you every Redis files in your system.

它会显示你系统中的每一个Redis文件。

#13


2  

systemd, ubuntu 16.04:

systemd,ubuntu 16.04:

$ sudo systemctl is-active redis-server
active

$ sudo systemctl is-enabled redis-server
enabled

$ sudo systemctl disable redis-server
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable redis-server
Removed /etc/systemd/system/redis.service.

$ sudo systemctl stop redis-server

#14


2  

Usually this problem arises after I shut down my computer ( or leaving running ) an irregular way.. I believe the port gets stuck open, while the process stops but continues to be bound to the previous port.

通常这个问题是在我关闭电脑(或离开运行)后出现的。我相信这个端口会被打开,进程会停止,但是会继续绑定到前一个端口。

9/10 times the fix can be:

9/10的修正量可以是:

$ ps aux | grep redis

-> MyUser 2976  0.0  0.0  2459704    320   ??  S    Wed01PM   0:29.94 redis-server *:6379

$ kill 2976

$ redis-server

Good to go.

好了。

#15


1  

I don't know specifically for redis, but for servers in general:

我不特别知道redis,但对于一般的服务器:

What OS or distribution? Often there will be a stop or /etc/init.d/... command that will be able to look up the existing pid in a pid file.

什么操作系统还是分销?通常会有一个stop或/etc/init.d/…命令将能够在pid文件中查找现有的pid。

You can look up what process is already bound to the port with sudo netstat -nlpt (linux options; other netstat flavors will vary) and signal it to stop. I would not use kill -9 on a running server unless there really is no other signal or method to shut it down.

您可以通过sudo netstat -nlpt (linux选项)查找已经绑定到端口的进程。其他netstat的口味将会有所不同,并发出停止的信号。我不会在运行的服务器上使用kill -9,除非真的没有其他的信号或方法来关闭它。

#16


1  

On MacOSX,

MacOSX,

This is what worked for me

这就是我的工作。

/etc/init.d/redis restart

/etc/init.d/redis stop

/etc/init.d/redis start

#17


1  

The commands below works for me on Ubuntu Server

下面的命令在Ubuntu服务器上为我工作。

$ service /etc/init.d/redis_6379 stop
$ service /etc/init.d/redis_6379 start
$ service /etc/init.d/redis_6379 restart

#18


0  

Another way could be :

另一种方法是:

brew services stop redis

#1


291  

Either connect to node instance and use shutdown command or if you are on ubuntu you can try to restart redis server through init.d:

要么连接到节点实例,要么使用关机命令,或者如果你在ubuntu上,你可以尝试重新启动redis服务器。

/etc/init.d/redis-server restart

or stop/start it:

或停止/启动它:

/etc/init.d/redis-server stop
/etc/init.d/redis-server start

On Mac

在Mac

redis-cli shutdown

#2


177  

A cleaner, more reliable way is to go into redis-cli and then type shutdown

更干净、更可靠的方法是进入redis-cli,然后输入关闭。

In redis-cli, type help @server and you will see this near the bottom of the list:

在redis-cli中,键入help @server,您将在列表底部看到以下内容:

SHUTDOWN - summary: Synchronously save the dataset to disk and then shut down the server since: 0.07

关闭-概要:同步将数据集保存到磁盘,然后自:0.07开始关闭服务器。

And if you have a redis-server instance running in a terminal, you'll see this:

如果你有一个在终端运行的redis-server实例,你会看到:

User requested shutdown...
[6716] 02 Aug 15:48:44 * Saving the final RDB snapshot before exiting.
[6716] 02 Aug 15:48:44 * DB saved on disk
[6716] 02 Aug 15:48:44 # Redis is now ready to exit, bye bye...

#3


119  

redis-cli shutdown is most effective. The accepted answer does not work for me (OSX Lion). Thanks, @JesseBuesking.

关闭-cli关闭是最有效的。公认的答案对我不起作用(OSX Lion)。谢谢,@JesseBuesking。

#4


22  

For osx I created the following aliases for starting and stopping redis (redis installed with homebrew):

对于osx,我创建了以下别名来启动和停止redis (redis安装了homebrew):

alias redstart='redis-server /usr/local/etc/redis/6379.conf'

alias redstop='redis-cli -h 127.0.0.1 -p 6379 shutdown'

This has worked great for me for local development.

这对我当地的发展很有帮助。

#5


22  

Type SHUTDOWN in the CLI

在CLI中类型关闭。

or

if your don't care about your data in memory, you may also type SHUTDOWN NOSAVE to force shutdown the server.

如果您不关心内存中的数据,那么您也可以输入SHUTDOWN NOSAVE以强制关闭服务器。

#6


14  

Try killall redis-server. You may also use ps aux to find the name and pid of your server, and then kill it with kill -9 here_pid_number.

killall redis-server试试。您也可以使用ps来查找服务器的名称和pid,然后用kill -9“here_pid_number”杀死它。

#7


11  

Option 1: go to redis installation directory and navigate to src , in my case :

选项1:转到redis安装目录并导航到src,在我的例子中:

/opt/redis3/src/redis-cli -p 6379 shutdown

where 6379 is the default port.

其中6379是默认端口。

Option 2: find redis process and kill

选项2:找到redis进程和kill。

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

And Then initiate kill:

然后开始杀:

kill -9 22292

kill -9 22299

I'm using Centos 6.7 , x86_64

我用的是Centos 6.7, x86_64。

hope it helps

希望它能帮助

#8


10  

Another way could be:

另一种可能是:

ps -ef | grep -i 'redis-server'
kill -9 PID owned by redis

Works on *NIX & OSX

在*NIX & OSX上工作。

#9


5  

If you know on what port it would be running(by default it would be 6379), you can use below command to get the pid of the process using that port and then can execute kill command for the same pid.

如果您知道它将运行哪个端口(默认情况下是6379),您可以使用下面的命令来获得使用该端口的进程的pid,然后可以执行kill命令以获得相同的pid。

sudo lsof -i : <port> | awk '{print $2}'

the above command will give you pid.

上面的命令会给你pid。

kill <pid>;

杀死< pid >;

This would shutdown your server.

这将关闭您的服务器。

#10


4  

MacOSX - It Worked :)

MacOSX -成功了:

Step 1 : Find the previously Running Redis Server

步骤1:找到之前运行的Redis服务器。

ps auxx | grep redis-server

Step 2 : Kill the specific process by finding PID (Process ID) - Redis Sever

步骤2:通过寻找PID(进程ID)来杀死特定的进程。

kill -9 PID

#11


4  

stop the redis server type in terminal with root user

在终端与根用户停止redis服务器类型。

sudo service redis-server stop

the message will be display after stop the redis-server

该消息将在停止redisserver后显示。

Stopping redis-server: redis-server.

if you want to start the redis-server type

如果您想启动redis-server类型。

sudo service redis-server start

if you want to restart the server type

如果您想重新启动服务器类型。

sudo service redis-server restart

#12


3  

In my case it was:

我的情况是:

/etc/init.d/redismaster stop
/etc/init.d/redismaster start

To find out what is your service name, you can run:

要知道您的服务名称是什么,您可以运行:

sudo updatedb
locate redis

And it will show you every Redis files in your system.

它会显示你系统中的每一个Redis文件。

#13


2  

systemd, ubuntu 16.04:

systemd,ubuntu 16.04:

$ sudo systemctl is-active redis-server
active

$ sudo systemctl is-enabled redis-server
enabled

$ sudo systemctl disable redis-server
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable redis-server
Removed /etc/systemd/system/redis.service.

$ sudo systemctl stop redis-server

#14


2  

Usually this problem arises after I shut down my computer ( or leaving running ) an irregular way.. I believe the port gets stuck open, while the process stops but continues to be bound to the previous port.

通常这个问题是在我关闭电脑(或离开运行)后出现的。我相信这个端口会被打开,进程会停止,但是会继续绑定到前一个端口。

9/10 times the fix can be:

9/10的修正量可以是:

$ ps aux | grep redis

-> MyUser 2976  0.0  0.0  2459704    320   ??  S    Wed01PM   0:29.94 redis-server *:6379

$ kill 2976

$ redis-server

Good to go.

好了。

#15


1  

I don't know specifically for redis, but for servers in general:

我不特别知道redis,但对于一般的服务器:

What OS or distribution? Often there will be a stop or /etc/init.d/... command that will be able to look up the existing pid in a pid file.

什么操作系统还是分销?通常会有一个stop或/etc/init.d/…命令将能够在pid文件中查找现有的pid。

You can look up what process is already bound to the port with sudo netstat -nlpt (linux options; other netstat flavors will vary) and signal it to stop. I would not use kill -9 on a running server unless there really is no other signal or method to shut it down.

您可以通过sudo netstat -nlpt (linux选项)查找已经绑定到端口的进程。其他netstat的口味将会有所不同,并发出停止的信号。我不会在运行的服务器上使用kill -9,除非真的没有其他的信号或方法来关闭它。

#16


1  

On MacOSX,

MacOSX,

This is what worked for me

这就是我的工作。

/etc/init.d/redis restart

/etc/init.d/redis stop

/etc/init.d/redis start

#17


1  

The commands below works for me on Ubuntu Server

下面的命令在Ubuntu服务器上为我工作。

$ service /etc/init.d/redis_6379 stop
$ service /etc/init.d/redis_6379 start
$ service /etc/init.d/redis_6379 restart

#18


0  

Another way could be :

另一种方法是:

brew services stop redis