参考

  1. https://www.cnblogs.com/nihaorz/p/10783249.html

config

  1. global
  2. log 127.0.0.1 local0
  3. log 127.0.0.1 local1 notice
  4. maxconn 4096
  5. #chroot /usr/share/haproxy
  6. #user haproxy
  7. #group haproxy
  8. daemon
  9. defaults
  10. log global
  11. mode http
  12. option httplog
  13. option dontlognull
  14. retries 3
  15. option redispatch
  16. timeout connect 5000
  17. timeout client 50000
  18. timeout server 50000
  19. # 统计页面配置
  20. listen admin_stats
  21. bind 0.0.0.0:50000 # 监听IP和端口,为了安全可以设置本机的局域网IP及端口;
  22. mode http
  23. option httplog # 采用http日志格式
  24. stats refresh 30s # 统计页面自动刷新时间
  25. stats uri /haproxy?stats # 状态管理页面,通过/haproxy?stats来访问
  26. stats realm Haproxy Manager # 统计页面密码框上提示文本
  27. stats auth admin:psadmin # 统计页面用户名和密码设置
  28. #stats hide-version # 隐藏统计页面上HAProxy的版本信息
  29. #errorfile 403 /usr/local/haproxy/examples/errorfiles/ #设置haproxy 错误页面
  30. frontend fe_k8s_6444
  31. bind *:6444
  32. mode tcp
  33. timeout client 1h
  34. log global
  35. option tcplog
  36. default_backend be_k8s_6443
  37. acl is_websocket hdr(Upgrade) -i WebSocket
  38. acl is_websocket hdr_beg(Host) -i ws
  39. backend be_k8s_6443
  40. mode tcp
  41. timeout queue 1h
  42. timeout server 1h
  43. timeout connect 1h
  44. log global
  45. balance roundrobin
  46. server rancher01 192.168.75.161:6443
  47. server rancher02 192.168.75.162:6443
  48. server rancher03 192.168.75.163:6443

运行

  1. docker run -d -p 8080 -p 30001 --name haproxy -v /root/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro haproxy:1.9.11