作者:Hily 原始链接:http://hily.me/blog/2010/05/rabbitmq-cluster-from-configfile/ 版权声明:可以转载,转载时务必以超链接形式标明文章原始出处 和作者信息 及版权声明
前一篇日志简单演示了下手动创建集群的过程,可能你已经发现以命令行的方式创建集群多少有些繁琐。 RabbitMQ 提供了一种创建集群的便捷方法——从配置文件创建集群。
环境变量 RABBITMQ_CLUSTER_CONFIG_FILE 指定了集群配置文件所在路径,默认为:/etc/rabbitmq/rabbitmq_cluster.config。 如果需要,可以在启动 RabbitMQ Server 前设置它来改变配置文件路径。 只需要把要组成集群的各个节点以数组的方式写在配置文件中即可,示例: ['test1@gentoo', 'test2@gentoo', 'test3@gentoo'].
清除上篇文章中创建的3个节点: # ./rabbitmqctl -n test1@gentoo stop_app Stopping node test1@gentoo ... ...done. # ./rabbitmqctl -n test1@gentoo reset Resetting node test1@gentoo ... ...done. # ./rabbitmqctl -n test1@gentoo stop Stopping and halting node test1@gentoo ... ...done. # ./rabbitmqctl -n test2@gentoo stop_app Stopping node test2@gentoo ... ...done. # ./rabbitmqctl -n test2@gentoo reset Resetting node test2@gentoo ... ...done. # ./rabbitmqctl -n test2@gentoo stop Stopping and halting node test2@gentoo ... ...done. # ./rabbitmqctl -n test3@gentoo stop_app Stopping node test3@gentoo ... ...done. # ./rabbitmqctl -n test3@gentoo reset Resetting node test3@gentoo ... ...done. # ./rabbitmqctl -n test3@gentoo stop Stopping and halting node test3@gentoo ... ...done.
然后分别启动 RabbitMQ Server 即可(启动时,以上集群配置就会被加载到节点上)。 # export RABBITMQ_NODENAME=test1 # export RABBITMQ_NODE_PORT=5672 # ./rabbitmq-server -detached
# export RABBITMQ_NODENAME=test2 # export RABBITMQ_NODE_PORT=5673 # ./rabbitmq-server -detached
# export RABBITMQ_NODENAME=test3 # export RABBITMQ_NODE_PORT=5674 # ./rabbitmq-server -detached
查看下3个节点的状态: # ./rabbitmqctl -n test1@gentoo status Status of node test1@gentoo ... [..., {nodes,[test3@gentoo,test2@gentoo,test1@gentoo]}, {running_nodes,[test3@gentoo,test2@gentoo,test1@gentoo]}] ...done. # ./rabbitmqctl -n test2@gentoo status Status of node test2@gentoo ... [..., {nodes,[test3@gentoo,test2@gentoo,test1@gentoo]}, {running_nodes,[test3@gentoo,test1@gentoo,test2@gentoo]}] ...done. # ./rabbitmqctl -n test3@gentoo status Status of node test3@gentoo ... [..., {nodes,[test3@gentoo,test2@gentoo,test1@gentoo]}, {running_nodes,[test2@gentoo,test1@gentoo,test3@gentoo]}] ...done.
集群创建完毕!
你可能会问,如何指定某个节点为 ram node 还是 disk node。 通过这种方式创建出来的节点,都是 disk node。 如果需要修改为 ram node,目前只能通过命令来完成了。