HAProxy的設定主要可以分為三個部分:
- command-line最為優先
- cfg檔的global section做全域設定
- cfg檔的proxy section做其他設定(“defaults", “listen", “frontend", “backend")
HAProxy會試著透過frontend端的socket監聽client的request,經過Http Header的驗證或修改後,再轉送到backend端來執行。
$ cat /etc/haproxy/haproxy.cfg
global #global section
# 1.Process Management And Security
chroot [jail dir] #執行chroot(),把process搬到jail dir運行,提高安全性
daemon #執行fork,在背後運行一個相同的process
gid [number] #把group ID設成數字
group [group name] #把group ID設成名字
log [address] [facility] [max level] #syslog server設定位址、實施應用類型,以及log必須具備等級
log-send-hostname [name] #在syslog表頭設定hostname
log-tag [string] #在syslog表頭設定tag,預設tag為program name
pidfile [pidfile] #把所有daemons的pid紀錄到這個pidfile
stats socket #在path創建一個UNIX Socket
stats timeout [timeout, in milliseconds] #stats socket的timeout預設10秒
stats maxconn [conn] #stats socket的連接數量預設10
uid [number] #把user ID設成數字
user [user name] #把user ID設成名字
node [name] #設定node name
description [text] #設定一段文字來描述這個實體
# 2.Performance Tuning
maxconn [number] #設定每個process最大可連接數量
maxpipes [number] #設定每個process最大pipes數量
noepoll #no epoll,禁用epoll(註:epoll可支援打開大量socket)
nopoll #no poll,禁用poll
spread-checks <0..50, in percent> #避免同時送出health check到server,增加隨機性
tune.XXXXX #其他tune相關設定
# 3.Userlists
userlist [list name]
group [groupname] [users [user],[user],(...)]
user [username] [password|insecure-password [password]] [groups [group],[group],(...)]
#例如:
#userlist L1
# group G1 users tiger,scott
# group G2 users xdb,scott
# user tiger password $6$k6y3o.eP$JlKBx9za9667qe4(...)xHSwRv6J.C0/D7cV91
# user scott insecure-password elgato
# user xdb insecure-password hello
