安装rabbitMq
erlang mq 版本对应关系
https://www.rabbitmq.com/which-erlang.html
如果erlang 是源码安装,则对应的rabbitmq 也需要用源码安装的方式进行
如果erlang 是采用yum方式安装,则rabbitmq 可以采用rpm的形式进行安装,如果erlang是源码方式安装,则rabbitmq 采用rpm方式安装会一直报错,显示找不到erlang
rabbitmq 3.8.8 的版本貌似有问题,mq可以正常启动,但是stomp不能启用
如果安装mq 建议采用源码安装的方式进行
安装依赖环境
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC unixODBC-devel httpd python-simplejson
源码安装RabbitMq
源码安装erlang
下载erlang
erlang 全版本下载地址:
下载以下版本
http://erlang.org/download/otp_src_21.3.tar.gz
安装erlang
tar -zxvf otp_src_21.3.tar.gz # 解压
./configure --prefix=/home/local/erlang --with-ssl --enable-threads --enable-smp-support --enable-kernel-poll --enable-hipe --without-javac
make && make install
配置环境变量
配置Erlang的环境变量
vim /etc/profile
export PATH=$PATH:/home/local/erlang/bin
source /etc/profile
验证
-
测试Erlang安装是否成功,输入erl,查看版本信息
-
测试输入hello.,在控制台上看到输入hello,之后退出输入halt().,Erlang环境安装完
源码安装RabbitMq
下载
https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.7.21
下载rabbitmq-server-generic-unix-3.7.21.tar.xz 版本
解压
tar -xvf rabbitmq-server-generic-unix-3.7.21.tar.xz
#解压后目录
/home/local/rabbitmq/rabbitmq_server-3.7.21
配置
配置环境变了
vim /etc/profile
#添加以下内容:
export PATH=$PATH:/home/local/erlang/bin
export PATH=$PATH:/home/local/rabbitmq/rabbitmq_server-3.7.21/sbin
启动
rabbitmq-server #此方式启动后,ctrl+c后服务依然在
#以后台形式启动
rabbitmq-server -detached
关闭
rabbitmqctl stop_app
或者
rabbitmqctl stop
重置
rm -rf /home/local/rabbitmq/rabbitmq_server-3.7.21/var/lib/rabbitmq/mnesia/
这个目录,为rabbitmq数据库,有时异常情况出现时,可删除该目录,重新对rabbitmq进行设置即可
查看插件
rabbitmq-plugins list
安装插件
rabbitmq-plugins enable rabbitmq_management rabbitmq_stomp rabbitmq_web_stomp
卸载插件
rabbitmq-plugins disable rabbitmq_management rabbitmq_stomp rabbitmq_web_stomp
加入启动服务
start.sh
#!/bin/bash
export PATH=$PATH:/home/local/erlang/bin
export HOME=/home/local/rabbitmq/rabbitmq_server-3.7.21/
/home/local/rabbitmq/rabbitmq_server-3.7.21/sbin/./rabbitmq-server -detached
stop.sh
#!/bin/bash
export PATH=$PATH:/home/local/erlang/bin
export HOME=/home/local/rabbitmq/rabbitmq_server-3.7.21/
/home/local/rabbitmq/rabbitmq_server-3.7.21/sbin/./rabbitmqctl stop
打开目录 cd /usr/lib/systemd/system/,在此目录下添加
rabbitmq.service
[Unit]
Description=rabbitmq-server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/home/local/rabbitmq/rabbitmq_server-3.7.21/start.sh
ExecStop=/home/local/rabbitmq/rabbitmq_server-3.7.21/stop.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
创建软连接
ln -s `pwd`/rabbitmq.service /etc/systemd/system/multi-user.target.wants
重新加载服务
systemctl daemon-reload
开机自启动
systemctl enable rabbitmq.service
加入系统服务之后
systemctl start rabbitmq # 开启
systemctl stop rabbitmq # 关闭
systemctl status rabbitmq # 查看状态
yum安装
yum安装erlang
编辑文件
vi /etc/yum.repos.d/rabbitmq_erlang.repo
文件内容修改如下:
# In /etc/yum.repos.d/rabbitmq_erlang.repo
[rabbitmq_erlang]
name=rabbitmq_erlang
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[rabbitmq_erlang-source]
name=rabbitmq_erlang-source
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
安装
yum install erlang
此方式安装rabbitmq 成功
rpm安装rabbitMq
安装socat
sudo yum install -y socat
下载 RabbitMQ
https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.8.8
安装RabbitMQ
sudo rpm -Uvh rabbitmq-server-3.8.8-1.el6.noarch.rpm
启动RabbitMQ服务
\#启动服务
sudo systemctl start rabbitmq-server
\#查看状态
sudo systemctl status rabbitmq-server
\#设置为开机启动
sudo systemctl enable rabbitmq-server
RabbitMQ配置
添加用户并授权
\#添加用户
sudo rabbitmqctl add_user admin pwd
\#设置用户角色
sudo rabbitmqctl set_user_tags admin administrator
\#tag(administrator,monitoring,policymaker,management)
\#设置用户权限(接受来自所有Host的所有操作)
sudo rabbitmqctl set_permissions -p "/" admin '.*' '.*' '.*'
\#查看用户权限
sudo rabbitmqctl list_user_permissions admin
配置用户远程访问
\#修改配置文件
sudo vi /etc/rabbitmq/rabbitmq.config
\#保存以下内容
[
{rabbit, [{tcp_listeners, [5672]}, {loopback_users, ["admin"]}]}
].
重启服务并开放端口
- 重启服务
sudo systemctl restart rabbitmq-server
- 开放端口
\#开放端口
sudo firewall-cmd --add-port=5672/tcp --permanent
\#重新加载防火墙配置
sudo firewall-cmd --reload
四、备注
RabbitMQ常用命令
\# 添加用户
sudo rabbitmqctl add_user <username> <password>
\# 删除用户
sudo rabbitmqctl delete_user <username>
\# 修改用户密码
sudo rabbitmqctl change_password <username> <newpassword>
\# 清除用户密码(该用户将不能使用密码登陆,但是可以通过SASL登陆如果配置了SASL认证)
sudo rabbitmqctl clear_password <username>
\# 设置用户tags(相当于角色,包含administrator,monitoring,policymaker,management)
sudo rabbitmqctl set_user_tags <username> <tag>
\# 列出所有用户
sudo rabbitmqctl list_users
\# 创建一个vhosts
sudo rabbitmqctl add_vhost <vhostpath>
\# 删除一个vhosts
sudo rabbitmqctl delete_vhost <vhostpath>
\# 列出vhosts
sudo rabbitmqctl list_vhosts [<vhostinfoitem> ...]
\# 针对一个vhosts给用户赋予相关权限;
sudo rabbitmqctl set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
\# 清除一个用户对vhosts的权限;
sudo rabbitmqctl clear_permissions [-p <vhostpath>] <username>
\# 列出哪些用户可以访问该vhosts;
sudo rabbitmqctl list_permissions [-p <vhostpath>]
\# 列出用户访问权限;
sudo rabbitmqctl list_user_permissions <username>
安装插件
rabbitmq-plugins enable rabbitmq_management rabbitmq_stomp rabbitmq_web_stomp
卸载插件
rabbitmq-plugins disable rabbitmq_management rabbitmq_stomp rabbitmq_web_stomp
查看插件安装情况
rabbitmq-plugins list
卸载RabbitMq
rpm -qa |grep rabbit
rpm -e rabbitmq-server-3.8.8-1.el6.noarch
本文参考
https://www.rabbitmq.com/download.html
https://github.com/judasn/Linux-Tutorial/blob/master/RabbitMQ-Install-And-Settings.md
http://blog.csdn.net/zyz511919766/article/details/42292655