zoukankan      html  css  js  c++  java
  • Centos 7 Docker、docker-compose、Registrator、Consul、Consul Template和Nginx实现高可扩展的Web框架

    安装所需软件

    Docker

    Docker-compose

       

    配置docker-compose.yml文件内容如下:

    #load balancer will automatically update the config using consul-template

    lb:

    image: yeasy/nginx-consul-template:latest

    hostname: lb

    volumes:

    - /usr/soft/consul/logapi.conf:/etc/consul-templates/nginx.conf

    links:

    - consulserver:consul

    ports:

    - "80:80"

       

    consulserver:

    image: gliderlabs/consul-server:latest

    hostname: consulserver

    ports:

    - "8300:8300"

    - "8301:8301"

    - "8301:8301/udp"

    - "192.168.190.131:8302:8302"

    - "192.168.190.131:8302:8302/udp"

    - "192.168.190.131:8400:8400"

    - "192.168.190.131:8500:8500"

    - "53:53/udp"

    - "53:53"

    command: -data-dir /tmp/consul -bootstrap -advertise 192.168.190.131

       

    registrator:

    image: gliderlabs/registrator:latest

    hostname: registrator

    links:

    - consulserver:consul

    volumes:

    - "/var/run/docker.sock:/tmp/docker.sock"

    command: consul://consul:8500

       

    logapi:

    image: logapi-1-0-app

    environment:

    SERVICE_80_NAME: http

    SERVICE_NAME: logapi

    SERVICE_TAGS: backend

    ports:

    - "60000"

       

    Nginx模板文件 /usr/soft/consul/logapi.conf内容如下:logapi名称与docker-compose.yml文件中logapi节点下的SERVICE_NAME名称相同

       

    upstream app {

    {{range service "logapi"}}server {{.Address}}:{{.Port}} max_fails=3 fail_timeout=60 weight=1;

    {{else}}server 127.0.0.1:65535; # force a 502{{end}}

    }

       

    server {

    listen 80 default_server;

       

    location / {

    proxy_pass http://app;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header Host $host;

    proxy_set_header X-Real-IP $remote_addr;

    }

    }

       

    转到docker-compose.yml文件所在目录

    运行sudo docker-compose up

       

       

    查看运行状态

       

    防火墙开启相应端口

    32860端口为logapi-1-0-app容器对应的端口号

    sudo firewall-cmd --zone=public --add-port=8500/tcp --permanent

    sudo firewall-cmd --zone=public --add-port=32861-33000/tcp --permanent

    sudo firewall-cmd --reload

       

    查看网站内容返回如下:

    curl http://192.168.190.131

    {"status":1,"message":"","data":{"hostName":"fdbd2c30b6c4","ip":["172.17.0.2","172.17.0.2","172.17.0.2"]}}

       

    开启2个站点

    sudo docker-compose scale logapi=2

       

       

    再次访问站点内容

       

       

  • 相关阅读:
    Mysql里的isnull(),ifnull(),nullif
    懒加载数据
    MyEclipse编辑xml文件没有提示
    java-五子棋游戏源码
    Java版打字练习游戏源码
    Wpf实现图片自动轮播自定义控件
    WP8.1开发:自定义控件
    简单的UIButton按钮动画效果ios源码下载
    自定义的一款选项卡ios源码
    Aisen微博应用源码完整版
  • 原文地址:https://www.cnblogs.com/liuyuhua/p/5944976.html
Copyright © 2011-2022 走看看