本文共 4913 字,大约阅读时间需要 16 分钟。
cd /home/hylink/tar zxvf haproxy-1.8.12.tar.gzcd zxvf haproxy-1.8.12
make TARGET=linux2628 ARCH=x86_64 PREFIX=/home/hylink/haproxymake install PREFIX=/home/hylink/haproxy
sudo gedit /home/hylink/haproxy/sbin/haproxy.cfg
添加以下内容:
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice daemon nbproc 2 maxconn 51200 pidfile /home/hylink/haproxy/sbin/haproxy.pid defaults log global mode http option httplog option dontlognull retries 3 option abortonclose timeout connect 5000ms timeout client 30000ms timeout server 60000ms balance roundrobinlisten stats bind *:9080 mode http option httplog maxconn 10 stats refresh 30s stats uri /stats stats realm Haproxy Manager stats hide-version stats admin if TRUE
/home/hylink/haproxy/sbin/haproxy -f /home/hylink/haproxy/sbin/haproxy.cfg
如果出现以下异常:
[WARNING] 227/155234 (4947) : Proxy 'stats': in multi-process mode, stats will be limited to process assigned to the current request.[WARNING] 227/155234 (4947) : Proxy 'stats': stats admin will not work correctly in multi-process mode.[WARNING] 227/155234 (4947) : [/home/hylink/haproxy/sbin/haproxy.main()] Cannot raise FD limit to 102411, limit is 4096.[WARNING] 227/155234 (4947) : [/home/hylink/haproxy/sbin/haproxy.main()] FD limit (4096) too low for maxconn=51200/maxsock=102411. Please raise 'ulimit-n' to 102411 or more to avoid any trouble.
解决方案:
/etc/security/limits.conf
,添加以下内容:* soft nofile = 32768* hard nofile = 65536
/etc/profile
,添加以下内容:ulimit -n 32768
sudo -sulimit -n 32768source /etc/profile
然后重新启动 Haproxy:
/home/hylink/haproxy/sbin/haproxy -f /home/hylink/haproxy/sbin/haproxy.cfg
./bin/emqttd_ctl cluster status
在 haproxy.cfg
中添加以下内容:
listen mqttbind *:1890mode tcpmaxconn 50000option clitcpkatimeout client 3htimeout server 3hoption tcplogbalance leastconnserver emq1 172.19.12.231:1883 check inter 10000 fall 2 rise 5 weight 1server emq2 172.19.12.207:1883 check inter 10000 fall 2 rise 5 weight 1
/home/hylink/haproxy/sbin/haproxy -f /home/hylink/haproxy/sbin/haproxy.cfg
acl denali_policy hdr_reg(host) -i ^(www.inbank.com|image.inbank.com)$acl tm_policy hdr_dom(host) -i www.inbank.comacl invalid_req url_sub -i sip_apiname=acl timetask_req url_dir -i timetaskacl missing_cl hdr_cnt(Content-length) eq 0
block if missing_clblock if !invalid_req || timetask_requse_backend denali_server if denali_policyuse_backend tm_server if tm_policyuse_backend ^[^\ ]*\ /(img|css)/ dynamicuse_backend ^[^\ ]*\ /admin/stats statsdefault_backend mms
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice daemon nbproc 1 maxconn 4096 # 用户和组 # pidfile /var/run/haproxy.pid # ulimit-n 819200 # chroot /usr/share/haproxy debug quiet
defaults log global mode http option httplog option dontlognull retries 2 option httpclose option abortonclose maxconn 4096 timeout connect 5000ms timeout client 30000ms timeout server 30000ms balance roundrobin
listen statsbind 0.0.0.0:1080mode httpoption httplogmaxconn 10stats refresh 30sstats uri /statsstats realm XingCloud Haproxystats auth admin:adminstats auth Frank:Frankstats hide-versionstats admin if TRUE
#errorfile 403 /home/haproxy/haproxy/errorfiles/403.http#errorfile 500 /home/haproxy/haproxy/errorfiles/500.http#errorfile 502 /home/haproxy/haproxy/errorfiles/502.http#errorfile 503 /home/haproxy/haproxy/errorfiles/503.http#errorfile 504 /home/haproxy/haproxy/errorfiles/504.http
frontend mainbind *:80acl web hdr(host) -i www.abc.comacl img hdr(host) -i img.abc.comuse_backend webserver if webuse_backend imgserver if imgdefault_backend dynamic
backend webservermode httpbalance roundrobinoption httpchk /index.html HTTP/1.0server web1 10.16.0.9:8085 cookie 1 weight 5 check inter 2000 rise 2 fall 3server web2 10.16.0.10:8085 cookie 2 weight 3 check inter 2000 rise 2 fall 3backend imgservermode httpoption httpchk /index.phpbalance roundrobinserver img01 192.168.137.101:80 check inter 2000 fall 3server img02 192.168.137.102:80 check inter 2000 fall 3backend dynamicbalance roundrobinserver test1 192.168.1.23:80 check maxconn 2000server test2 192.168.1.24:80 check maxconn 2000listen tcptestbind 0.0.0.0:5222mode tcpoption tcplogbalance sourceserver s1 192.168.100.204:7222 weight 1server s2 192.168.100.208:7222 weight 1
转载地址:http://stffk.baihongyu.com/