zoukankan      html  css  js  c++  java
  • docker 部署一个简单的nginx负载均衡

    1. 系统环境:

    底层系统:CentOS Linux release 8.1.1911 (Core
    负载均衡:192.168.0.115: 9117
    web1: 192.168.0.115:9113
    web2: 192.168.0.115:9111
    注意:关闭selinux, 防火墙
    

    2. docker环境部署

    2.1 安装docker-ce
    	dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
    	dnf -y install docker-ce
    2.2 安装nginx
    	docker run --name nginxlb -p 9117:80 -d nginx
    	docker run --name nginx01 -p 9113:80 -d nginx
    	docker run --name nginx02 -p 9111:80 -d nginx
    

    3. 配置nginx负载均衡

    3.1 配置负载均衡容器, 在/etc/nginx/nginx.conf的http中插入以下内容
        upstream test01 {
            server 192.168.0.115:9111 weight=2;
            server 192.168.0.115:9113 weight=7;
        }
        server {
            listen       9117;
            server_name 192.168.0.115;
            root         /usr/share/nginx/html;
            index index.html;
        location / {
             proxy_pass http://test01;
             proxy_set_header Host $http_host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
             proxy_connect_timeout 30;
             proxy_send_timeout 60;
             proxy_read_timeout 60;
    
             proxy_buffering on;
             proxy_buffer_size 32k;
             proxy_buffers 4 128k;
        }
    
    }
    3.2 修改nginx01,nginx02容器里nginx的欢迎页面,测试是否实现了负载均衡
    	index.html的路径在: /usr/share/nginx/html/index.html
    	把在外面改好的内容传人到容器内
    	docker cp index.html nginx02:/usr/share/nginx/html
    	
    

    至此,一个简单的负载均衡已经实现

    原文链接: https://www.cnblogs.com/sonyy/p/13225661.html

    微醺生活,醉美人生
  • 相关阅读:
    Sprinig.net 双向绑定 Bidirectional data binding and data model management 和 UpdatePanel
    Memcached是什么
    Spring.net 网络示例 codeproject
    jquery.modalbox.show 插件
    UVA 639 Don't Get Rooked
    UVA 539 The Settlers of Catan
    UVA 301 Transportation
    UVA 331 Mapping the Swaps
    UVA 216 Getting in Line
    UVA 10344 23 out of 5
  • 原文地址:https://www.cnblogs.com/sonyy/p/13225661.html
Copyright © 2011-2022 走看看