A
A
Anton B2016-12-07 15:56:40
linux
Anton B, 2016-12-07 15:56:40

What is the best way to set up a server for Redis uptime?

Good day.
OS Debian 8.6
There is a dedicated server 1 on which MySQL and Redis are spinning.
There is a dedicated server 2 on which PHP is running and which in each script connects to MySQL and Redis, using MySQLi and PHPRedis, respectively.
From time to time, PHP scripts fail to connect to the Redis server.

$Redis = new Redis();

if ( ! $Redis->connect('x.x.x.x'))
    trigger_error('Cache connect error', E_USER_WARNING);

At one time, I thought that the problem was related to the PHPRedis extension and wrote to the developer, but it turned out that no one but me faced such problems. That's why I decided to look in the direction of the server configuration.
I should report that server 1 's iptables rules are written in a "do not allow anything that is not allowed" principle. That is, I close all ports and open only 3306 + 6379 for server IP 2 .

Here are the changes I made to the base OS configuration
echo "net.netfilter.nf_conntrack_max = 1048576" >> /etc/sysctl.conf  
echo "net.netfilter.nf_conntrack_tcp_timeout_established = 3600" >> /etc/sysctl.conf
echo "net.core.somaxconn = 65535" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 65535" >> /etc/sysctl.conf

//добавить в /etc/rc.local до exit 0 строку
echo 262144 > /sys/module/nf_conntrack/parameters/hashsize

Changes in redis.conf
tcp-backlog 32768
By default , net.core.somaxconn was 2k, and tcp-backlog was 511. I doubled these values ​​in stages and the connection problem disappeared for a couple of days, but then appeared again.
Tell me how to solve my problem?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neol, 2016-12-07
@neol

You have a ton of connections hanging from the client side.
For starters, I would add
iptables -I INPUT -p icmp -j ACCEPT
This will probably already solve your problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question