消息中间件----rabbitMq之安装篇

消息中间件----rabbitMq之安装篇

简述

下列rabbitmq安装方法centos6和centos7都适用,只有环境配置的命令根据不同的系统使用对应的命令,安装部分是一致的。总结自己采坑的历程,记录自己遇到的几个常见问题。

适用环境

  • 系统:centos6、centos7

实验环境

  • 系统:centos6.7
  • rabbitMQ版本:3.6.11
  • erlang版本:Erlang/OTP 18

辅助文档、网址

安装工作

  • 准备工作

    根据rabbitmq官方文档中RabbitMQ Erlang版本要求 根据自己需要选定合适的rabbitmq和对应的erlang版本。

    #检测是否安装erlang
    [root@localhost ~]# rpm -qa | grep erlang
    erlang-18.1-1.el6.x86_64
    
  • 系统环境配置(非必需)

    #下列命令是centos6关闭防火墙,centos7是systemctl stop firewalld,命令有些区别
    [root@localhost ~]# chkconfig iptables off
    
    #将SELINUX=enforcing改成SELINUX=disabled
    [root@localhost ~]# vi /etc/sysconfig/selinux
    

    ps: 环境配置可以跳过,后面只需要对外开放rabbitmq的端口,能够使得别人访问到就行。

  • 依赖环境安装

    • erlang安装

      erlang安装参考我整理的另一篇博客:centos安装erlang,该文章整理了两种安装方式,其中踩了不少的坑,特意单独整理出来,以供小伙伴参考。

    • centos的epel的扩展源安装

    #安装epel
    [root@localhost ~]# yum -y install epel-release
    
    #修改epel的扩展源路径,也可以先安装socat是否会报错,我的会报错:Cannot retrieve metalink for repository: epel. Please verify its path and try again,所以先修改了扩展源路径
    [root@localhost ~]# vi /etc/yum.repos.d/epel.repo
    #将文件[epel]的baseurl的注释放开,mirrorlist注释掉,下列为修改后:
    [epel]
    name=Extra Packages for Enterprise Linux 6 - $basearch
    baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
    #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=1
    
    [epel-source]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Source
    #baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=1
    

    **ps:**如果不安装epel,在安装socat步骤会报No package socat available.错误

    • socat安装
    [root@localhost ~]# yum -y install socat
    
  • rabbitmq安装

    方式一:rpm包安装

    #下载rabbitmq的rpm包
    [root@localhost ~]# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_6_11/rabbitmq-server-3.6.11-1.el6.noarch.rpm
    
    #安装rabbitmq
    [root@localhost ~]# yum install -y rabbitmq-server-3.6.11-1.el6.noarch.rpm
    
    #验证:启动服务
    [root@localhost ~]# service rabbitmq-server start
    Starting rabbitmq-server: SUCCESS
    rabbitmq-server.
    
    #查看日志
    [root@localhost ~]# cd /var/log/rabbitmq
    [root@localhost rabbitmq]# ls
    rabbit@localhost.log  rabbit@localhost-sasl.log  startup_err  startup_log
    
    #创建配置文件,现在查看日志文件会有配置文件未找到的提示
    [root@localhost rabbitmq]# cd /etc/rabbitmq/
    [root@localhost rabbitmq]# vi rabbitmq.config
    [{rabbit, [{loopback_users, []}]}].
    
    #重启服务
    [root@localhost rabbitmq]# service rabbitmq-server stop
    [root@localhost rabbitmq]# service rabbitmq-server start
    
    #设置开机自启
    [root@localhost ~]# chkconfig rabbitmq-server on
    
    #启用监控管理,可以通过页面登陆查看rabbitmq,没有关闭防火墙的记得开放端口
    [root@localhost rabbitmq]# rabbitmq-plugins enable rabbitmq_management
    
    #如果没有关闭防火墙,则可以执行下列命令设置外部访问端口号
    [root@localhost rabbitmq]# iptables -I INPUT -p tcp --dport 15672 -j ACCEPT
    
    #添加账号,rabbitmqctl add_user username password
    [root@localhost ~]# rabbitmqctl add_user admin admin
    
    #分配用户标签,必须有这个否则无法登陆
    [root@localhost ~]# rabbitmqctl set_user_tags admin administrator
    

    ps:

    ​ 1.配置文件内容的意思:rabbitmq默认创建的用户guest,密码也是guest,这个用户默认只能是本机访问,localhost或者127.0.0.1,从外部访问需要添加上面的配置

    ​ 2.重启服务之后就可以从外部访问了,但此时再看log文件,发现内容还是原来的,还是显示没有找到配置文件,可以手动删除这个文件再重启服务,不过这不影响使用

  • 登陆,验证成果,登陆地址:ip:15672

    方式二:源码安装

    源码安装没有边做边整理,时间有限没有检查如果有错误的地方希望指正。

#下载RabbitMQ安装包
[root@localhost ~]# wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server-generic-unix-3.6.1.tar.xz

#解压安装包
[root@localhost ~]# xz -d rabbitmq-server-generic-unix-3.6.1.tar.xz
[root@localhost ~]# tar -xvf rabbitmq-server-generic-unix-3.6.1.tar

#重命名为rabbitmq
[root@localhost ~]# mv rabbitmq_server-3.6.1/ rabbitmq

#移动到安装路径,根据自己喜好来
[root@localhost ~]# mv rabbitmq /usr/local

#配置环境变量,添加一下内容
[root@localhost ~]# vi /etc/profile
export PATH=$PATH:/usr/local/rabbitmq/sbin

#使配置环境生效
[root@localhost ~]# source /etc/profile

#启动,-detached代表后台守护进程方式启动,不加-detached 为前台启动
[root@localhost ~]# cd /usr/local/rabbitmq/sbin
[root@localhost sbin]# ./rabbitmq-server -detached 

#查看服务状态
[root@localhost sbin]# ./rabbitmqctl status

#关闭服务
[root@localhost sbin]# ./rabbitmqctl stop

#创建配置文件以及开启页面监控管理,添加用户等和上面一致,这里不在重复

ps:

​ 用源码安装后,只能用sbin文件夹下的命令启停,无法用rpm安装方式的service rabbitmq-server start命令启停,貌似需要在/etc/init.d添加启动服务,但是没有成功,对于liunx知识有限,之后查询补充之后再来修改,或者有知道的可以留言,谢谢。可以参考这篇博客 的操作试试,不过我没有成功添加rabbitmq服务,有时间再试试

sbin目录下文件说明:

rabbitmq-env     // 环境配置脚本
   rabbitmq-defaults   // 默认参数设置脚本
   rabbitmqctl      // 管理工具脚本
   rabbitmq-plugins   // 插件管理工具脚本
   rabbitmq-server    // rabbitmq服务脚本

rabbitmq常用命令整理

  • 服务命令
#启动服务
[root@localhost ~]# service rabbitmq-server start

#停止服务
[root@localhost ~]# service rabbitmq-server stop

#重启服务
[root@localhost ~]# service rabbitmq-server restart

#查看服务状态
[root@localhost ~]# service rabbitmq-server status

#启用后台管理插件
[root@localhost ~]# rabbitmq-plugins enable rabbitmq_management

#查看rabbitmq进程
[root@localhost ~]# ps -ef | grep rabbitmq

#查看监听,rabbitmq默认监听端口15672/5672
[root@localhost ~]# netstat -anplt | grep LISTEN

#添加用户,rabbitmqctl add_user username password
[root@localhost ~]# rabbitmqctl add_user admin admin

#删除用户
[root@localhost ~]# rabbitmqctl delete_user admin

#修改用户密码
[root@localhost ~]# rabbitmqctl change_password admin 666666

#查看用户列表
[root@localhost ~]# rabbitmqctl list_users

#分配用户标签
[root@localhost ~]# rabbitmqctl set_user_tags admin administrator

#设置用户权限:set_permissions [-p vhost] {user} {conf} {write} {read}
#rabbitmqctl set_permissions -p 虚拟主机名称 用户名 <conf> <write> <read>
#1.这里的权限,只是针对一般用户的访问权限,注意和角色的区分。举个例子来说,非管理用户(普通用户),角色设置为none,然后在这里配置conf、write、read的权限。
2.conf、write、read采用正则表达式,这里的正则主要是针对exchange和queue。主要2种特殊的表达式:
^$:表示完全不匹配(即没有权限)
.*:表示匹配所有(即所有权限)
[root@localhost ~]# rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

#查看用户权限:rabbitmqctl list_user_permissions 用户名
[root@localhost ~]# rabbitmqctl list_user_permissions admin

#查看虚拟主机
[root@localhost ~]# rabbitmqctl list_vhosts

#添加虚拟主机
[root@localhost ~]# rabbitmqctl add_vhost coreSystem

#删除虚拟主机:rabbitmqctl delete_vhost 虚拟主机名称
[root@localhost ~]# rabbitmqctl delete_vhost coreSystem
  • 日志地址
[root@localhost ~]# cd /var/log/rabbitmq
  • 角色说明

    • none----普通用户

      没有控制台操作权限

    • management----普通管理员

      可以查看当前用户的queues, exchanges和bindings。
      可以查看和关闭当前用户的channels和connections。
      可以查看当前用户的virtual hosts的统计信息。

    • policymaker----策略管理员

      具有management权限及查看、创建和删除当前用户的policies和parameters。

    • monitoring----监控管理员

      具有management权限
      查看所有virtual hosts及全局的统计信息
      查看所有用户的connections和channels
      查看所有节点数据,如clustering和memory使用情况

    • administrator----超级管理员

      具有policymaker、monitoring权限
      查看、创建、删除所有virtual hosts
      查看、创建、删除所有users
      查看、创建、删除所有permissions
      可以关闭所有用户的connections

rabbitmq配置文件

一般情况下,RabbitMQ的默认配置就足够了。如果希望特殊设置的话,有两个途径:

  • 环境变量的配置文件:rabbitmq-env.conf

    • 在/etc/rabbitmq目录下,这个文件的位置是确定和不能改变的,并且目录需要自己创建

    • 文件的内容包括了RabbitMQ的一些环境变量,

      常用的有:

      ​ #RABBITMQ_NODE_PORT= //端口号

      ​ #HOSTNAME=

      ​ RABBITMQ_NODENAME=mq

      ​ RABBITMQ_CONFIG_FILE= //配置文件的路径

      ​ RABBITMQ_MNESIA_BASE=/rabbitmq/data //需要使用的MNESIA数据库的路径

      ​ RABBITMQ_LOG_BASE=/rabbitmq/log //log的路径

      ​ RABBITMQ_PLUGINS_DIR=/rabbitmq/plugins //插件的路径

      ​ 具体的列表见:http://www.rabbitmq.com/configure.html#define-environment-variables

  • 是配置信息的配置文件:rabbitmq.config

**ps:**这两个文件默认是没有的,如果需要必须自己创建。

这。它。

参考文档:

http://www.mamicode.com/info-detail-1994926.html

https://www.cnblogs.com/uptothesky/p/6094357.html

https://www.cnblogs.com/skychenjiajun/p/8930147.html

https://blog.csdn.net/qq_40809549/article/details/80227987

https://www.cnblogs.com/hyl8218/p/5573301.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值