Nginx를 사용할 때 로드 밸런싱이 예상대로 작동하지 않습니다.

Nginx를 사용할 때 로드 밸런싱이 예상대로 작동하지 않습니다.

1분에 수천 개의 요청을 보내는 서버가 있습니다. Nginx 서버에 연결됩니다. Nginx는 아래 구성 설정에 따라 4개의 서버로 요청을 업스트림합니다.

upstream cmdc {
server cmdc2b:5600 max_fails=3 fail_timeout=30s;
server cmdc2a:5600 max_fails=3 fail_timeout=30s;
server cmdc1d:5600 max_fails=3 fail_timeout=30s;
server cmdc1c:5600 max_fails=3 fail_timeout=30s;
keepalive 30;
}

ELK에서 요청의 거의 50%가 cmdc2b로 전송되고 나머지는 다른 요청에 분산되어 있음을 알 수 있습니다. 문제를 일으키는 다른 값을 의심하는 사람이 있습니까? 아래에 Nginx 구성을 나열했습니다.

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
worker_rlimit_nofile 30000;
pid        /var/run/nginx.pid;


events {
    worker_connections  10240;
}


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


log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" cachestatus: $upstream_cache_status'
    'dest: $upstream_addr'
                  ' response_time: $request_time';

access_log  /var/log/nginx/access.log  main;
sendfile        off;
#tcp_nopush     on;

keepalive_timeout  65;
keepalive_requests 5000;
gzip  on;#page will be served using Nginx Gzip Module if requested by client
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
#error_page--configure the server's statuses when errors occur
proxy_cache_path /opt/nds/data/nginx/cache levels=1:2 keys_zone=cmdc_cache:10m max_size=11g loader_threshold=300 loader_files=200 inactive=5m;
proxy_cache_key "$scheme$request_method$host$request_uri";
include /etc/nginx/conf.d/cmdc.conf;
}

누군가 여기에 빛을 비출 수 있습니까?

답변1

기본 루프에 의존하기보다는 가능한 가장 적은 수의 연결을 찾고 있다는 것을 알 수 있습니다.

upstream cmdc {
  least_conn;
  server cmdc2b:5600 max_fails=3 fail_timeout=30s;
  server cmdc2a:5600 max_fails=3 fail_timeout=30s;
  server cmdc1d:5600 max_fails=3 fail_timeout=30s;
  server cmdc1c:5600 max_fails=3 fail_timeout=30s;
  keepalive 30;
}

서버에 가중치를 적용할 수도 있습니다.여기더 많은 정보를 알고 싶다면

관련 정보