HaProxy(无法绑定套接字,选择测试失败)

 蘚小凤_950 发布于 2023-01-07 18:20

各位大家好,我正在研究一个高可用性项目,我不得不为某些应用程序投入生产haproxy.一些基础测试后一切都很好,但我有一些错误,无法解决它.有人有想法吗?

这是测试

#/ usr/sbin/haproxy -d -f /etc/haproxy/haproxy.cfg

Available polling systems : 

 sepoll : pref=400,  test result OK 
 epoll : pref=300,  test result OK 
 poll : pref=200,  test result OK 
 select : pref=150,  test result FAILED 

Total: 4 (3 usable), will use sepoll. 
Using sepoll() as the polling mechanism. 
[ALERT] 174/160258 (22038) : Starting proxy mysql: cannot bind socket 
[ALERT] 174/160258 (22038) : Starting proxy http: cannot bind socket 

有我的文件haproxy.cfg

global 
log 127.0.0.1 local0 notice
user haproxy
group haproxy
maxconn 32000
ulimit-n 65536

defaults
log global
option dontlognull
retries 2
timeout connect 3000
timeout server 5000
timeout client 5000
option redispatch

listen  mysql
bind *:3306
mode tcp
option tcplog
balance roundrobin
option  mysql-check user haproxy_check
server mysql1 10.83.83.167:3306 check
server mysql2 10.83.83.168:3306 check
server mysql3 10.83.83.169:3306 check 

listen  http
mode http
bind *:80
stats enable
stats uri /stats
stats auth admin:HaProxy2014
acl app1_cluster_acl hdr_beg(host) -i app1
acl app2_cluster_acl hdr_beg(host) -i app2
acl mysql_cluster_acl hdr_beg(host) -i mysql
use_backend app1_cluster if app1_cluster_acl
use_backend app2_cluster if app2_cluster_acl
use_backend mysql_cluster if mysql_cluster_acl 

backend app1_cluster
mode http
cookie SERVERID insert indirect nocache
option  forwardfor header X-Real-IP
option  http-server-close
option  httplog
balance roundrobin
server serv1 10.83.83.203:80 check cookie serv1
server serv2 10.83.83.204:80 check cookie serv2 

backend app2_cluster
mode http
cookie SERVERID insert indirect nocache
option  forwardfor header X-Real-IP
option  http-server-close
option  httplog
balance roundrobin
server serv1 10.83.83.187:80 check cookie serv1
server serv2 10.83.83.188:80 check cookie serv2 

backend mysql_cluster
mode http
cookie SERVERID insert indirect nocache
option  forwardfor header X-Real-IP
option  http-server-close
option  httplog
balance roundrobin
server mysql1 10.83.83.167:80 check cookie serv1
server mysql2 10.83.83.168:80 check cookie serv2
server mysql3 10.83.83.169:80 check cookie serv2

小智.. 6

如果我的负载均衡器上已经运行了mysql或http服务,除了后端运行,我也会遇到同样的错误.

例如,如果nginx/apache已在我的负载均衡器上运行.

$ netstat -anp | grep ":80"
tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      3646/nginx    

我尝试用bind*:80启动我的负载均衡器, 我得到了类似的错误.

$ haproxy -d -f /etc/haproxy/haproxy.cfg
Available polling systems :
      epoll : pref=300,  test result OK
      poll : pref=200,  test result OK
     select : pref=150,  test result FAILED
Total: 3 (2 usable), will use epoll.
Using epoll() as the polling mechanism.
[ALERT] 195/001456 (1903) : Starting frontend www: cannot bind socket [0.0.0.0:80]

如果你需要在127.0.0.1上监听mysql或http实例,那么你可以在bind调用中指定另一个接口的ip.

bind: 10.0.0.20:80

使用最新版本的haproxy,您甚至可以使用变量.

bind ${LB1}:80

并从haproxy启动脚本或/ etc/default/haproxy导出这些

export LB1="10.0.0.20"

否则,您的haproxy启动脚本可能存在问题.

1 个回答
  • 如果我的负载均衡器上已经运行了mysql或http服务,除了后端运行,我也会遇到同样的错误.

    例如,如果nginx/apache已在我的负载均衡器上运行.

    $ netstat -anp | grep ":80"
    tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      3646/nginx    
    

    我尝试用bind*:80启动我的负载均衡器, 我得到了类似的错误.

    $ haproxy -d -f /etc/haproxy/haproxy.cfg
    Available polling systems :
          epoll : pref=300,  test result OK
          poll : pref=200,  test result OK
         select : pref=150,  test result FAILED
    Total: 3 (2 usable), will use epoll.
    Using epoll() as the polling mechanism.
    [ALERT] 195/001456 (1903) : Starting frontend www: cannot bind socket [0.0.0.0:80]
    

    如果你需要在127.0.0.1上监听mysql或http实例,那么你可以在bind调用中指定另一个接口的ip.

    bind: 10.0.0.20:80
    

    使用最新版本的haproxy,您甚至可以使用变量.

    bind ${LB1}:80
    

    并从haproxy启动脚本或/ etc/default/haproxy导出这些

    export LB1="10.0.0.20"
    

    否则,您的haproxy启动脚本可能存在问题.

    2023-01-07 18:23 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有