疯狂小鸡/ty 发表于 2015-11-20 10:12:47

haproxy简单负载均衡搭建

  最近对负载均衡进行搭建具体方法如下:

[*]haproxy 修改部分(haproxy-cfg.cfg)
global
daemon
maxconn 4500
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 180000ms
stats enable
stats uri /stats
stats auth admin:age!^*
frontend http-in
bind *:<span style=&quot;color: #ff0000;&quot;><strong>9090</strong></span>
default_backend dynamic_servers
backend dynamic_servers
mode http
option httpclose
option forwardfor header X-Forwarded-For
appsession JSESSIONID len 52 timeout 30m
balance roundrobin
server server_9091 191.29.70.6:9091 maxconn 250
server server_9092 191.29.70.6:9092 maxconn 250
server server_9093 191.29.70.6:9093 maxconn 250
server server_9094 191.29.70.6:9094 maxconn 250
server server_9095 191.29.70.6:9095 maxconn 250   使用haproxy做端口转发,只需要修改tomcat的 到不同的端口(保证端口不被占用)
  在haproxy映射即可。
  启动方法 ./haproxy -f haproxy-cfg.cfg
  haproxy 有编译好的版本,也可以自行编译参考方法
  http://wenku.baidu.com/view/0a7a28154431b90d6c85c760.html
  tomcat示例
<!-- Note:A &quot;Server&quot; is not itself a &quot;Container&quot;, so you may not
define subcomponents such as &quot;Valves&quot; at this level.
Documentation at /docs/config/server.html
-->
<Server <strong><span style=&quot;color: #ff0000;&quot;>port=&quot;9005&quot;</span></strong> shutdown=&quot;SHUTDOWN&quot;>
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className=&quot;org.apache.catalina.core.AprLifecycleListener&quot; SSLEngine=&quot;on&quot; />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className=&quot;org.apache.catalina.core.JasperListener&quot; />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className=&quot;org.apache.catalina.mbeans.ServerLifecycleListener&quot; />
<Listener className=&quot;org.apache.catalina.mbeans.GlobalResourcesLifecycleListener&quot; />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name=&quot;UserDatabase&quot; auth=&quot;Container&quot;
type=&quot;org.apache.catalina.UserDatabase&quot;
description=&quot;User database that can be updated and saved&quot;
factory=&quot;org.apache.catalina.users.MemoryUserDatabaseFactory&quot;
pathname=&quot;conf/tomcat-users.xml&quot; />
</GlobalNamingResources>
<!-- A &quot;Service&quot; is a collection of one or more &quot;Connectors&quot; that share
a single &quot;Container&quot; Note:A &quot;Service&quot; is not itself a &quot;Container&quot;,
so you may not define subcomponents such as &quot;Valves&quot; at this level.
Documentation at /docs/config/service.html
-->
<Service name=&quot;Catalina&quot;>
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name=&quot;tomcatThreadPool&quot; namePrefix=&quot;catalina-exec-&quot;
maxThreads=&quot;150&quot; minSpareThreads=&quot;4&quot;/>
-->
<!-- A &quot;Connector&quot; represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJPConnector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector <span style=&quot;color: #ff0000;&quot;><strong>port=&quot;9091&quot;</strong></span> protocol=&quot;HTTP/1.1&quot;
connectionTimeout=&quot;100000&quot;
redirectPort=&quot;8443&quot; URIEncoding=&quot;gbk&quot;/>
<!-- A &quot;Connector&quot; using the shared thread pool-->
<!--
<Connector executor=&quot;tomcatThreadPool&quot;
port=&quot;8081&quot; protocol=&quot;HTTP/1.1&quot;
connectionTimeout=&quot;20000&quot;
redirectPort=&quot;8443&quot; />
-->         
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port=&quot;8443&quot; protocol=&quot;HTTP/1.1&quot; SSLEnabled=&quot;true&quot;
maxThreads=&quot;150&quot; scheme=&quot;https&quot; secure=&quot;true&quot;
clientAuth=&quot;false&quot; sslProtocol=&quot;TLS&quot; />
-->
.....  
  
页: [1]
查看完整版本: haproxy简单负载均衡搭建