unbound icon indicating copy to clipboard operation
unbound copied to clipboard

error: failed to connect to redis server

Open liang-hiwin opened this issue 2 years ago • 8 comments

I statically compiled the unbound-master by myself. From the -vvvv debug window, I saw that the redis server could not be found.

My redis configuration is below,

cachedb:
    backend: "redis"
    #redis-server-host: 127.0.0.1
    #redis-server-port: 6379
    redis-server-path: "/tmp/redis.sock"
    redis-timeout: 5000
    redis-expire-records: no
./unbound -c /usr/local/sbin/static_unbound/etc/unbound/unbound.conf -dd -vvvv
[1687795308] unbound[5403:0] notice: Start of unbound 1.17.2.
[1687795308] unbound[5403:0] debug: creating udp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] debug: creating tcp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] debug: creating udp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] debug: creating tcp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] debug: creating udp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] debug: creating tcp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] debug: creating udp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] debug: creating tcp4 socket 127.0.0.1 5356
[1687795308] unbound[5403:0] warning: unbound is already running as pid 947.
[1687795308] unbound[5403:0] debug: chdir to /usr/local/sbin/static_unbound/etc/unbound
[1687795308] unbound[5403:0] debug: chroot to /usr/local/sbin/static_unbound/etc/unbound
[1687795308] unbound[5403:0] debug: drop user privileges, run as root
[1687795308] unbound[5403:0] debug: switching log to stderr
[1687795308] unbound[5403:0] debug: module config: "subnetcache validator cachedb iterator"
[1687795308] unbound[5403:0] notice: init module 0: subnetcache
[1687795308] unbound[5403:0] debug: send-client-subnet: ::0/0
[1687795308] unbound[5403:0] debug: send-client-subnet: 0.0.0.0/0
[1687795308] unbound[5403:0] debug: subnetcache: option registered (8)
[1687795308] unbound[5403:0] notice: init module 1: validator
[1687795308] unbound[5403:0] debug: validator nsec3cfg keysz 1024 mxiter 150
[1687795308] unbound[5403:0] debug: validator nsec3cfg keysz 2048 mxiter 150
[1687795308] unbound[5403:0] debug: validator nsec3cfg keysz 4096 mxiter 150
[1687795308] unbound[5403:0] notice: init module 2: cachedb
[1687795308] unbound[5403:0] debug: redis_init
[1687795308] unbound[5403:0] error: failed to connect to redis server: No such file or directory
[1687795308] unbound[5403:0] error: failed to connect to redis server: No such file or directory
[1687795308] unbound[5403:0] error: failed to connect to redis server: No such file or directory
[1687795308] unbound[5403:0] error: failed to connect to redis server: No such file or directory

B`N(@6U3(OBX (%3}ZUR2O

liang-hiwin avatar Jun 26 '23 16:06 liang-hiwin

NOT sure, just trying to help here... you have log lines:

[1687795308] unbound[5403:0] debug: chdir to /usr/local/sbin/static_unbound/etc/unbound
[1687795308] unbound[5403:0] debug: chroot to /usr/local/sbin/static_unbound/etc/unbound

which, according to what I know about chroot, for unbound the root (/) is now "/usr/local/sbin/static_unbound/etc/unbound" This means, the folder "/usr/local/sbin/static_unbound/etc/unbound/test" needs to be referred to (in an unbound configuration file) as "/test".

since you use redis-server-path: "/tmp/redis.sock", and this path doesn't exist for chrooted unbound, the message

[1687795308] unbound[5403:0] error: failed to connect to redis server: No such file or directory

is thus perfectly normal (due to the usage of chroot).

jpgpi250 avatar Sep 24 '23 08:09 jpgpi250

NOT sure, just trying to help here... you have log lines:

[1687795308] unbound[5403:0] debug: chdir to /usr/local/sbin/static_unbound/etc/unbound
[1687795308] unbound[5403:0] debug: chroot to /usr/local/sbin/static_unbound/etc/unbound

which, according to what I know about chroot, for unbound the root (/) is now "/usr/local/sbin/static_unbound/etc/unbound" This means, the folder "/usr/local/sbin/static_unbound/etc/unbound/test" needs to be referred to (in an unbound configuration file) as "/test".

since you use redis-server-path: "/tmp/redis.sock", and this path doesn't exist for chrooted unbound, the message

[1687795308] unbound[5403:0] error: failed to connect to redis server: No such file or directory

is thus perfectly normal (due to the usage of chroot).

I installed the latest unbound 1.18.0 and got the same error

How do I define this location? chroot to /usr/local/etc/unbound I can't write it like this redis-server-path: "/usr/local/etc/unbound/redis.sock"

:/usr/local/sbin# unbound -c /usr/local/etc/unbound/unbound.conf -dd -vvvv
[1695565597] unbound[1814288:0] notice: Start of unbound 1.18.0.
[1695565597] unbound[1814288:0] debug: increased limit(open files) from 1024 to 10264
[1695565597] unbound[1814288:0] debug: creating udp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: creating tcp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: creating udp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: creating tcp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: creating udp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: creating tcp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: creating udp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: creating tcp4 socket 0.0.0.0 5353
[1695565597] unbound[1814288:0] debug: chdir to /usr/local/etc/unbound
[1695565597] unbound[1814288:0] debug: chroot to /usr/local/etc/unbound
[1695565597] unbound[1814288:0] debug: drop user privileges, run as root
[1695565597] unbound[1814288:0] debug: switching log to stderr
[1695565597] unbound[1814288:0] debug: module config: "subnetcache validator cachedb iterator"
[1695565597] unbound[1814288:0] notice: init module 0: subnetcache
[1695565597] unbound[1814288:0] debug: send-client-subnet: ::0/0
[1695565597] unbound[1814288:0] debug: send-client-subnet: 0.0.0.0/0
[1695565597] unbound[1814288:0] debug: subnetcache: option registered (8)
[1695565597] unbound[1814288:0] notice: init module 1: validator
[1695565597] unbound[1814288:0] debug: validator nsec3cfg keysz 1024 mxiter 150
[1695565597] unbound[1814288:0] debug: validator nsec3cfg keysz 2048 mxiter 150
[1695565597] unbound[1814288:0] debug: validator nsec3cfg keysz 4096 mxiter 150
[1695565597] unbound[1814288:0] notice: init module 2: cachedb
[1695565597] unbound[1814288:0] notice: Redis initialization
[1695565597] unbound[1814288:0] error: failed to connect to redis server: No such file or directory
[1695565597] unbound[1814288:0] error: failed to connect to redis server: No such file or directory
[1695565597] unbound[1814288:0] error: failed to connect to redis server: No such file or directory
[1695565597] unbound[1814288:0] error: failed to connect to redis server: No such file or directory

liang-hiwin avatar Sep 24 '23 14:09 liang-hiwin

in order for unbound to see the redis.sock file, it needs to be below /usr/local/sbin/static_unbound/etc/unbound e.g. /usr/local/sbin/static_unbound/etc/unbound/redis.sock. The chrooted config than needs to be redis-server-path: "/redis.sock"

jpgpi250 avatar Sep 24 '23 20:09 jpgpi250

in order for unbound to see the redis.sock file, it needs to be below /usr/local/sbin/static_unbound/etc/unbound e.g. /usr/local/sbin/static_unbound/etc/unbound/redis.sock. The chrooted config than needs to be redis-server-path: "/redis.sock"

I'll give it a try, thank you

liang-hiwin avatar Sep 25 '23 11:09 liang-hiwin

in order for unbound to see the redis.sock file, it needs to be below /usr/local/sbin/static_unbound/etc/unbound e.g. /usr/local/sbin/static_unbound/etc/unbound/redis.sock. The chrooted config than needs to be redis-server-path: "/redis.sock"

Same error report

liang-hiwin avatar Sep 28 '23 13:09 liang-hiwin

permissions on the file or / and folder?

jpgpi250 avatar Sep 28 '23 17:09 jpgpi250

permissions on the file or / and folder?

777

liang-hiwin avatar Oct 01 '23 10:10 liang-hiwin

Same issue here, symlinking returned too many levels of symbolic links, so I disabled the chroot feature. It successfully connected, but I rollbacked this config to keep unbound sandboxed. (I failed to write a systemd service file that runs unbound as a non-root user)

Bind-mounting the socket file before the chroot will be needed. (edit: I tried mount --bind, and got error: failed to connect to redis server: Permission denied. I have no clue why it loses permission only when bind-mounted)

Slug-V avatar Feb 22 '24 06:02 Slug-V