• nginx基于tcp负载均衡


    官方参考文档:http://nginx.org/en/docs/stream/ngx_stream_core_module.html
    只有nginx1.9以上的版本才支持tcp负载均衡
    配置必须出现在main段,不能配置在http,event和server标签段

    (1)安装官方nginx

    1.配置官方yum源

    #vim /etc/yum.repos.d/nginx.repo 
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
    gpgcheck=0
    enabled=1
    
    yum makecache
    yum repolist 
    

    2.安装nginx

    yum install nginx -y 
    systemctl start nginx 
    systemctl enable nginx 
    

    (2)配置tcp负载均衡

    #vim /etc/nginx/nginx.conf 
    stream {
            upstream ssh_proxy {
    				hash $remote_addr consistent;								//一致性hash
                    server 192.9.191.31:22 max_fails=2 fail_timeout=2s;			//健康状态检测
                    server 192.9.191.32:22 max_fails=2 fail_timeout=2s;
                    }
            server {
                    listen 2222;
                    proxy_connect_timeout 1s;						//连接超时
                    proxy_timeout 20s;								//连接超时时间,如果不配置,永远不超时
                    proxy_pass ssh_proxy;		
                    }
    }
    #systemctl reload nginx 
    
  • 相关阅读:
    链接、装载与库
    mysql 调用外部程序
    SAMBA 共享服务器搭建
    Django 部署
    python基础教程1
    django 文件上传
    Django URLconf
    django view
    admin site
    django book
  • 原文地址:https://www.cnblogs.com/lovelinux199075/p/9062219.html
Copyright © 2020-2023  润新知