sql >> Base de Datos >  >> NoSQL >> Redis

¿Por qué redis no puede establecer el archivo abierto máximo?

Bueno, es un poco tarde para esta publicación, pero como acabo de pasar mucho tiempo (toda la noche) configurando un nuevo servidor redis 3.0.6 en ubuntu 16.04. Creo que debería escribir cómo lo hago para que otros no tengan que perder el tiempo...

Para un servidor redis recién instalado, probablemente verá los siguientes problemas en el archivo de registro de redis que es /var/log/redis/redis-server.log

Máximo de archivos abiertos

3917:M 16 Sep 21:59:47.834 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
3917:M 16 Sep 21:59:47.834 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
3917:M 16 Sep 21:59:47.834 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.

He visto muchas publicaciones que te dicen que modifiques

/etc/security/limits.conf
redis soft nofile 10000
redis hard nofile 10000

o

/etc/sysctl.conf
fs.file-max = 100000

Eso podría funcionar en ubuntu 14.04, pero ciertamente no funciona en ubuntu 16.04. Supongo que tiene algo que ver con el cambio de upstart a systemd, ¡pero no soy un experto en el kernel de Linux!

Para arreglar esto tienes que hacerlo con el systemd camino

/etc/systemd/system/redis.service
[Service]
...
User=redis
Group=redis
# should be fine as long as you add it under [Service] block
LimitNOFILE=65536
...

Entonces debes recargar el demonio y reiniciar el servicio

sudo systemctl daemon-reload
sudo systemctl restart redis.service

Para verificar si funciona, intente con los límites de procesamiento cat.

cat /run/redis/redis-server.pid
cat /proc/PID/limits

y verás

Max open files            65536                65536                files     
Max locked memory         65536                65536                bytes   

En esta etapa, se resuelve el máximo de archivos abiertos.

Conexión máxima de socket

2222:M 16 Sep 20:38:44.637 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

Sobreasignación de memoria

2222:M 16 Sep 20:38:44.637 # Server started, Redis version 3.0.6
2222:M 16 Sep 20:38:44.637 # 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.

Como estos dos están relacionados, lo resolveremos de inmediato.

sudo vi /etc/sysctl.conf

# Add at the bottom of file
vm.overcommit_memory = 1
net.core.somaxconn=1024

Ahora, para que estas configuraciones funcionen, debe volver a cargar la configuración

sudo sysctl -p

Páginas enormes transparentes

1565:M 16 Sep 22:48:00.993 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

Para resolver esto permanentemente, siga la sugerencia del registro y modifique rc.local

sudo vi /etc/rc.local

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi

Esto requiere que reinicie , haz una copia de seguridad de tus datos o haz cualquier cosa que necesites antes de hacerlo!!

sudo reboot

Ahora revise su registro de redis nuevamente, debería tener un servidor de redis sin errores ni advertencias.