设置pika的连接socket_time参数超时时间长一些,例如1s: connection = pika.BlockingConnection(pika.ConnectionParameters(host='10.17.1.226',port=5672,credentials=cred,socket_timeout=1)) 显然我的原因是,我没有安装abbitmq-server. # pip3 install rabbitmq //仍然不行!! 5762这个port如何打开呢?就是rabbitmq-server如何启动呢?我在一台服务器上面安装吧。47.95.235.167 root ~ $ apt-get install rabbitmq-server Reading package lists... Done Building dependency tree Reading state information... Done rabbitmq-server is already the newest version (3.5.7-1ubuntu0.16.04.2). 0 upgraded, 0 newly installed, 0 to remove and 96 not upgraded. root ~ $ 启动rabbitmq web服务: 2.远程访问rabbitmq:自己增加一个用户,步骤如下: l1. 创建一个admin用户:sudo rabbitmqctl add_user admin 123123 l2. 设置该用户为administrator角色:sudo rabbitmqctl set_user_tags admin administrator l3. 设置权限:sudo rabbitmqctl set_permissions -p '/' admin '.' '.' '.' l4. 重启rabbitmq服务:sudo service rabbitmq-server restart 之后就能用admin用户远程连接rabbitmq server了。 这就是exchanger的服务安装和启动过程。 结果还是不行!连接超时,我估计是阿里云限制了port=5672的连接请求。添加port放行后,如下: [root@izwz9jay6aqdkrnnlgscchz project]# service rabbitmq-server restart Redirecting to /bin/systemctl restart rabbitmq-server.service [root@izwz9jay6aqdkrnnlgscchz project]# rabbitmqctl add_user admin 123123 Creating user "admin" ... ...done. [root@izwz9jay6aqdkrnnlgscchz project]# rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] ... ...done. [root@izwz9jay6aqdkrnnlgscchz project]# sudo rabbitmqctl set_permissions -p '/' admin '.' '.' '.' Setting permissions for user "admin" in vhost "/" ... ...done. [root@izwz9jay6aqdkrnnlgscchz project]# 这样就可以了。
pika.exceptions.ConnectionClosed: Connection to 127.0.0.1:5672 failed: timeout
最新推荐文章于 2024-09-26 19:30:58 发布