拉取tomcat镜像

docker pull tomcat 

运行两个tomcat容器

docker run -d -p 8088:8080 --name tomcat8088 tomcat
docker run -d -p 8089:8080 --name tomcat8089 tomcat

修改下index.jsp把两个tomcat区别开来

docker ps
docker exec -it 01c626690608 /bin/bash
cd webapps/ROOT/
echo "<h1>Apache Tomcat 8088</h1>" >index.jsp
cat index.jsp
exit
docker restart 01c626690608
echo "test" >index.jsp  替换index.jsp的内容
echo "test" >>index.jsp 在文件末尾追加内容

另外一个也是一样的

获取nginx镜像

docker pull nginx
创建目录
mkdir -p /data/nginx/{conf,conf.d,html,logs}
创建配置文件nginx.conf
vim /data/nginx/conf/nginx.conf
编辑内容
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; 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; # Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf; server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 192.168.1.4;
root /usr/share/nginx/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
proxy_pass http://pic;
} error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
} upstream pic{
server 192.168.1.4:8088 weight=5;
server 192.168.1.4:8089 weight=5;
} }

创建nginx容器
docker run --name mynginx -d -p 80:80  -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/logs:/var/log/nginx -d docker.io/nginx
访问页面
--
至此nginx负载均衡已完成。

Docker中nginx+tomcat实现负载均衡的更多相关文章

  1. Docker + Nginx + Tomcat 实现负载均衡简单演示

    Docker + Nginx + Tomcat 实现负载均衡 环境 [root@pinyoyougou-docker ~]# docker -v Docker version 1.12.6, buil ...

  2. Nginx+Tomcat+Memcached负载均衡集群服务搭建

    操作系统:CentOS6.5  本文档主要讲解,如何在CentOS6.5下搭建Nginx+Tomcat+Memcached负载均衡集群服务器,Nginx负责负载均衡,Tomcat负责实际服务,Memc ...

  3. nginx+tomcat实现负载均衡以及双机热备

    还记得那些年吗? 还记得更新代码之后,服务器起不来被领导训斥吗?还记得更新代码,需要停机过多的时间被渠道部们埋怨吗?还记得更新代码,代码出错时自己吓个半死吗?于是我们聪明勤快的程序员,看着电影待到夜深 ...

  4. Ubuntu下实现Nginx+Tomcat实现负载均衡

    先说一下为什么写这个文章,在性能测试过程中,我们可能会关注很多指标,比如CPU.IO.网络.磁盘等,通过这些指标大致可以判断哪个环节遇到了性能瓶颈,但是当这些指标无法判断出性能瓶颈时,我们可能就需要对 ...

  5. 简单的 Nginx+Tomcat 配置负载均衡集群

    简单 Nginx+Tomcat 配置负载均衡集群 前期准备 解压两个tomcat,修改端口号 server1:8081 server:8082 同时启动 nginx官网下载解压版nginx 创建一个简 ...

  6. Nginx+Tomcat 实现负载均衡 ,动静分离集群部署

    Nginx + Tomcat 实现负载均衡,动静分离集群部署 1.Nginx实现负载均衡原理 2.Nginx配置反向代理主要参数 3.实验 1.Nginx实现负载均衡原理: Nginx服务器作为前端, ...

  7. nginx+tomcat+redis负载均衡及session共享

    概述 本文档是用来详细描述 nginx+tomcat+redis负载均衡实现session共享 所需软件及下载地址 软件名称 下载地址 功能说明 Nginx-v1.6.0 http://nginx.o ...

  8. 使用 Nginx + Tomcat 搭建负载均衡

    负载均衡 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性. 负载均衡,英文名称为Load Balance, ...

  9. Docker+Nginx+Tomcat实现负载均衡

    环境检测: 1.Docker没有安装的小伙伴请查看https://www.cnblogs.com/niuniu0108/p/12372531.html 2.没有创建Nginx容器的小伙伴请查看http ...

随机推荐

  1. Linux下Mysql5.7忘记密码

    一.问题 linux下的mysql5.7忘记密码 二.解决 第一步:打开mysql5.7的配置文件my.cnf,并在里面增加一行:skip-grant-tables   保存并退出(:wq) [roo ...

  2. CentOS 7.0 使用yum 安装 Mariadb

    第一步: 使用命令查看是否已经安装: mysql -u root -p 返回 Enter password:  时表示已经安装成功的,需要卸载安装. 第二步: 使用yum直接安装mariadb,注意带 ...

  3. Qt QVector简单用法

    添加元素 QVector<QString> strArray; strArray.append("Hello"); 遍历 QVector<QString>: ...

  4. pgsql主备搭建及切换

    二.主从搭建 2.1测试目标 测试postgresql主从搭建安装过程 2.2环境准备 实例级别的复制 流复制主库可读写,但从库只允许查询不允许写人, 而逻辑复制的从库可读写 流复制实验环境 主机 主 ...

  5. There is already an open DataReader associated with this Command which must be closed first

    通常出现在嵌套查询数据库(比如在一个qry的遍历时,又进行了数据库查询) 通过在连接字符串中允许MARS可以轻松解决这个问题. 将MultipleActiveResultSets = true添加到连 ...

  6. Linux用户环境配置文件

    用户操作环境配置文件: 从/etc/skel目录复制过来 .bashrc             打开新终端           /etc/bashrc .bash_profile       用户登 ...

  7. Linux小知识:CentOS使用Google-BBR加速网络

    准备一台centos的服务器查看系统内核:rpm -qa | grep kernel这里需要Linux内核在4.9 RC版本以上,如果版本不是请继续下面操作 访问https://elrepo.org/ ...

  8. SpringBoot整合JavaWeb

    一.SpringBoot整合Servlet的两种方式 1.通过注解扫描完成Servlet组件的注册 编写Servlet package com.example.demo.servlet; import ...

  9. 让istio中的jaeger跑起来

    现在的水平,仅止于让它跑起来.:) 同样的环境,microk8s+istio. 步骤如下: 一,使用kubectl get pod -n istio-system查看所有istio的POD运行正常. ...

  10. django+sqlite进行web开发(二)

    模板 前面的例子中,我们是直接将HTML写在了Python代码中,这种写法并不可取.我们需要使用模板技术将页面设计和Python代码分离. 模板通常用于产生HTML,但是Django的模板也能产生任何 ...