高可用RabbitMQ集群安装配置(4)

主节点:

vrrp_script chk_haproxy { script "/etc/keepalived/scripts/haproxy_check.sh" interval 2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 101 unicast_src_ip 192.168.12.192 unicast_peer { 192.168.12.194 } authentication { auth_type PASS auth_pass rabbitmq } virtual_ipaddress { 192.168.12.111 } track_script { chk_haproxy } notify_master "/etc/keepalived/scripts/haproxy_master.sh" }

chk_haproxy.sh

#!/bin/bash LOGFILE="/var/log/keepalived-ha-state.log" echo "===========================================" >> \$LOGFILE date +%Y%m%d-%H:%M:%S >> \$LOGFILE pid1=\`ps aux|grep /etc/haproxy/haproxy.cfg | grep -v grep | grep -v bash | wc –l\` if [ "\$pid1" = "0" ]; then echo "Ready to start haproxy....." >> \$LOGFILE haproxy -f /etc/haproxy/haproxy.cfg –D

启动Haproxy

pid2=\`ps aux|grep /etc/haproxy/haproxy.cfg | grep -v grep | grep -v bash |wc –l\` if [ "\$pid2" = "0" ]; then echo "Haproxy failed to start !!! So,stop keepalived!!!" >> \$LOGFILE /etc/init.d/keepalived stop else echo "Haproxy start success........." >> \$LOGFILE fi fi

haproxy_master.sh

#!/bin/bash LOGFILE="/var/log/keepalived-ha-state.log" echo "===========================================" >> $LOGFILE date +%Y%m%d-%H:%M:%S >> $LOGFILE echo "Switch to here....." >> $LOGFILE

集群搭建完毕!

常用命令 rabbitmqctl命令

1). 服务器启动与关闭
启动: rabbitmq-server –detached
关闭:rabbitmqctl stop
若单机有多个实例,则在rabbitmqctlh后加–n 指定名称

2). 插件管理
开启某个插件:rabbitmq-pluginsenable xxx
关闭某个插件:rabbitmq-pluginsdisablexxx
注意:重启服务器后生效。

3).virtual_host管理
新建virtual_host: rabbitmqctladd_vhost xxx
撤销virtual_host:rabbitmqctl delete_vhost xxx

4). 用户管理
新建用户:rabbitmqctl add_user xxxpwd
删除用户: rabbitmqctl delete_user xxx
改密码: rabbimqctlchange_password {username} {newpassword}
设置用户角色:rabbitmqctlset_user_tags {username} {tag …}
Tag可以为 administrator,monitoring, management

5). 权限管理
权限设置:set_permissions [-pvhostpath] {user} {conf} {write} {read}
Vhostpath
Vhost路径
user
用户名
Conf
一个正则表达式match哪些配置资源能够被该用户访问。
Write
一个正则表达式match哪些配置资源能够被该用户读。
Read
一个正则表达式match哪些配置资源能够被该用户访问。

6). 获取服务器状态信息
服务器状态:rabbitmqctl status
队列信息:rabbitmqctl list_queues[-p vhostpath] [queueinfoitem …]
Queueinfoitem可以为:name,durable,auto_delete,arguments,messages_ready,messages_unacknowledged,messages,consumers,memory
Exchange信息:rabbitmqctllist_exchanges[-p vhostpath] [exchangeinfoitem …]
Exchangeinfoitem有:name,type,durable,auto_delete,internal,arguments.
Binding信息:rabbitmqctllist_bindings[-p vhostpath] [bindinginfoitem …]
Bindinginfoitem有:source_name,source_kind,destination_name,destination_kind,routing_key,arguments
Connection信息:rabbitmqctllist_connections [connectioninfoitem …]
Connectioninfoitem有:recv_oct,recv_cnt,send_oct,send_cnt,send_pend等。
Channel信息:rabbitmqctl list_channels[channelinfoitem …]
Channelinfoitem有consumer_count,messages_unacknowledged,messages_uncommitted,acks_uncommitted,messages_unconfirmed,prefetch_count,client_flow_blocked

rabbimq-plugins

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/df0ffabec4837e9a57dc842da7aa2861.html