redis2-nginx-module icon indicating copy to clipboard operation
redis2-nginx-module copied to clipboard

redis pass to unix sockets working?

Open osevan opened this issue 3 years ago • 11 comments

It is possible to use unix socket in redis pass instead of localhost IP?

Like unix://path/redis.sock?

Thanks and best regards.

osevan avatar Apr 11 '22 09:04 osevan

yeah, it is working, I just tested it now.

mkdir /var/run/redis/ && chown -R redis:www-data /var/run/redis

then, in your /etc/redis/redis.conf, search for "unixsocketperm". modify "unixsocket" and "unixsocketperm" as following: unixsocket /var/run/redis/redis.sock unixsocketperm 777

then, service redis-server restart.

then, in your nginx configuration, just pass to: unix://var/run/redis/redis.sock

tzukav avatar Jun 08 '23 13:06 tzukav

@tzukav are you sure this is working? This does not seem to work for me at all.

connect() to unix:/... failed (11: Resource temporarily unavailable) while connecting to upstream

I have no trouble connecting to the UNIX socket with redis-cli -s unix:/...

It would be a very nice feature to use UNIX sockets with redis2-nginx-module.

woutd avatar Jan 05 '24 15:01 woutd

@tzukav are you sure this is working? This does not seem to work for me at all.

connect() to unix:/... failed (11: Resource temporarily unavailable) while connecting to upstream

I have no trouble connecting to the UNIX socket with redis-cli -s unix:/...

It would be a very nice feature to use UNIX sockets with redis2-nginx-module.

can i confirm this is still working.

tzukav avatar Jan 05 '24 18:01 tzukav

@woutd is nginx using www-data as user?

tzukav avatar Jan 05 '24 18:01 tzukav

"Resource temporarily unavailable" can be a user, permissions error. if the socket file exists, i'm pretty sure there is a user or permission error.

tzukav avatar Jan 05 '24 18:01 tzukav

you can try by changing the nginx user to root temporarily, restart nginx and then see if it is working or not

tzukav avatar Jan 05 '24 18:01 tzukav

Thanks for your answer @tzukav. Sorry, I got it to work from the first time but was also doing some stress tests which caused the "Resource temporarily unavailable" error.

woutd avatar Jan 08 '24 09:01 woutd

@woutd redis has max connection set by default to something like 10k as i remember. consider increasing ulimit too, the process may be auto killed if something like max open files is hit.

tzukav avatar Jan 08 '24 09:01 tzukav

That is true, I already increased maxclients and max number of open files (ulimit). The "Resource temporarily unavailable" errors are temporary. Seems to be some "connection build up" limit I am hitting. After a great number of clients are connected everything seems to work. But this is probably related with Redis, not the NGINX module. (I was hitting the max number of ephemeral ports using IP, that is why I am looking at UNIX sockets.)

Edit: Increasing tcp-backlog in Redis config resolved my issue.

woutd avatar Jan 08 '24 10:01 woutd

@woutd yeah, i had same problem with backlog long time ago but in nginx, not redis. backlog is a always a problem in high traffic scenarios. forgot to tell you about it. also, depending on what you are using redis for, you may want to take a look over https://nginx.org/en/docs/njs/reference.html#dict as a replace for redis non persistent data.

tzukav avatar Jan 08 '24 11:01 tzukav

@tzukav looks nice. Thanks for the info and your support.

I guess this ticket can be closed as UNIX socket support certainly works.

woutd avatar Jan 08 '24 15:01 woutd