设为首页 收藏本站
查看: 1950|回复: 0

[经验分享] haproxy简单负载均衡搭建

[复制链接]
累计签到:15 天
连续签到:1 天
发表于 2015-11-20 10:12:47 | 显示全部楼层 |阅读模式
  最近对负载均衡进行搭建具体方法如下:

  • 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 AJP  Connector: /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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-141418-1-1.html 上篇帖子: freebsd+nginx+mysql+php-fpm+phpmyadmin+haproxy安装日志 下篇帖子: linux下haproxy1.5.11配置文件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表