1. 程式人生 > >HAproxy負載均衡部署

HAproxy負載均衡部署

null ide gas have dont 用戶組 adding net sock

HAproxy負載均衡部署

1、安裝HAproxy

yum -y install haproxy

2、編輯配置文件

#---------------------------------------------------------------------
# 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/haproxy    #定義haproxy的家目錄, pidfile /var/run/haproxy.pid #定義pid maxconn 4000        #設置最大並發連接數 user haproxy        #用戶名 group haproxy        #用戶組 daemon        #以守護進程模式運行 # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the listen and backend sections will # use if not designated in their block #--------------------------------------------------------------------- defaults #默認參數 mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 listen stats #狀態信息 mode http bind *:1080 #綁定端口 stats enable #開啟或者關閉 stats hide-version #關閉版本信息 stats uri /haproxy?admin #web狀態界面的url stats realm Haproxy\ Statistics # stats auth admin:admin #認證的用戶名:密碼 stats admin if TRUE #如果認證成功開啟admin frontend http-in #前端配置 bind *:80 #前端綁定端口 mode http #http log global #全局日誌 option httpclose # option logasap capture request header Host len 20 capture request header Referer len 60 default_backend http-server backend http-server #後端web服務集群 balance roundrobin #調度算法模式 server web1 192.168.10.150:81 check maxconn 4000 #後端web列表 server web2 192.168.10.122:80 check maxconn 3000

HAproxy負載均衡部署