日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Centos 7 安装 Haproxy

發(fā)布時間:2025/10/17 84 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Centos 7 安装 Haproxy 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

【環(huán)境】

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

為了方便區(qū)分web服務器,我們編輯下首頁

web1:?

echo 'This is web 1' > /usr/share/nginx/html/index.htmlsystemctl restart nginx

web2:

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服務器的地址,如有多個節(jié)點,就繼續(xù)添加)

#--------------------------------------------------------------------- # 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的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。