我正在运行 Ubuntu 服务器 20.04 LAMP,带有 Redis 5.0.7。
问题:
当配置了 unix 套接字时,port 0
Redis 将拒绝所有连接。
基本的/etc/redis/redis.conf
:
# create a unix domain socket to listen on
unixsocket /var/run/redis/redis.sock
# set permissions for the socket
unixsocketperm 775
bind 127.0.0.1
daemonize yes
stop-writes-on-bgsave-error no
rdbcompression yes
# maximum memory allowed for redis
maxmemory 50M
# how redis will evice old objects - least recently used
maxmemory-policy allkeys-lru
# tells redis to ignore TCP ports
port 0
#creates pidfile
pidfile /run/redis/redis-server.pid
插座:
# ls -lh /var/run/redis
total 4.0K
-rw-rw---- 1 redis redis 5 Jul 30 18:23 redis-server.pid
srwxrwxr-x 1 redis redis 0 Jul 30 18:23 redis.sock
监听端口:
# ps aux | grep redis
redis 4912 0.1 0.0 50192 3972 ? Ssl 18:23 0:01 /usr/bin/redis-server 127.0.0.1:0
root 6395 0.0 0.0 6432 592 pts/1 S+ 18:36 0:00 grep --color=auto redis
连接被拒绝:
# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> quit
和
# redis-cli -h 127.0.0.1 -p 0
Could not connect to Redis at 127.0.0.1:0: Connection refused
防火墙完全禁用。
有任何想法吗?
答案1
从评论中我看到redis
不要监听 TCP 端口,而只使用套接字。在这种情况下,应该使用命令完成连接
redis-cli -s /var/run/redis/redis.sock
线路
redis-cli -h 127.0.0.1 -p 0
连接到 IP 和端口。你不能使用端口0
,据我所知它是保留的