当前位置:
首页 >
Centos 7 安装 Haproxy
发布时间:2025/10/17
107
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Centos 7 安装 Haproxy
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
【环境】
Centos 7.2
Web1:192.168.136.170
web2:192.168.136.166
Haproxy:192.168.136.173
【web服务器1、2】
安装Nginx(可参考YUM快速搭建LNMP)两台Web服务器都需要安装Nginx
为了方便区分web服务器,我们编辑下首页
web1:
echo 'This is web 1' > /usr/share/nginx/html/index.htmlsystemctl restart nginxweb2:
echo 'This is web 1' > /usr/share/nginx/html/index.htmlsystemctl restart nginx
【Haproxy服务器】
yum -y install haproxy
编辑haproxy配置文件
vim /etc/haproxy/haproxy.cfg
(下列红色的#部分,是需要注释的,最下方的是web服务器的地址,如有多个节点,就继续添加)
#--------------------------------------------------------------------- # 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/haproxypidfile /var/run/haproxy.pidmaxconn 4000user haproxygroup haproxydaemon# 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/8 # option redispatchretries 3timeout http-request 10stimeout queue 1mtimeout connect 10stimeout client 1mtimeout server 1mtimeout http-keep-alive 10stimeout check 10smaxconn 3000#--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend main *:5000acl url_static path_beg -i /static /images /javascript /stylesheetsacl url_static path_end -i .jpg .gif .png .css .jsuse_backend static if url_staticdefault_backend app#--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- backend staticbalance roundrobinserver static 127.0.0.1:4331 check#--------------------------------------------------------------------- # round robin balancing between the various backends #--------------------------------------------------------------------- backend appbalance roundrobinserver app1 127.0.0.1:5001 checkserver app2 127.0.0.1:5002 checkserver app3 127.0.0.1:5003 checkserver app4 127.0.0.1:5004 check listen webcluster 0.0.0.0:80option httpchk GET /index.htmloption persistbalance roundrobin server inst1 192.168.136.170 check inter 2000 fall 3server inst2 192.168.136.166 check inter 2000 fall 3然后访问haproxy地址,查看是否会对两台web服务器进行轮询访问。
转载于:https://www.cnblogs.com/willamwang/p/11378323.html
总结
以上是生活随笔为你收集整理的Centos 7 安装 Haproxy的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: HTML 基本标签
- 下一篇: Centos7.x 安装 Supervi