内容简介:如果您考虑通过RabbitMQ实现更大规模的AMQP基础架构,那么肯定会尝试使用Ansible作为基础架构部署者,因为Ansible的RabbitMQ模块非常容易使用,让我们举个例子。任务:使用名称:ansible_exchange创建DIRECT交换,ansible_exchange绑定两个队列myRemoteQueue1 和myRemoteQueue2,路由键为key1和key2。
如果您考虑通过RabbitMQ实现更大规模的AMQP基础架构,那么肯定会尝试使用Ansible作为基础架构部署者,因为Ansible的RabbitMQ模块非常容易使用,让我们举个例子。
任务:
使用名称:ansible_exchange创建DIRECT交换,ansible_exchange绑定两个队列myRemoteQueue1 和myRemoteQueue2,路由键为key1和key2。
让我们为这个任务来创建用于基础设施的部署容易ansible角色:
../roles/create_infra/tasks/main.yml
# Create exchange on remote host
- rabbitmq_exchange:
name: ansible_exchange
type: direct
login_user: guest
login_password: guest
login_port: 15672
# Create a queues on remote host
- rabbitmq_queue:
name: <font>"{{item}}"</font><font>
login_user: guest
login_password: guest
login_host: localhost
login_port: 15672
with_items:
- myRemoteQueue1
- myRemoteQueue2
- rabbitmq_binding:
name: ansible_exchange
destination: myRemoteQueue1
type: queue
routing_key: key1
- rabbitmq_binding:
name: ansible_exchange
destination: myRemoteQueue2
type: queue
routing_key: key2
</font>
并使用简单的基本剧本启动此角色:
infra.yml:
- hosts:localhost
gather_facts:false
roles:
- create_infra
我相信create_infra的任务代码是selfexplanatory,有关更多信息,请参阅以下内容:
http:<font><i>//docs.ansible.com/ansible/latest/rabbitmq_exchange_module.html http://docs.ansible.com/ansible/latest/rabbitmq_binding_module.html http://docs.ansible.com/ansible/latest/rabbitmq_queue_module.html</i></font><font> </font>
现在让我们来启动infra.yml playbook:
$ ansible-playbook infra.yml
PLAY [localhost] ******************************************************************************************************************************************************************** TASK [create_infra : rabbitmq_exchange] ********************************************************************************************************************************************* changed: [localhost] TASK [create_infra : rabbitmq_queue] ************************************************************************************************************************************************ ok: [localhost] => (item=myRemoteQueue1) ok: [localhost] => (item=myRemoteQueue2) TASK [create_infra : rabbitmq_binding] ********************************************************************************************************************************************** changed: [localhost] TASK [create_infra : rabbitmq_binding] ********************************************************************************************************************************************** changed: [localhost] PLAY RECAP ************************************************************************************************************************************************************************** localhost : ok=4 changed=3 unreachable=0 failed=0
并检查剧本是否符合我们的要求:
exchange创建验证:
$ ./rabbitmqctl list_exchanges | grep <font>"ansible_"</font><font> ansible_exchange direct </font>
队列创建验证:
$ ./rabbitmqctl list_queues | grep myRemoteQueue* myRemoteQueue1 0 myRemoteQueue2 0
绑定创建验证:
$ ./rabbitmqctl list_bindings | grep ansible_ ansible_exchange exchange myRemoteQueue1 queue key1 [] ansible_exchange exchange myRemoteQueue2 queue key2 []
伙计们,使用Ansible的AMQP模块并享受乐趣!
以上所述就是小编给大家介绍的《如何使用ANSIBLE在远程主机上创建RabbitMQ》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Pattern Recognition and Machine Learning
Christopher Bishop / Springer / 2007-10-1 / USD 94.95
The dramatic growth in practical applications for machine learning over the last ten years has been accompanied by many important developments in the underlying algorithms and techniques. For example,......一起来看看 《Pattern Recognition and Machine Learning》 这本书的介绍吧!