我正在尝试远程访问托管在我的小型 Debian 服务器上的 redis 数据库,但我无法让它工作。希望有人能帮我解决这个问题。
这是我采取的步骤。
我已经根据 this 设置了我的 redis教程。 使用提供的安装 shell 脚本,我得到以下日志,其中显示了所有已创建的目录/文件:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
现在我可以使用 service redis_6379 start/stop/restart
启动/停止/重启。
此时,我能够在本地连接到我的 redis。
root@smg:/home/local: redis-cli ping
PONG
这是我的日志输出。
12505:M 11 Jun 16:18:48.248 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
12505:M 11 Jun 16:18:48.248 # Server initialized
12505:M 11 Jun 16:18:48.248 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
12505:M 11 Jun 16:18:48.249 * DB loaded from disk: 0.000 seconds
12505:M 11 Jun 16:18:48.249 * Ready to accept connections
我继续修改 redis/6379.conf
中 Networking 下的绑定(bind)设置以绑定(bind)到 bind 0.0.0.0
这应该允许所有 IP 连接到我的服务器使用端口 6379。
我还为 iptables 设置了一个传入规则,看起来像这样 -A INPUT -p tcp -m tcp --dport 6379 -j ACCEPT
。
如果需要,我可以提供完整的 iptables 日志。
我重新启动了我的 redis。使用 ps aux | 检查grep redis
我确认我的服务器正在运行。
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 12505 0.0 0.1 43216 4008 ? Ssl 16:18 0:08 /usr/local/bin/redis-server *:6379
我现在检查我的 redis 是否真的在所有端口上监听。所以我检查了 netstat -nlpt | grep 6379
并获得以下输出。我认为输出确认 Redis 正在监听所有外部 IP,但我不太确定。
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 12505/redis-server
现在基本上一切都已为远程连接设置好,但如果我尝试从我的服务器连接,我会收到连接超时。
root@smg:/home/local: redis-cli -h [serverIP]
Could not connect to Redis at [serverIP]:6379: Connection timed out
我在 StackOverflow 上的许多线程中看到了 Connection Refused
错误,但与连接超时无关。
我真的不知道为什么会出现此超时。希望你们中的一个人对此有更多了解。
提前致谢!
最佳答案
我的 friend 。
警告:无法强制执行 511 的 TCP 积压设置,因为/proc/sys/net/core/somaxconn 设置为较低的值 128。
更改/proc/sys/net/core/somaxconn
sysctl -w net.core.somaxconn=65535
在/etc/sysctl.conf 中更改为 vm.overcommit_memory = 1
关于bash - 远程访问redis。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50802908/