sysctl.conf
Add to /etc/sysctl.conf
nano /etc/sysctl.conf
In the end of file these lines:
net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 net.ipv4.tcp_syncookies = 0 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 vm.swappiness = 0 net.ipv4.tcp_fack = 1 net.ipv4.tcp_sack = 1 net.ipv4.tcp_mem = 8388608 12582912 16777216 net.ipv4.udp_mem = 8388608 12582912 16777216 net.ipv4.udp_rmem_min = 16384 net.ipv4.udp_wmem_min = 16384 net.core.wmem_max = 8388608 net.core.rmem_max = 8388608 net.ipv4.tcp_rmem = 8192 87380 8388608 net.ipv4.tcp_wmem = 8192 87380 8388608 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_window_scaling = 1 net.core.somaxconn = 300000 net.core.netdev_max_backlog = 8192 net.ipv4.tcp_max_syn_backlog = 2048 net.ipv4.tcp_keepalive_time = 180 net.ipv4.tcp_keepalive_probes = 5 net.ipv4.tcp_keepalive_intvl = 30 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 0 net.ipv4.tcp_max_tw_buckets = 1000000 net.ipv4.ip_local_port_range = 1024 65535 net.nf_conntrack_max = 1000000
Also, if you have in the redis.log error like:
# Can't save in background: fork: Cannot allocate memory
then add these line:
vm.overcommit_memory = 1
Count of opened files
Sometimes you can see in the redis.log that error:
#Too many open files
It signals you that you need to increase count of opened files in your server settings.
Look at the current settings of count of simultaneously open files:
cat /proc/sys/fs/file-max
Look at the current state of opened files:
cat /proc/sys/fs/file-nr
If you need to increase this value, add to the end of /etc/sysctl.conf something like that:
fs.file-max = 6545570
limits.conf
Add to /etc/security/limits.conf
nano /etc/security/limits.conf
In the end of file these lines:
* soft nproc 65000 * hard nproc 1000000 * - nofile 1048576 root - memlock unlimited
AOF fsync problem
When you get error:
#Asynchronous AOF fsync is taking too long
You have only one possible solution — get server with better disks performance. But if you can optimize your data, just do it 😉
UPD: Some interesting configuration changes
More information can be found here:
https://github.com/antirez/redis/issues/990
http://m.blog.chinaunix.net/uid-20776139-id-5739743.html
How Redis Took Us Offline And What We Did About It
If you don’t worry about losing some data, look at redis config at these settings:
#no-appendfsync-on-rewrite yes #appendfsync no
but be carefully and read documentation in marked comments: Redis stable config with documentation
Links
System Settings for server with high load
Sysctl.conf example with comments