概要
在Redis中我们通常会修改redis.conf来配置我们的Redis,但是配置完后需要重启Redis才能生效,下面我将分享我学习到的两种重启方式,
推荐使用第二种
技术细节
1、kill -9 Redis进程号
# 在包含Redis配置文件和bin文件夹的目录下执行下面命令会启动redis
./bin/redis-server redis.conf
# 运行下面的命令查看Redis的进程号
ps -ef|grep redis
# 杀死该进程
kill -9 8993
# 再一次启动Redis
./bin/redis-server redis.conf
上述查看Redis的进程号的命令,运行结果如下:
2、通过客户端告诉Redis服务器重新启动(安全)
# 在包含bin文件夹的目录下执行下面命令停止redis服务
./bin/redis-cli -h 192.168.200.128 shutdown
# 再一次启动Redis
./bin/redis-server redis.conf
上述的192.168.200.128
是 redis.conf
中配置的redis服务器启动的机器的地址,一般为localhost或者Linux虚拟机的IP地址
可能出现的错误
# 在包含bin文件夹的目录下执行下面命令连接redis
./bin/redis-cli -h 192.168.200.128
可能会出下下面的错误:
(error) DENIED Redis is running in protected mode because protected mode is enabled and no password is set for the default user. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option. 4) Set up an authentication password for the default user. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
192.168.200.128:6379> ping
Error: Connection reset by peer
我第一次在虚拟机上启动时就出现了此错误,解决办法如下:
1、进入Redis的配置文件
vim redis.conf
2、找到下面两个配置,修改为no文章来源:https://www.toymoban.com/news/detail-822575.html
protected-mode no
daemonize no
3、使用第一种方法重启Redis
4、如果发送ping还是不能返回PONG,那么关闭虚拟机重新启动
我的到这一步就好了,希望对大家有帮助。文章来源地址https://www.toymoban.com/news/detail-822575.html
到了这里,关于Linux中重启Redis的两种方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!