背景:前端
状况是这样的,咱们要支撑高并发业务,须要多个web服务器来支持,若是一台机器只部署一个tomcat的话,那资源没有办法充分利用,因此咱们的办法是在一台物理机部署数十个tomcat,前端使用haproxy作负载均衡,而且网站须要https访问,因此证书须要在haproxy中配置。linux
部署:web
一、haproxy的配置redis
#--------------------------------------------------------------------- # 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 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 400000 user haproxy group haproxy daemon tune.ssl.default-dh-param 2048 # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 option httpclose timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s stats enable stats hide-version stats uri /haproxy?status stats realm Haproxy\ Statistics stats auth admin:admin123 #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend wzlinux_ssl bind *:80 bind *:443 ssl crt /etc/haproxy/wzlinux.pem mode http default_backend wzlinuxs backend wzlinuxs mode http balance roundrobin option forwardfor # option httpchk HEAD / HTTP/1.1\r\nHost:localhost server tomcat01 127.0.0.1:8080 check inter 15000 rise 2 fall 4 weight 1 server tomcat02 127.0.0.1:8081 check inter 15000 rise 2 fall 4 weight 1 server tomcat03 127.0.0.1:8082 check inter 15000 rise 2 fall 4 weight 1 server tomcat04 127.0.0.1:8083 check inter 15000 rise 2 fall 4 weight 1 server tomcat05 127.0.0.1:8084 check inter 15000 rise 2 fall 4 weight 1 server tomcat06 127.0.0.1:8085 check inter 15000 rise 2 fall 4 weight 1 server 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 }
二、tomcat的配置设定apache
由于tomcat日志须要知道真正的来源IP是什么,因此默认的是不知足要求的,咱们须要修改日志格式的内容以下。tomcat
<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 "%r" %s %b" /> </Host>