• RabbitMQ单节点安装/使用!


    
    
    在开始之前一定要看官方文档,教程不一定是最新的
    官方文档:https://www.rabbitmq.com/install-rpm.html
    安装Erlang:
    本人用yum仓库安装
    
    1)vim /etc/yum.repos.d/rabbitmq-erlang.repo
    
    [rabbitmq-erlang]
    name=rabbitmq-erlang
    baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7
    gpgcheck=1
    gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
    repo_gpgcheck=0
    enabled=1
    
    yum clean all
    yum makecache
    
    2)然后下载RabbitMQ的rpm包(http://www.rabbitmq.com/download.html)
    这里是centos7的版本:
      wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.4/rabbitmq-server-3.7.4-1.el7.noarch.rpm
      yum install rabbitmq-server-3.7.4-1.el7.noarch.rpm
    yum会自动去源里安装依赖包
    3)优化配置
       [root@sh-op-mq01 ~]# cat /etc/security/limits.conf
       ....... 
       * soft nofile 65535
       * hard nofile 65535 
      
      [root@sh-op-mq01 ~]# ulimit -n 
      65535 
      
      [root@sh-op-mq01 ~]# vim /etc/sysctl.conf //添加下面一行 
      fs.file-max = 100000 
    
      [root@sh-op-mq01 ~]# sysctl -p
    
    4)启动RabbitMQ
      [root@sh-op-mq01 ~]# systemctl enable rabbitmq-server.service 
    
      [root@sh-op-mq01 ~]# systemctl start/restart/stop/status rabbitmq-server.service 
    
      RabbitMQ默认监听端口是15672 
      [root@sh-op-mq01 rabbitmq]# lsof -i:15672 
      COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME beam.smp 12776 rabbitmq 50u IPv4 582895 0t0 TCP *:15672 (LISTEN)
    
      默认RabbitMQ的安装目录路径是/var/lib/rabbitmq、默认log路径是/var/log/rabbitmq/ 
      [root@sh-op-mq01 ~]# rabbitmqctl --help 
      [root@sh-op-mq01 ~]# rabbitmqctl status 
      [root@sh-op-mq01 ~]# rabbitmqctl environment 
    
    5) 可以自定义RabbitMQ配置
      [root@sh-op-mq01 ~]# cd /etc/rabbitmq/
      [root@sh-op-mq01 rabbitmq]# cat rabbitmq-env.conf
      LOG_BASE=/data/log/rabbitmq                            //定义RabbitMQ的日志路径
     
      [root@sh-op-mq01 rabbitmq]# mkdir /data/log/rabbitmq
      [root@sh-op-mq01 rabbitmq]# chown -R rabbitmq.rabbitmq /data/log/rabbitmq
     
    6)重启RabbitMQ
      [root@sh-op-mq01 rabbitmq]# systemctl restart rabbitmq-server.service
     
    rabbit-server当前状态:
    
    [root@sh-op-mq01 rabbitmq]# rabbitmqctl status
    Status of node 'rabbit@sh-op-mq01' ...
    [{pid,12776},
     {running_applications,
         [{rabbitmq_management,"RabbitMQ Management Console","3.6.5"},
          {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.6.5"},
          {webmachine,"webmachine","1.10.3"},
          {mochiweb,"MochiMedia Web Server","2.13.1"},
          {rabbitmq_management_agent,"RabbitMQ Management Agent","3.6.5"},
          {rabbit,"RabbitMQ","3.6.5"},
          {os_mon,"CPO  CXC 138 46","2.2.14"},
          {ssl,"Erlang/OTP SSL application","5.3.3"},
          {public_key,"Public key infrastructure","0.21"},
          {crypto,"CRYPTO version 2","3.2"},
          {amqp_client,"RabbitMQ AMQP Client","3.6.5"},
          {rabbit_common,[],"3.6.5"},
          {inets,"INETS  CXC 138 49","5.9.8"},
          {mnesia,"MNESIA  CXC 138 12","4.11"},
          {compiler,"ERTS  CXC 138 10","4.9.4"},
          {xmerl,"XML parser","1.3.6"},
          {syntax_tools,"Syntax tools","1.6.13"},
          {asn1,"The Erlang ASN1 compiler version 2.0.4","2.0.4"},
          {ranch,"Socket acceptor pool for TCP protocols.","1.2.1"},
          {sasl,"SASL  CXC 138 11","2.3.4"},
          {stdlib,"ERTS  CXC 138 10","1.19.4"},
          {kernel,"ERTS  CXC 138 10","2.16.4"}]},
     {os,{unix,linux}},
     {erlang_version,
         "Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:128] [hipe] [kernel-poll:true]
    "},
     {memory,
         [{total,61117832},
          {connection_readers,0},
          {connection_writers,0},
          {connection_channels,0},
          {connection_other,2800},
          {queue_procs,2800},
          {queue_slave_procs,0},
          {plugins,669584},
          {other_proc,19656864},
          {mnesia,67096},
          {mgmt_db,521824},
          {msg_index,39960},
          {other_ets,1445264},
          {binary,29648},
          {code,27158116},
          {atom,992409},
          {other_system,10531467}]},
     {alarms,[]},
          ...........
          ...........
     
    ------------------------------------------------------------------------
    可以用下面命令安装更新维护插件:
    [root@sh-op-mq01 rabbitmq]# rabbitmq-plugins enable rabbitmq_management
    [root@sh-op-mq01 rabbitmq]# systemctl restart rabbitmq-server.service
    在浏览器里输入http://localhost:15672访问RabbitMQ,默认用户名和密码都是guest,若能正常访问和登陆,即说明正常连接RabbitMQ
    

      

     

    如果使用默认的guest/guest账号密码登陆不上,解决办法如下
    [root@sh-op-mq01 rabbitmq]# vim /etc/rabbitmq/rabbitmq.config
    [{rabbit, [{loopback_users, []}]}]. 
    
    [root@sh-op-mq01 rabbitmq]# systemctl restart rabbitmq-server.service 
    
    然后使用guest/guest登陆即可!
    
    --------------------------------------------------------------------------------
    
    如果还是使用guest/guest登陆不上RabbitMQ,可以自己创建了一个账户,赋予管理员权限
    [root@sh-op-mq01 rabbitmq]# rabbitmqctl  add_user  username  password
    [root@sh-op-mq01 rabbitmq]# rabbitmqctl  set_user_tags  username  administrator 
    
    创建完后用以下命令查看创建完的账号
    [root@sh-op-mq01 rabbitmq]# rabbitmqctl list_users 
    

    RabbitMQ使用:

     1)用户管理
    用户管理包括增加用户,删除用户,查看用户列表,修改用户密码,设置用户角色,权限等等。
      
    新增一个用
    # rabbitmqctl  add_user  Username Password
      
    删除一个用户
    # rabbitmqctl  delete_user  Username
     
    修改用户的密码
    # rabbitmqctl  oldPassword  Username  newPassword
     
    查看当前用户列表
    # rabbitmqctl  list_users
    赋予角色
    # rabbitmqctl set_user_tags zx(用户名)  (超级管理员)
                                           monitoring(监控者)
                                           policymaker(策略制定者)
                                           management(普通管理者)
    2)用户角色
    按照个人理解,用户角色可分为五类,超级管理员, 监控者, 策略制定者, 普通管理者以及其他。
     
    超级管理员(administrator)
    可登陆管理控制台(启用management plugin的情况下),可查看所有的信息,并且可以对用户,策略(policy)进行操作。
     
    监控者(monitoring)
    可登陆管理控制台(启用management plugin的情况下),同时可以查看rabbitmq节点的相关信息(进程数,内存使用情况,磁盘使用情况等)
     
    策略制定者(policymaker)
    可登陆管理控制台(启用management plugin的情况下), 同时可以对policy进行管理。但无法查看节点的相关信息(上图红框标识的部分)。
     
    普通管理者(management)
    仅可登陆管理控制台(启用management plugin的情况下),无法看到节点信息,也无法对策略进行管理。
     
    其他
    无法登陆管理控制台,通常就是普通的生产者和消费者。
    

    远程连接MQ:

    3)远程连接MQ:
        创建一个用户
        rabbitmqctl add_user zx(名字) zx(密码)
    
        创建一个新的Vhost
        rabbitmqctl add_vhost test(Vhost名字)
    
        赋予权限
        rabbitmqctl set_permissions -p test(Vhost名字) zx(用户) ".*" ".*" ".*"
    
    用户权限
    
        用户权限指的是用户对exchange,queue的操作权限,包括配置权限,读写权限。配置权限会影响到exchange,queue的声明和删除。读写权限影响到从queue里取消息,向    exchange发送消息以及queue和exchange的绑定(bind)操作。
        例如: 将queue绑定到某exchange上,需要具有queue的可写权限,以及exchange的可读权限;向exchange发送消息需要具有exchange的可写权限;从queue里取数据需要具有queue的可读权限。详细请参考官方文档中"How permissions work"部分。
    相关命令为:
        (1) 设置用户权限
        rabbitmqctl set_permissions -p VHostPath User ConfP WriteP ReadP
        (2) 查看(指定hostpath)所有用户的权限信息
        rabbitmqctl list_permissions [-p VHostPath]
        (3) 查看指定用户的权限信息
        rabbitmqctl list_user_permissions User
        (4) 清除用户的权限信息
        rabbitmqctl clear_permissions [-p VHostPath] User
    
    2.删除用户
    rabbitmqctl delete_user username
    
    3.修改密码
    rabbitmqctl change_password usernamene wpassword
    
    4.列出所有用户
    rabbitmqctl list_users
    
    权限控制:
    1.创建虚拟主机
    rabbitmqctl add_vhost vhostpath
    
    2.删除虚拟主机
    rabbitmqctl delete_vhost vhostpath
    
    3.列出所有虚拟主机
    rabbitmqctl list_vhosts
    
    4.设置用户权限
    rabbitmqctl set_permissions [-pvhostpath] username regexp regexp regexp
    
    5.清除用户权限
    rabbitmqctl clear_permissions [-pvhostpath] username
    
    6.列出虚拟主机上的所有权限
    rabbitmqctl list_permissions [-pvhostpath]
    
    7.列出用户权限
    rabbitmqctl list_user_permissionsusername
        
    

      

      

  • 相关阅读:
    7.10.8107.79 小心80180048
    Sliverlight MD5
    WP 数据绑定Visibility
    WP7 剪贴板 Clipboard
    [10年之后我是谁]读书笔记
    linux面试题
    [你的灯亮着吗]读书笔记
    Linux命令行简明教程
    <Ruby入门教程>读书笔记
    [职场谎言系列]读书笔记
  • 原文地址:https://www.cnblogs.com/Mr-Axin/p/11419309.html
Copyright © 2020-2023  润新知