日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > centos >内容正文

centos

Centos 7 安装 Haproxy

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

?

【環(huán)境】

Centos 7.2

Web1:192.168.136.170

web2:192.168.136.166

Haproxy:192.168.136.173

?

【web服務(wù)器1、2】

安裝Nginx(可參考YUM快速搭建LNMP)兩臺(tái)Web服務(wù)器都需要安裝Nginx

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

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服務(wù)器】

yum -y install haproxy

編輯haproxy配置文件

vim /etc/haproxy/haproxy.cfg

(下列紅色的#部分,是需要注釋的,最下方的是web服務(wù)器的地址,如有多個(gè)節(jié)點(diǎn),就繼續(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地址,查看是否會(huì)對(duì)兩臺(tái)web服務(wù)器進(jìn)行輪詢?cè)L問。

?

轉(zhuǎn)載于:https://www.cnblogs.com/willamwang/p/11378323.html

總結(jié)

以上是生活随笔為你收集整理的Centos 7 安装 Haproxy的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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