使用自制程序安装Redis,但当我尝试ping Redis时,它显示这个错误:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
注意: 我尝试关闭防火墙并编辑conf文件,但仍然无法ping通。 我使用的是macOS Sierra和自制版本1.1.11
使用自制程序安装Redis,但当我尝试ping Redis时,它显示这个错误:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
注意: 我尝试关闭防火墙并编辑conf文件,但仍然无法ping通。 我使用的是macOS Sierra和自制版本1.1.11
当前回答
日期:2021年12月
这个错误有几个原因。我读了一篇文章来解决这个问题。所以我就逐一总结一下要检查什么。
1检查:Redis-Server未启动
redis-server
Also to run Redis in the background, the following command could be used.
redis-server --daemonize yes
2. 检查:防火墙限制
sudo ufw status (inactive)
sudo ufw active (for making active it might disable ssh when first time active. So enable port 22 to access ssh.)
sudo ufw allow 22
sudo ufw allow 6379
3.检查:资源使用情况
ps -aux | grep redis
4. 配置设置限制
sudo vi /etc/redis/redis.conf.
注释下面的行。
# bind 127.0.0.1 ::1
注意:恶意行为者将更难发出请求或访问您的服务器。确保您绑定到正确的IP地址网络。
希望它能帮助到别人。欲了解更多信息,请阅读下面的文章。
https://bobcares.com/blog/could-not-connect-to-redis-connection-refused/
其他回答
我使用的是Ubuntu 18.04 我刚刚在CMD中输入了这个命令 Sudo systemctl start redis-server 现在它正在发挥作用。所以我认为我的redis服务器没有启动,为什么它显示我的错误 无法连接到Redis 127.0.0.1:6379:连接被拒绝。
Mac版Redis:
1-酿造安装redis 2-酿造服务启动redis 3- redis-cli ping
$ brew services start redis
$ brew services stop redis
$ brew services restart redis
午餐自动启动选项:
$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
# autostart activate
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
# autostart deactivate
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Redis conf默认路径:/usr/local/etc/redis.conf
就像Aaron一样,在我的案例中,brew services list声称redis正在运行,但实际上并没有。我在/usr/local/var/log/redis.log的日志文件中发现了以下信息:
4469:C 28 Feb 09:03:56.197 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4469:C 28 Feb 09:03:56.197 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=4469, just started
4469:C 28 Feb 09:03:56.197 # Configuration loaded
4469:M 28 Feb 09:03:56.198 * Increased maximum number of open files to 10032 (it was originally set to 256).
4469:M 28 Feb 09:03:56.199 # Creating Server TCP listening socket 192.168.161.1:6379: bind: Can't assign requested address
这是由以下配置引起的:
bind 127.0.0.1 ::1 192.168.161.1
这是让我的VMWare Fusion虚拟机访问macOS主机上的redis服务器所必需的。但是,如果虚拟机没有启动,这个绑定失败会导致redis根本不启动。所以启动虚拟机就解决了这个问题。
首先,您需要使用以下命令启动/启动所有redis节点,一个接一个地启动所有的conf文件。 @注:如果你正在建立集群,那么你应该有6个节点,3个主节点和3个从节点。Redis-cli将使用——cluster命令从6个节点中自动选择主节点和从节点,如下所示。
[xxxxx@localhost redis-stable]$ redis-server xxxx.conf
然后运行
[xxxxx@localhost redis-stable]$ redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
上述输出应如下:
>>> Performing hash slots allocation on 6 nodes...
自动设置所有东西的第二种方法: 您可以使用utils/create-cluster脚本来设置您喜欢的任何东西 启动所有节点,创建集群 你可以关注https://redis.io/topics/cluster-tutorial
谢谢
如果安装后你需要一直运行redis,只需输入terminal:
redis-server &
在Ubuntu上使用upstart运行redis
我一直在试图理解如何从头开始在Ubuntu上安装系统。我只是在盒子上安装了redis,这里是我是怎么做的,还有一些事情要注意。
如何安装:
sudo apt-get install redis-server
这将创建一个redis用户并安装init。D脚本。因为upstart现在是使用init的替代品。d,我认为我应该将其转换为使用upstart运行。
禁用默认的init。redis D脚本:
sudo update-rc.d redis-server disable
然后使用以下脚本创建/etc/init/redis-server.conf:
description "redis server"
start on runlevel [23]
stop on shutdown
exec sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf
respawn
这是upstart的脚本,让upstart知道要运行什么命令来启动进程。最后一行还告诉新贵,如果它死了,要继续尝试重生。
我必须在/etc/redis/redis.conf中修改的一件事是daemonize yes改为daemonize no。如果你不改变它会发生什么,redis-server会fork并守护自己,并且父进程会消失。当这种情况发生时,upstart认为进程已经死亡/停止,您将无法从upstart内部控制进程。
现在你可以使用下面的命令来控制你的redis-server:
sudo start redis-server
sudo restart redis-server
sudo stop redis-server
希望这对你有帮助!