歡迎您光臨本站 註冊首頁

haproxy 安裝與配置

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

hi 歡迎閱讀此文,此文主要講解 haproxy 的安裝與配置,還有兩個shell script :

haproxy_install.sh 用於haproxy安裝與配置

haproxy.sh 用於管理haproxy 服務,功能 開啟 關閉 重啟

此文沒有介紹haproxy ,因為既然您來到這裡,說明您很關心haproxy 可能早就聞其大名了(4,7層負載均衡軟體),haproxy 優點與強大的功能我就不重複了,好了下面開始!

1 haproxy 配置文檔,#號為註釋,用於功能說明

  1. cat /usr/local/haproxy/haproxy.cfg
  2. global
  3. log 127.0.0.1 local0
  4. maxconn 4096 #最大連接數
  5. chroot /usr/local/haproxy #安裝目錄
  6. uid 99 #用戶haproxy
  7. gid 99 #組haproxy
  8. daemon #守護進程運行
  9. nbproc 1 #進程數量
  10. pidfile /usr/local/haproxy/logs/haproxy.pid #haproxy pid
  11. defaults
  12. log global
  13. mode http #7層 http;4層tcp
  14. option httplog #http 日誌格式
  15. option httpclose #主動關閉http通道
  16. option redispatch #serverId對應的伺服器掛掉后,強制定向到其他健康的伺服器
  17. option dontlognull
  18. maxconn 2000 #最大連接數
  19. contimeout 5000 #連接超時(毫秒)
  20. clitimeout 50000 #客戶端超時(毫秒)
  21. srvtimeout 50000 #伺服器超時(毫秒)
  22. frontend haproxy_test #定義前端伺服器(haproxy)
  23. bind *:80 #監聽地址
  24. default_backend server_pool #指定後端伺服器群
  25. #errorfile 502 /usr/local/haproxy/html/maintain.html
  26. #errorfile 503 /usr/local/haproxy/html/maintain.html
  27. #errorfile 504 /usr/local/haproxy/html/maintain.html
  28. backend server_pool #定義後端伺服器群(web server/apache/nginx/iis..)
  29. mode http
  30. option forwardfor #後端伺服器(apache/nginx/iis/*),從Http Header中獲得客戶端IP
  31. #balance roundrobin #負載均衡的方式,輪詢方式
  32. balance leastconn #負載均衡的方式,最小連接
  33. cookie SERVERID #插入serverid到cookie中,serverid後面可以定義
  34. option httpchk HEAD /check.html #用來做健康檢查html文檔
  35. server server1 10.0.1.252:80 cookie server1 check inter 2000 rise 3 fall 3 weight 3
  36. server server2 10.0.1.253:80 cookie server2 check inter 2000 rise 3 fall 3 maxconn 120 weight 3
  37. server server3 10.0.1.254:80 cookie server3 check maxconn 90 rise 2 fall 3 weight 3
  38. #伺服器定義:
  39. #cookie server1表示serverid為server1;
  40. #check inter 2000 是檢測心跳頻率(check 默認 );
  41. #rise 3 表示 3次正確認為伺服器可用;
  42. #fall 3 表示 3次失敗認為伺服器不可用;
  43. #weight 表示權重.
  44. listen admin_stat #status
  45. bind *:8080 #監聽埠
  46. mode http #http的7層模式
  47. stats refresh 30s #統計頁面自動刷新時間
  48. stats uri /haproxy-stats #統計頁面URL
  49. stats realm Haproxy\ Statistics #統計頁面密碼框上提示文本
  50. stats auth admin:admin #統計頁面用戶名和密碼設置
  51. stats hide-version #隱藏統計頁面上HAProxy的版本信息
  52. stats admin if TRUE #手工啟用/禁用,後端伺服器

2 haproxy 安裝腳本

這裡

3 haproxy 服務腳本

這裡

4 運行 haproxy

  1. ./haproxy.sh
  2. usage: ./haproxy.sh {start|stop|restart}
  3. ./haprroxy.sh start

5 haproxy 監控頁面

http://yourip:8080/haproxy-stats

用戶名與密碼:admin

結束

shell 腳本如有bug ,歡迎反饋!



[火星人 ] haproxy 安裝與配置已經有349次圍觀

http://coctec.com/docs/linux/show-post-45967.html