본문 바로가기

LINUX

(DK) NGINX LB (TCP/UDP) 구성

728x90
yum install nginx nginx-mod-stream -y
systemctl start nginx
systemctl enable nginx

### TCP / UDP LB를 설정 하기 위해 폴더 생성 후 LB 구성

mkdir -p /etc/nginx/tcpconf.d


cat << EOF | tee lb.conf
stream{
    upstream ocp_k8s_api {
        #round-robin;
        server 10.253.107.10:6443; #bootstrap
        server 10.253.107.11:6443; #master1
        server 10.253.107.12:6443; #master2
        server 10.253.107.13:6443; #master3
    }
    server {
        listen 6443;
        proxy_pass ocp_k8s_api;
    }


    upstream ocp_m_config {
        #round-robin;
        server 10.253.107.10:22623; #bootstrap
        server 10.253.107.11:22623; #master1
        server 10.253.107.12:22623; #master2
        server 10.253.107.13:22623; #master3
    }
    server {
        listen 22623;
        proxy_pass ocp_m_config;
    }

    upstream ocp_http {
        #round-robin;
        server 10.253.107.11:80; #master1
        server 10.253.107.12:80; #master2
        server 10.253.107.13:80; #master3
        server 10.253.107.14:80; #worker1
        server 10.253.107.15:80; #worker2
        server 10.253.107.16:80; #worker3
    }
    server{
        listen 80;
        proxy_pass ocp_http;
    }

    upstream ocp_https {
        #round-robin;
        server 10.253.107.11:443; #master1
        server 10.253.107.12:443; #master2
        server 10.253.107.13:443; #master3
        server 10.253.107.14:443; #worker1
        server 10.253.107.15:443; #worker2
        server 10.253.107.16:443; #worker3   
    }
    server{
        listen 443;
        proxy_pass ocp_https;
    }
}
EOF

 

### NGINX.CONF 추가

아래에 http에 INCLUDE 하지않고 밖에다 해야 하므로 include /usr/share/nginx/modules/*.conf; 밑에 붙여 넣음

http { 

}

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

include /etc/nginx/tcpconf.d/*.conf;   ### ADD 
 
events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    
#    server {
#        listen       8081;
#        listen       [::]:8081;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#        location = /404.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#        location = /50x.html {
#        }
#    }
# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

 

### 서비스 restart

systemctl restart nginx
systemctl enable nginx

아래처럼 화면이 나오면 성공 

반응형