码迷,mamicode.com
首页 > 其他好文 > 详细

redis最大连接数

时间:2019-08-26 11:28:19      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:theme   log   linu   version   OWIN   file   geek   script   can   

Well, it‘s a bit late for this post, but since I just spent a lot of time(the whole night) to configure a new redis server 3.0.6 on ubuntu 16.04. I think I should just write down how I do it so others don‘t have to waste their time...

For a newly installed redis server, you are probably going to see the following issues in redis log file which is /var/log/redis/redis-server.log

Maximum Open Files

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‘.

I have seen a lot of posts telling you to modify

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

or

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

That might work in ubuntu 14.04, but it certainly not works in ubuntu 16.04. I guess it has something to do with changing from upstart to systemd, but I am no expert of linux kernel!

To fix this you have to do it the systemd way

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

Then you must daemon reload and restart the service

sudo systemctl daemon-reload
sudo systemctl restart redis.service

To check if it works, try to cat proc limits

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

and you will see

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

At this stage, the maximum open file is solved.

Socket Maximum Connection

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.

Memory Overcommit

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.

Since these two are related, we will solve it at once.

sudo vi /etc/sysctl.conf

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

Now for these configs to work, you need to reload the config

sudo sysctl -p

Transparent Huge Pages

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.

To permanently solve this, follow the log‘s suggestion, and modify 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

This require you to reboot, backup your data or do anything you need before you actually do it!!

sudo reboot

Now check you redis log again, you should have a redis server without any errors or warnings.

 

0

You just need this command in console:

sudo ulimit -n 65535

redis最大连接数

标签:theme   log   linu   version   OWIN   file   geek   script   can   

原文地址:https://www.cnblogs.com/cheyunhua/p/11411465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!