![Redis 无法创建 unix 套接字](https://linux22.com/image/779923/Redis%20%E6%97%A0%E6%B3%95%E5%88%9B%E5%BB%BA%20unix%20%E5%A5%97%E6%8E%A5%E5%AD%97.png)
我正在尝试设置 redis 以使用 Unix Socket。
我使用的是 Debian 原版安装/etc/redis/redis.conf
,但在文件末尾添加了以下内容,基于此信息:
# create a unix domain socket to listen on
unixsocket /run/project/redis.sock
# set permissions for the socket
unixsocketperm 775
#requirepass passwordtouse
# bind 127.0.0.1
daemonize yes
# maximum memory allowed for redis
maxmemory 128Mb
我请求它在以下位置创建 unix 套接字/run/project/redis.socket
:
# ll /run/project
total 4
drwxrwxrwx 2 michael www-data 100 Aug 29 16:32 .
drwxr-xr-x 21 root root 640 Aug 30 10:49 ..
我将用户添加redis
到组www-data
,又无奈地添加redis
到组michael
:
$ cat /etc/group | grep redis
www-data:x:33:michael,redis
michael:x:1000:www-data,redis
redis:x:119:
对我来说,我认为权限很好:
$ sudo -u redis touch /run/project/foo
$ ll /run/project/foo
-rw-r--r-- 1 redis redis 0 Aug 30 11:13 /run/project/foo
但是当我重新启动 redis 服务器时,它会失败:
$ systemctl restart redis-server.service
Job for redis-server.service failed because the control process exited with error code.
See "systemctl status redis-server.service" and "journalctl -xe" for details.
$ systemctl status redis-server.service
redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2022-08-30 10:49:52 SAST; 3min 47s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 2465457 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no (code=exited, status=1/FAILURE)
Main PID: 2465457 (code=exited, status=1/FAILURE)
Status: "Redis is loading..."
CPU: 23ms
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Main process exited, code=exited, status=1/FAILURE
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 10:49:52 vps systemd[1]: Failed to start Advanced key-value store.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Aug 30 10:49:52 vps systemd[1]: Stopped Advanced key-value store.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Start request repeated too quickly.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 10:49:52 vps systemd[1]: Failed to start Advanced key-value store.
这是日志文件(根据我的研究,显然应该忽略有关 TimeoutStartSec / TimeoutStopSec 的警告。
2465442:C 30 Aug 2022 10:49:51.155 # WARNING supervised by systemd - you MUST set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit.
2465442:C 30 Aug 2022 10:49:51.158 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2465442:C 30 Aug 2022 10:49:51.158 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=2465442, just started
2465442:C 30 Aug 2022 10:49:51.158 # Configuration loaded
2465442:M 30 Aug 2022 10:49:51.158 # Opening Unix socket: bind: Read-only file system
$ journalctl -xeu redis.service
-- Journal begins at Mon 2021-08-16 08:09:33 SAST, ends at Tue 2022-08-30 10:59:15 SAST. --
-- No entries --
使用 Debian。安装redis
有sudo apt install redis
。
我试过此解决方案,但出现此错误:
$ sudo systemctl enable redis.service
Failed to enable unit: Refusing to operate on alias name or linked unit file: redis.service
更新:日志/配置文件的文件权限:
$ ll /var/lib/redis/dump.rdb
-rw-rw---- 1 redis redis 93 Aug 29 14:53 /var/lib/redis/dump.rdb
$ ll /etc/redis/redis.conf
-rw-r----- 1 redis redis 86461 Aug 30 11:11 /etc/redis/redis.conf
$ ll /var/log/redis/redis-server.log
-rw-rw---- 1 redis adm 22476 Aug 30 11:22 /var/log/redis/redis-server.log
关于停止然后重新运行的更新/usr/bin/redis-server
:
$ systemctl stop redis-server.service
$ systemctl status redis-server.service
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2022-08-30 11:22:15 SAST; 1h 44min ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 2682 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no (code=exited, status=1/FAILURE)
Main PID: 2682 (code=exited, status=1/FAILURE)
Status: "Redis is loading..."
CPU: 24ms
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Main process exited, code=exited, status=1/FAILURE
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 11:22:15 vps systemd[1]: Failed to start Advanced key-value store.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Aug 30 11:22:15 vps systemd[1]: Stopped Advanced key-value store.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Start request repeated too quickly.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 11:22:15 vps systemd[1]: Failed to start Advanced key-value store.
$ /usr/bin/redis-server /etc/redis/redis.conf
$
更新:尝试清除并重新安装 redis,但没有帮助。如果我使用默认配置启动它,则安装正常,并且运行:
# systemctl status redis-server.service
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-08-30 20:52:29 SAST; 44s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 26102 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 1133)
Memory: 7.4M
CPU: 90ms
CGroup: /system.slice/redis-server.service
└─26102 /usr/bin/redis-server 127.0.0.1:6379
Aug 30 20:52:29 vps systemd[1]: Starting Advanced key-value store...
Aug 30 20:52:29 vps systemd[1]: Started Advanced key-value store.
但是,当我添加以下内容以使用 unix 套接字时,它就停止工作:
unixsocket /run/project/redis.sock
# set permissions for the socket
unixsocketperm 775
requirepass passwordtouse
# bind 127.0.0.1
daemonize yes
# maximum memory allowed for redis
maxmemory 128Mb
答案1
我猜你搞错了必要的 redis 文件权限。请检查以下内容,确保 redis 可以访问文件/配置
redis-server.log(and associated logs files)
dump.rdb
Any config file which is read by redis process
更新:如果其他原因阻止 redis 启动,请尝试以下命令(根据您的设置更改路径),它将大多数时间向您显示确切的问题。
/usr/bin/redis-server /etc/redis/redis.conf
答案2
unixsocketperm 777
然后重启redis。
关于这个有很多信息,可以谷歌一下
它对我和其他人都有效。
我想我在这里发现了它......https://github.com/redis/node-redis/issues/204