openstack基础服务运维 RabbitMQ

RabbitMQ消息队列服务

它是应用程序之间的一种通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来去进行通信,而不需要专用连接来链接他们.

轻量级,无论是在本地还是在云端,都非常的容易部署,可以部署在分布式和联合配置中,满足高规模和高可用性的要求.

特点:异步消息\优秀的开发人员体验\分布式的部署\企业级和云端的支持\丰富工具和插件\易管理和监控\

1.rabbitmq服务在centos7上的安装

(1)因为服务是由erlang语言去编写的,在安装mq之前要先安装它的基础编译环境

[root@controller ~]# yum -y install erlang

(2)安装rabbitmq

[root@controller ~]# yum -y install rabbitmq-server     // 安装包可以在官网上查找

[root@controller ~]# systemctl  start rabbitmq-server      //如果启动失败,可以将服务器进行重新启动之后在执行该命令

[root@controller ~]# systemctl  status rabbitmq-server

● rabbitmq-server.service - RabbitMQ broker

   Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)

   Active: active (running) since Wed 2022-10-12 02:31:07 EDT; 2 days ago

 Main PID: 1021 (beam)

   Status: "Initialized"

   CGroup: /system.slice/rabbitmq-server.service

           ├─1021 /usr/lib64/erlang/erts-8.3.5.3/bin/beam -W w -A 64 -P 1048576 -t 5000000 -stbt db -...

           ├─1619 erl_child_setup 1024

           ├─1968 inet_gethost 4

           └─1979 inet_gethost 4

Oct 12 02:30:39 controller systemd[1]: Starting RabbitMQ broker...

Oct 12 02:30:58 controller rabbitmq-server[1021]: RabbitMQ 3.6.16. Copyright (C) 2007-2018 Pivotal...nc.

Oct 12 02:30:58 controller rabbitmq-server[1021]: ##  ##      Licensed under the MPL.  See http://...om/

Oct 12 02:30:58 controller rabbitmq-server[1021]: ##  ##

Oct 12 02:30:58 controller rabbitmq-server[1021]: ##########  Logs: /var/log/rabbitmq/rabbit@contr...log

Oct 12 02:30:58 controller rabbitmq-server[1021]: ######  ##        /var/log/rabbitmq/rabbit@contr...log

Oct 12 02:30:58 controller rabbitmq-server[1021]: ##########

Oct 12 02:30:58 controller rabbitmq-server[1021]: Starting broker...

Oct 12 02:31:07 controller systemd[1]: Started RabbitMQ broker.

Oct 12 02:31:08 controller rabbitmq-server[1021]: completed with 0 plugins.

Hint: Some lines were ellipsized, use -l to show in full.

[root@controller ~]# netstat  -ntpl |grep 15672        //查看服务的端口号

[root@controller ~]# rabbitmq-plugins  enable rabbitmq_management       //启动rabbit插件

The following plugins have been enabled:

  amqp_client

  cowlib

  cowboy

  rabbitmq_web_dispatch

  rabbitmq_management_agent

  rabbitmq_management

Applying plugin configuration to rabbit@controller... started 6 plugins.

[root@controller ~]# netstat  -ntpl |grep 15672          

tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      1021/beam 

测试登录,浏览器打开输入地址192.168.100.10:15672,登录的账号和密码为guest

2.rabbitmq在openstack中的作用

Openstack中与消息相关的几个概念.

Target:指明消息的目标对象,包括一些消息路由器\命名空间\消息主题\版本等信息

Transport:消息通道,负责将消息传递给设定的后端驱动进行消息处理

在Openstack中.任何需要通过Rabbitmq实现消息交互的服务或者模块,都会在服务启动的过程中,初始化相关的rabbitmq的参数,然后获取远程服务对象,并且启动服务流程.

3.运维rabbitmq

(1)用户与权限的管理

[root@controller ~]# rabbitmqctl  --help

Error: could not recognise command

Usage:

rabbitmqctl [-n <node>] [-t <timeout>] [-q] <command> [<command options>]

Options:

    -n node

    -q

    -t timeout

Commands:

    stop [<pid_file>]

    shutdown

    stop_app

    start_app

    wait <pid_file>

    reset

    force_reset

    rotate_logs <suffix>

    hipe_compile <directory>

    join_cluster <clusternode> [--ram]

    cluster_status

    change_cluster_node_type disc | ram

    forget_cluster_node [--offline]

    rename_cluster_node oldnode1 newnode1 [oldnode2] [newnode2 ...]

    update_cluster_nodes clusternode

    force_boot

    sync_queue [-p <vhost>] queue

    cancel_sync_queue [-p <vhost>] queue

    purge_queue [-p <vhost>] queue

    set_cluster_name name

    add_user <username> <password>

    delete_user <username>

    change_password <username> <newpassword>

    clear_password <username>

    authenticate_user <username> <password>

    set_user_tags <username> <tag> ...

    list_users

    add_vhost <vhost>

    delete_vhost <vhost>

    list_vhosts [<vhostinfoitem> ...]

    set_permissions [-p <vhost>] <user> <conf> <write> <read>

    clear_permissions [-p <vhost>] <username>

    list_permissions [-p <vhost>]

    list_user_permissions <username>

    set_parameter [-p <vhost>] <component_name> <name> <value>

    clear_parameter [-p <vhost>] <component_name> <key>

    list_parameters [-p <vhost>]

    set_global_parameter <name> <value>

    clear_global_parameter <name>

    list_global_parameters

    set_policy [-p <vhost>] [--priority <priority>] [--apply-to <apply-to>]

<name> <pattern>  <definition>

    clear_policy [-p <vhost>] <name>

    list_policies [-p <vhost>]

    list_queues [-p <vhost>] [--offline|--online|--local] [<queueinfoitem> ...]

    list_exchanges [-p <vhost>] [<exchangeinfoitem> ...]

    list_bindings [-p <vhost>] [<bindinginfoitem> ...]

    list_connections [<connectioninfoitem> ...]

    list_channels [<channelinfoitem> ...]

    list_consumers [-p <vhost>]

    status

    node_health_check

    environment

    report

...

[root@controller ~]# rabbitmqctl  add_user test 000000         //添加一个test用户

Creating user "test"

[root@controller ~]# rabbitmqctl  delete_user test          //删除一个test用户

Deleting user "test"

[root@controller ~]# rabbitmqctl  change_password test 111111             //修改test用户的密码

Changing password for user "test"

[root@controller ~]# rabbitmqctl  list_users           //列出所有的用户

Listing users

test    []

openstack       []

guest   [administrator]

[root@controller ~]# rabbitmqctl  --help  |grep set    //查询设置权限的参数命令

    set_permissions [-p <vhost>] <user> <conf> <write> <read>    //[-p <vhost>]:代表了路径  <user>:代表了对于哪一个用户进行更改  <conf>:一个正则表达式,允许那些配置资源能够被该用户进行访问 <write>:一个正则表达式,允许那些配置资源能够被该用户进行写  <read>:一个正则表达式,允许那些配置资源能够被该用户进行读

[root@controller ~]# rabbitmqctl  set_permissions test ".*" ".*" ".*"    //给test用户设置所有的权限

Setting permissions for user "test" in vhost "/"

[root@controller ~]# rabbitmqctl  clear_permissions test     //清除test用户的所有权限

Clearing permissions for user "test" in vhost "/"

[root@controller ~]# rabbitmqctl  list_user_permissions test     //列出用户的权限

Listing permissions for user "test"

5.rabbitmq常规的命令

[root@controller ~]# rabbitmq-plugins  enable rabbitmq_management//开启监控管理器

[root@controller ~]# rabbitmq-plugins  disable rabbitmq_management   //关闭监控管理器

[root@controller ~]# rabbitmq-server  start        //开启rabbitmq

[root@controller ~]# rabbitmq-server  stop        //关闭rabbitmq

[root@controller ~]# rabbitmqctl  list_queues      //列出所有的消息队列

Listing queues

conductor_fanout_74a5e6f0b704413eb8a199e15d16ee06       0

q-agent-notifier-port-update_fanout_03da1701628d4654888bd349c858b758    0

cinder-volume_fanout_4f9e8ee87c5148f7adbeb628623161f3   0

neutron-vo-SubPort-1.0  0

q-agent-notifier-network-delete 0

q-agent-notifier-l2population-update.compute    0

q-agent-notifier-network-update.compute 0

scheduler_fanout_592c512b22c74af6ad7c54ef2cf17a5e       0

q-server-resource-versions_fanout_fa04dcf0e1b84cc98afb52c3546d44e8      0

q-agent-notifier-security_group-update.compute  0

q-reports-plugin_fanout_d9b8cd6fb5b44bc2915310497be07a51        0

q-agent-notifier-port-update.controller 0

l3_agent_fanout_0c96b33b19a3463d90f46bb825ce9c29        0

q-agent-notifier-l2population-update_fanout_45efc2a79b4c4821a82e3871544a6cd0    0

q-agent-notifier-network-delete.compute 0

dhcp_agent.controller   0

q-l3-plugin_fanout_ab27815ce7e74fb68545e73f6246e979     0

dhcp_agent_fanout_5369b217fb9b4bbea66e74076add2b2c      0

q-l3-plugin_fanout_af7c7a79edc54a6fb301c5c03e95c416     0

q-agent-notifier-binding-deactivate.compute     0

cinder-scheduler        0

reply_0761780cad4548189d327e79d2501b95  0

l3_agent        0

scheduler       0

neutron-vo-Trunk-1.1.compute    0

q-agent-notifier-network-update 0

compute_fanout_8c3c8103a09e4946b2f7d04aa66453c7 0

q-agent-notifier-network-delete_fanout_c5af4b3246034ab6b3a58aef546adf81 0

neutron-vo-SubPort-1.0_fanout_2b862958c3bd41b99d4e5a35f82fd4db  0

q-agent-notifier-network-update_fanout_813608cddcc74e359d24c8ddf3ce7d5f 0

q-l3-plugin.controller  0

neutron-vo-Trunk-1.1    0

reply_f60a28a97f644ea093d700235389d885  0

q-plugin.controller     0

q-plugin_fanout_ffe63c99cc91437a8de17837d2c7eba0        0

cinder-volume   0

neutron-vo-Trunk-1.1_fanout_80f48c883d5c4a47b470752fc9bd87c4    0

q-agent-notifier-security_group-update_fanout_bef9f3f60d7940faa7e3665cbeab14de  0

q-l3-plugin     0

reply_384ef18cf95a4c7f8f533f220ed719ba  0

neutron-vo-SubPort-1.0.compute  0

q-agent-notifier-binding-deactivate     0

q-agent-notifier-binding-activate.controller    0

neutron-vo-Trunk-1.1_fanout_f2353de43d5642b2a9402ba05ee0733e    0

cinder-volume.compute@lvm       0

q-agent-notifier-binding-activate_fanout_fb9367280c9d4702a8c436f8fc3af558       0

q-agent-notifier-network-update_fanout_36fa3a17b3b34a90aaaf5a3a0330639d 0

q-agent-notifier-network-update.controller      0

q-agent-notifier-l2population-update.controller 0

q-reports-plugin        0

reply_8054c6577da840aa9712896c2457ec5d  0

reply_612ffc60b7c74d7abf3e3c0aaf14b014  0

q-agent-notifier-security_group-update_fanout_341a9facf42d41f3a03760edb30a4b41  0

q-agent-notifier-binding-deactivate_fanout_71572e4b118448f997868826739f55a0     0

q-agent-notifier-l2population-update    0

compute.compute 0

cinder-scheduler_fanout_79fc3bc2cf434404a1ba89c8e8cedf40        0

q-agent-notifier-binding-deactivate.controller  0

q-agent-notifier-port-update_fanout_d852675c672147e8a92869c9bcbdd0ed    0

conductor.controller    0

q-server-resource-versions.controller   0

reply_c6464aba6e7a4f8c8a77115b07ab512e  0

q-agent-notifier-security_group-update  0

neutron-vo-SubPort-1.0_fanout_3f26e448c6034ad69b056ba16eca6aac  0

cinder-volume.compute@lvm_fanout_c6196c9c33bc4a3d8ddf38db0116140d       0

compute 0

q-plugin        0

cinder-volume.compute@lvm.compute       0

q-agent-notifier-network-delete.controller      0

q-reports-plugin_fanout_e843ba2141b143729611e4eeb0ca5d05        0

q-agent-notifier-binding-activate.compute       0

q-agent-notifier-security_group-update.controller       0

q-agent-notifier-port-update    0

q-agent-notifier-network-delete_fanout_62e66efa38624f6982790f5cbcf89acb 0

reply_6289117acc5a482aa1abe9a63a4324b6  0

scheduler.controller    0

q-agent-notifier-binding-deactivate_fanout_080f9e180f1842be8906012d07090d98     0

cinder-scheduler.controller     0

reply_b1a9c36f4d824291b01e4e15a1cc9d4e  0

q-reports-plugin.controller     0

q-agent-notifier-binding-activate       0

l3_agent.controller     0

q-agent-notifier-network-update_fanout_414e2caafde749a6ba8a93079af8a14f 0

dhcp_agent      0

q-server-resource-versions      0

q-agent-notifier-port-update.compute    0

neutron-vo-SubPort-1.0.controller       0

neutron-vo-Trunk-1.1.controller 0

q-agent-notifier-binding-activate_fanout_c210025a37ee4ad8846f3099e91967d3       0

conductor       0

q-agent-notifier-l2population-update_fanout_5c0ee1fa376346d4a8b9335a892ed254    0

[root@controller ~]# rabbitmqctl  reset         //清除所有队列消息,谨慎执行

[root@controller ~]# rabbitmqctl  stop_app      //关闭应用

[root@controller ~]# rabbitmqctl  start_app       //启动应用

6.rabbitmq操作实例

以及群搭建为例,需要用到两个主机,

(1)修改主机名

[root@node-1 ~]# hostnamectl  set-hostname  node-1

[root@node-2 ~]# hostnamectl  set-hostname  node-2

(2)两台节点配置映射文件

[root@node-1 ~]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.200.11 node-1

192.168.200.12 node-2

[root@node-1 ~]# scp /etc/hosts node-2:/etc/hosts

(3)在两台节点上安装rabbitmq

[root@node-1 ~]# yum install rabbitmq-server -y

//安装所用的源可以使用openstack台配置的源

[root@node-1 ~]# systemctl  start rabbit-server     //在node-1节点启动

(4)拷贝cookie文件给第二台节点

[root@controller ~]# scp /var/lib/rabbitmq/.erlang.cookie  node-2:/var/lib/rabbitmq/

(5)启动第二台节点的服务

[root@node-2 ~]# systemctl  start rabbit-server

(6)将node-2节点与node-1节点组成集群

[root@node-2 ~]# rabbitmqctl  stop_app 

[root@node-2 ~]# rabbitmqctl join_cluster rabbit@node-1   //node-1节点接入集群

[root@node-2 ~]# rabbitmqctl  start_app         //开启应用

(7)查看集群的状态

[root@controller ~]# rabbitmqctl  cluster_status    //查看集群状态

//可以观察到node-2节点已经和node-1组成了集群

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值