• docker搭建nginx+springboot集群


    1、首先准备两个springboot jar包,一个端口设置为8000,一个设置为8080。

    2、打包第一个springboot jar包,Dockerfile如下

    FROM java:8
    VOLUME /tmp
    ADD spring-boot-docker-0.1.0.jar app.jar
    RUN bash -c 'touch /app.jar'
    ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
    

    然后运行docker构建命令

    docker build -t xiao/springboot .

    3、同理我们构建第二个镜像springboot2


    4、构建nginx,Dockerfile如下

    FROM ubuntu:latest
    MAINTAINER xiao
    ENV REFRESHED_AT 2017-03-19
    RUN apt-get update
    RUN apt-get -y -q install nginx
    RUN mkdir -p /var/www/html
    ADD nginx/global.conf /etc/nginx/conf.d/
    ADD nginx/nginx.conf /etc/nginx/nginx.conf
    EXPOSE 80

    其中global.conf设置如下

    upstream service_group{
          server sample:8080 max_fails=1 fail_timeout=60s weight=1;
          server sample2:8000 max_fails=1 fail_timeout=60s weight=2;
    }
    
    
    server {
            listen 80;
            server_name localhost;
            location / {  
                    proxy_pass http://service_group;  
                    proxy_redirect default;  
                }  
                  
          
                error_page   500 502 503 504  /50x.html;  
                location = /50x.html {  
                    root   html;  
                }  
    } 

    nginx.conf如下

    user www-data;
    worker_processes 4;
    pid /run/nginx.pid;
    daemon off;
    
    events {  }
    
    http {
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
      gzip on;
      gzip_disable "msie6";
      include /etc/nginx/conf.d/*.conf;
    }

    注意daemon设置为off省的一启动就关闭容器。

    5、构建nginx镜像。

    6、使用 docker iamges查看镜像

    7、启动两个springboot镜像

    docker run -d -h sample -p 8080:8080 --name sample xiao/springboot
    docker run -d -h sample2 -p 8000:8000 --name sample2 xiao/springboot2

    8、启动nginx镜像

    docker run -d -h sample2 -p 9000:80 --link sample:sample --link sample2:sample2  --name nginx1 xiao/nginx nginx

    9、使用docker ps查看container状态

    10、访问http://localhost:9000/ 就能实现nginx负载均衡随机选择两个服务器进行转发。

  • 相关阅读:
    截取字符
    vue中移动端调取本地的复制的文本
    vue中用 async/await 来处理异步
    vue中子组件调用父组件里面的数据和方法 父组件调用子组件的数据和方法
    spy-debugger 安装以及使用
    vuex用法-新手一
    monent API详解
    原生js标识当前导航位置(给当前导航一个className=active)
    webpack 4.0 配置文件 webpack.config.js文件的放置位置
    移动端部分安卓手机(三星,小米)竖拍上传图片预览的时候发生旋转问题
  • 原文地址:https://www.cnblogs.com/tuifeideyouran/p/6592973.html
Copyright © 2020-2023  润新知