背景:

情况是这样的,我们要支撑高并发业务,需要多个web服务器来支持,如果一台机器只部署一个tomcat的话,那资源没有办法充分利用,所以我们的办法是在一台物理机部署数十个tomcat,前端使用haproxy做负载均衡,并且网站需要https访问,所以证书需要在haproxy中配置。

部署:

1、haproxy的配置

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global# to have these messages end up in /var/log/haproxy.log you will# need to:## 1) configure syslog to accept network log events.  This is done#    by adding the '-r' option to the SYSLOGD_OPTIONS in#    /etc/sysconfig/syslog## 2) configure local2 events to go to the /var/log/haproxy.log#   file. A line like the following can be added to#   /etc/sysconfig/syslog##    local2.*                       /var/log/haproxy.log#log         127.0.0.1 local2chroot      /var/lib/haproxypidfile     /var/run/haproxy.pidmaxconn     400000user        haproxygroup       haproxydaemontune.ssl.default-dh-param  2048# turn on stats unix socketstats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaultsmode                    httplog                     globaloption                  httplogoption                  dontlognulloption http-server-closeoption forwardfor       except 127.0.0.0/8option                  redispatchretries                 3option                  httpclosetimeout http-request    10stimeout queue           1mtimeout connect         10stimeout client          1mtimeout server          1mtimeout http-keep-alive 10stimeout check           10sstats enablestats hide-versionstats uri     /haproxy?statusstats realm   Haproxy\ Statisticsstats auth    admin:admin123
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  wzlinux_sslbind *:80bind *:443 ssl crt /etc/haproxy/wzlinux.pemmode httpdefault_backend  wzlinuxs
backend wzlinuxsmode httpbalance     roundrobinoption forwardfor
#    option httpchk HEAD / HTTP/1.1\r\nHost:localhostserver      tomcat01  127.0.0.1:8080 check inter 15000 rise 2 fall 4 weight 1server      tomcat02  127.0.0.1:8081 check inter 15000 rise 2 fall 4 weight 1server      tomcat03  127.0.0.1:8082 check inter 15000 rise 2 fall 4 weight 1server      tomcat04  127.0.0.1:8083 check inter 15000 rise 2 fall 4 weight 1server      tomcat05  127.0.0.1:8084 check inter 15000 rise 2 fall 4 weight 1server      tomcat06  127.0.0.1:8085 check inter 15000 rise 2 fall 4 weight 1server      tomcat07  127.0.0.1:8086 check inter 15000 rise 2 fall 4 weight 1
#    http-request set-header X-Forwarded-Port %[dst_port]
#    http-request add-header X-Forwarded-Proto https if { ssl_fc }

2、tomcat的配置设定

因为tomcat日志需要知道真正的来源IP是什么,所以默认的是不满足要求的,我们需要修改日志格式的内容如下。

<Host name="localhost"  appBase="/home/webapps"unpackWARs="true" autoDeploy="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/log/tomcat"prefix="wzlinux." suffix=".txt"pattern="%{X-Forwarded-For}i %l %u %t &quot;%r&quot; %s %b" />
</Host>

haproxy 反向代理 tomcat (https、负载均衡)相关推荐

  1. nginx反向代理,实现负载均衡

    nginx反向代理,实现负载均衡 一,先启动nginx和php-cgi #启动 php-cgi /usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 8000 -C 5 ...

  2. Nginx 部署、反向代理配置、负载均衡

    Nginx 部署.反向代理配置.负载均衡 最近我们的angular项目部署,我们采用的的是Nginx,下面对Nginx做一个简单的介绍. 为什么选择Nginx 轻:相比于Apache,同样的web服务 ...

  3. nginx 反向代理,nginx 负载均衡【nginx】(一)

    文章目录 1 具体内容 1.1 nginx简介 1.2 正向代理和反向代理 1.3 web服务器搭建 1.4 部署安装nginx 1.5 配置文件详解: 1.6 负载均衡: 1 具体内容 中文官网: ...

  4. Nginx反向代理 实现Web负载均衡

    实现负载均衡的方式有很多种,DNS.反向代理.LVS负载均衡器(软件实现).F5(负载均衡器,硬件,非常昂贵)这里我们只提到基于DNS,以及反向代理的方式来实现负载均衡Web服务       DNS服 ...

  5. Nginx反向代理及简单负载均衡配置

    nginx配置文件主要分为六个区域:main section.events section.http section.sever section.location section.upstream s ...

  6. Squid反向代理加速缓存+负载均衡实验架构

    实验环境: 公司有两台web服务器,运行同一套网站,读取同一台mysql数据库. 两台web服务器的主机名如下: test1.com 192.168.1.119 test2.com 192.168.1 ...

  7. 关于Tomcat+Nginx负载均衡与Jmeter服务器测压的日记

    Jmeter测压 1.Jmeter-5.1.1下载:http://mirror.bit.edu.cn/apache//jmeter/binaries/apache-jmeter-5.1.1.zip 2 ...

  8. Nginx+Tomcat 搭建负载均衡、动静分离(tomcat多实例)

    文章目录 一.Tomcat多实例配置 1.关闭防火墙 2.将软件包上传到/opt目录下 3.安装JDK 4.安装Tomcat 5.配置tomcat环境变量 6.修改tomcat2中的server.xm ...

  9. haproxy配置代理tomcat和nginx_Nginx负载均衡配置实例

    点击▲关注 "长安大司马"   给公众号标星置顶 更多精彩 第一时间直达 实现效果:配置负载均衡浏览器地址栏输入地址 http://192.168. 17.129/edu/a.ht ...

最新文章

  1. 英伟达奔驰共同发布自动驾驶系统,还自带停车功能
  2. 鸿蒙系统明年上市巧,鸿蒙系统官网下载-鸿蒙系统官网下载手机版 v2.0下载-955游戏网...
  3. WPF窗体置于桌面最底层
  4. byte数组转字符串_VS2012 C# 16进制数与字符串的互换
  5. Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
  6. 微信多开txt_1分钟教你如何实现微信多开!建议收藏!
  7. 查询数据进行排名,一样的并列
  8. 阿里云弹性计算,等您来!
  9. 只要3分钟免费的快速部署自己的网易云API(一)
  10. Java中的成员变量和局部变量
  11. CKfinder3版本冲突
  12. [Unity][Crowd]学习人群模拟资源分享以及相关的问题
  13. SqlServer 如何插入图片和导出图片数据
  14. 拼多多模式,砍价免费拿商品算法
  15. Java终结者和捷安特pp_终结者致命的弱点-我会怎么对付终结者
  16. itext Pdf页眉/页脚/水印
  17. oracle怎么新开账期,oracle成本核算
  18. 射影几何--圆锥曲线在平面上某点确定的对合线束
  19. STM32 OLED显示屏--SPI通信知识汇总
  20. Unity5.0 RPG角色扮演历险类游戏之 森林历险记

热门文章

  1. Redis 缓存击穿(失效)、缓存穿透、缓存雪崩怎么解决?
  2. 使用IntelliJ IDEA查看类图,内容极度舒适
  3. 这可能是最中肯的Redis规范了
  4. 实战:使用Nginx限流
  5. Java8中一个极其强悍的新特性,很多人没用过(非常实用)
  6. 终于有人把 Docker 讲清楚了,万字详解!
  7. Java面试中最高频的那20%知识点是什么?
  8. EasyDL桌面版发布!3天体验学习
  9. 强化学习,路在何方?
  10. 为什么“晚上9点钟洗澡的大学生成绩更好”?