美文网首页
Docker ELB 动态负载均衡

Docker ELB 动态负载均衡

作者: SkTj | 来源:发表于2019-12-04 11:05 被阅读0次

    consul+confd实现动态负载均衡

    image.png

    consul

    docker run -d -p 8400:8400 -p 8500:8500 -p 8600:53/udp
    -h cookbook progrium/consul -server
    -bootstrap -ui-dir /ui

    registrator

    docker run -d -v /var/run/docker.sock:/tmp/docker.sock
    -h 192.168.33.10 gliderlabs/registrator
    -ip 192.168.33.10 consul://192.168.33.10:8500/elb

    docker run -d -p 5001:5000 runseb/hostname
    docker run -d -p 5002:5000 runseb/hostname

    nginx

    events {
    worker_connections 1024;
    }
    http {
    upstream elb {
    server 192.168.33.10:5001;
    server 192.168.33.10:5002;
    }
    server {
    listen 80;
    location / {
    proxy_pass http://elb;
    }
    }
    }

    nginx container

    docker run -d -p 80:80 -v /home/vagrant/nginx.conf:/etc/nginx/nginx.conf
    --name elb nginx

    加入confd

    sudo mkdir -p /etc/confd/{conf.d,templates}

    在/etc/confd/conf.d/config.toml

    [template]
    src = "config.conf.tmpl"
    dest = "/home/vagrant/nginx.conf"
    keys = [
    "/elb/hostname",
    ]
    reload_cmd = "docker restart elb"

    /etc/confd/templates/config.conf.tmpl

    events {
    worker_connections 1024;
    }
    http {
    upstream elb {
    {{range getvs "/elb/hostname/*"}}
    server {{.}};
    {{end}}
    }
    server {
    listen 80;
    location / {
    proxy_pass http://elb;
    }
    }
    }

    ./confd -onetime -backend consul -node 192.168.33.10:8500

    docker run -d -p 5003:5000 runseb/hostname
    ./confd -onetime -backend consul -node 192.168.33.10:8500

    ./confd -backend consul -interval 5 -node 192.168.33.10:8500

    相关文章

      网友评论

          本文标题:Docker ELB 动态负载均衡

          本文链接:https://www.haomeiwen.com/subject/kqvmvctx.html