0

我有 4 个 redis 服务器的上游 nginx。有时我会在 nginx error.log 中收到此类错误(每分钟 20-30 个,仅适用于上游的第一台和第二台服务器):

... upstream timed out (110: Connection timed out) while connecting to upstream ... upstream: "redis2://AAA.BBB.CCC.DDD:6379" ....

我的 redis 服务器和 nginx 上的平均负载 <1,所有这些 - CentOS 6.6;我的 nginx 上的 RPS - 250-350。

这些错误的原因可能是什么?提前Tnx。

nginx.conf

user nginx;
worker_processes  4;
timer_resolution 100ms;
worker_priority -15;
worker_rlimit_nofile 200000;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
  worker_connections  65536;
  use epoll;
  multi_accept on;
}

http {


  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  access_log    /var/log/nginx/access.log;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;

  keepalive_timeout  65;

  gzip  on;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_vary off;
  gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml;
  gzip_min_length  1000;
  gzip_disable     "MSIE [1-6]\.";

  server_names_hash_bucket_size 64;
  types_hash_max_size 2048;
  types_hash_bucket_size 64;

   include /etc/nginx/sites-enabled/*;
}

上游配置:

upstream redis_cluster {
    server redis1.mydomain.com:6379 max_fails=0 fail_timeout=1s weight=4;
    server redis2.mydomain.com:6379 max_fails=0 fail_timeout=1s weight=4;
    server redis3.mydomain.com:6379 max_fails=0 fail_timeout=1s weight=4;
    server redis4.mydomain.com:6379 max_fails=0 fail_timeout=1s weight=4;
}

sysctl.conf(在 nginx 上,仅限版本)

net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.tcp_max_syn_backlog = 20480
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.netfilter.nf_conntrack_max = 1048576
net.nf_conntrack_max = 1048576
net.ipv4.tcp_congestion_control = htcp
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 15000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 5

sysctl.conf(在 redis-server 上,实际上,相同,仅版本)

vm.overcommit_memory = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.tcp_max_syn_backlog = 20480
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.netfilter.nf_conntrack_max = 1048576
net.nf_conntrack_max = 1048576
net.ipv4.tcp_congestion_control = htcp
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 15000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 5
4

0 回答 0