global
daemon
nbproc 1
pidfile /var/run/haproxy.pid
ulimit -n 65535
defaults
mode tcp #mode { tcp|http|health },tcp 表示4層,http表示7層,health僅作爲健康檢查使用
retries 2 #嘗試2次失敗則從集羣摘除
option redispatch #如果失效則強制轉換其他服務器
option abortonclose #連接數過大自動關閉
maxconn 1024 #最大連接數
timeout connect 1d #連接超時時間,重要,hive查詢數據能返回結果的保證
timeout client 1d #同上
timeout server 1d #同上
timeout check 2000 #健康檢查時間
log 127.0.0.1 local0 err #[err warning info debug]
listen admin_stats #定義管理界面
bind 0.0.0.0:1090 #管理界面訪問IP和端口
mode http #管理界面所使用的協議
maxconn 10 #最大連接數
stats refresh 30s #30秒自動刷新
stats uri / #訪問url
stats realm Hive\ Haproxy #驗證窗口提示
stats auth admin:123456 #401驗證用戶名密碼
listen hive #hive後端定義
bind 0.0.0.0:10001 #ha作爲proxy所綁定的IP和端口
mode tcp #以4層方式代理,重要
balance leastconn #調度算法 'leastconn' 最少連接數分配,或者 'roundrobin',輪詢分配
maxconn 1024 #最大連接數
server hive_1 192.168.1.1:10000 check inter 180000 rise 1 fall 2
server hive_2 192.168.1.2:10000 check inter 180000 rise 1 fall 2
#釋義:server 主機代名(你自己能看懂就行),IP:端口 每180000毫秒檢查一次。也就是三分鐘。
#hive每有10000端口的請求就會創建一個log,設置短了,/tmp下面會有無數個log文件,刪不完。
haproxy -f conf.cfg