Centos 7 安装 Haproxy
生活随笔
收集整理的這篇文章主要介紹了
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 nginxweb2:
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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML 基本标签
- 下一篇: 安装与使用 Trac 来管理项目