1.下载
RabbitMQ服务端代码是使用并发式语言Erlang编写的,安装Rabbit MQ的前提是安装Erlang
注意事项
erlang的版本会影响到rabbitmq的安装,两者有个版本对照。查看对照的地址:http://www.rabbitmq.com/which-erlang.html
https://www.rabbitmq.com/documentation.html
https://packagecloud.io/rabbitmq/erlang
2.准备工作
关闭防火墙
firewall-cmd --permanent --add-port=5672/tcp
firewall-cmd --reload
setsebool -P nis_enabled 1 (关闭selinux)
firewall-cmd --permanent --add-port=5672/tcp
firewall-cmd --reload
setsebool -P nis_enabled 1 (关闭selinux)
安装依赖包
yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ kernel-devel m4 ncurses-devel tk tc xz
yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ kernel-devel m4 ncurses-devel tk tc xz
3.开启后台管理
rabbitmq-plugins enable rabbitmq_management
4.开启远程访问
#添加用户
#rabbitmqctl add_user 账号 密码
#rabbitmqctl add_user admin admin
#分配用户标签(admin为要赋予administrator权限的刚创建的那个账号的名字)
#rabbitmqctl set_user_tags admin administrator
#设置权限<即开启远程访问>(如果需要远程连接,例如java项目中需要调用mq,则一定要配置,否则无法连接到mq,admin为要赋予远程访问权限的刚创建的那个账号的名字,必须运行着rabbitmq此命令才能执行)
#rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
#添加用户
#rabbitmqctl add_user 账号 密码
#rabbitmqctl add_user admin admin
#分配用户标签(admin为要赋予administrator权限的刚创建的那个账号的名字)
#rabbitmqctl set_user_tags admin administrator
#设置权限<即开启远程访问>(如果需要远程连接,例如java项目中需要调用mq,则一定要配置,否则无法连接到mq,admin为要赋予远程访问权限的刚创建的那个账号的名字,必须运行着rabbitmq此命令才能执行)
#rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
5.源码安装
一、安装erlang
1.利用yum安装erlang编译所依赖的环境
yum -y install make gcc gcc-c++ kernel-devel m4ncurses-devel openssl-devel unixODBC-devel
2.下载erlang 进行源码安装
erlang官网地址: http://www.erlang.org/downloads
3.解压并进行编译安装
#解压
tar -xvf otp_src_21.0.tar.gz
#进入目录
cd cd otp_src_21.0
#编译
./configure --prefix=/usr/local/erlang --without-javac
#安装
make && make install
#解压
tar -xvf otp_src_21.0.tar.gz
#进入目录
cd cd otp_src_21.0
#编译
./configure --prefix=/usr/local/erlang --without-javac
#安装
make && make install
4.安装rabbitmq
下载rabbitmq
rabbitmq官网下载地址 : http://www.rabbitmq.com/download.html
rabbitmq源码下载地址: http://www.rabbitmq.com/install-generic-unix.html
xz -d rabbitmq-server-generic-unix-3.7.7.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.7.7.tar
mv rabbitmq_server-3.7.7/ /usr/local/rabbitmq
#添加系统变量
#打开环境变量文件
vim /etc/profile
#添加erlang rabbitmq 到环境变量
export PATH=$PATH:/usr/local/erlang/bin
export PATH=$PATH:/usr/local/rabbitmq/sbin
#重新加载环境变量
source /etc/profile
#启动web插件 启动rabbitmq
#启动web插件 便于访问
rabbitmq-plugins enable rabbitmq_management
#启动rabbitmq服务
rabbitmq-server
添加远端登录账户
#添加用户 admin 密码为 123456
rabbitmqctl add_user admin 123456
#将admin 设置为管理员权限
rabbitmqctl set_user_tags admin administrator
#将admin 设置为远端登录
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
xz -d rabbitmq-server-generic-unix-3.7.7.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.7.7.tar
mv rabbitmq_server-3.7.7/ /usr/local/rabbitmq
#添加系统变量
#打开环境变量文件
vim /etc/profile
#添加erlang rabbitmq 到环境变量
export PATH=$PATH:/usr/local/erlang/bin
export PATH=$PATH:/usr/local/rabbitmq/sbin
#重新加载环境变量
source /etc/profile
#启动web插件 启动rabbitmq
#启动web插件 便于访问
rabbitmq-plugins enable rabbitmq_management
#启动rabbitmq服务
rabbitmq-server
添加远端登录账户
#添加用户 admin 密码为 123456
rabbitmqctl add_user admin 123456
#将admin 设置为管理员权限
rabbitmqctl set_user_tags admin administrator
#将admin 设置为远端登录
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
6.yum 安装
1.1 官网地址
https://www.rabbitmq.com/download.html
- RabbitMQ(3.8.8): https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.8.8
- erlang(22.3):https://www.erlang-solutions.com/downloads/
1.2依赖安装
安装文件(分别按照以下顺序安装)
# yum install epel-release
# yum install unixODBC unixODBC-devel wxBase wxGTK SDL wxGTK-gl socat -y
# 安装erlang
rpm -ivh esl-erlang_22.3.1-1_centos_7_amd64.rpm
#安装RabbitMQ
rpm -ivh rabbitmq-server-3.8.8-1.el7.noarch.rpm
# yum install epel-release
# yum install unixODBC unixODBC-devel wxBase wxGTK SDL wxGTK-gl socat -y
# 安装erlang
rpm -ivh esl-erlang_22.3.1-1_centos_7_amd64.rpm
#安装RabbitMQ
rpm -ivh rabbitmq-server-3.8.8-1.el7.noarch.rpm
1.3yum安装位置
bin | |
---|---|
/usr/lib/rabbitmq/lib/rabbitmq_server-3.8.8/sbin | 可执行命令 |
/usr/lib/rabbitmq/lib/rabbitmq_server-3.8.8/sbin/rabbitmq-defaults | 查看默认配置文件位置 |
[root@dj_a_sms_otc_index_opera01 sbin]# ll
total 40
-rwxr-xr-x 1 root root 1245 Sep 3 2020 rabbitmqctl
-rwxr-xr-x 1 root root 983 Sep 3 2020 rabbitmq-defaults
-rwxr-xr-x 1 root root 1254 Sep 3 2020 rabbitmq-diagnostics
-rwxr-xr-x 1 root root 6948 Sep 3 2020 rabbitmq-env
-rwxr-xr-x 1 root root 1250 Sep 3 2020 rabbitmq-plugins
-rwxr-xr-x 1 root root 1249 Sep 3 2020 rabbitmq-queues
-rwxr-xr-x 1 root root 7042 Sep 3 2020 rabbitmq-server
-rwxr-xr-x 1 root root 1250 Sep 3 2020 rabbitmq-upgrade
[root@dj_a_sms_otc_index_opera01 sbin]# ll
total 40
-rwxr-xr-x 1 root root 1245 Sep 3 2020 rabbitmqctl
-rwxr-xr-x 1 root root 983 Sep 3 2020 rabbitmq-defaults
-rwxr-xr-x 1 root root 1254 Sep 3 2020 rabbitmq-diagnostics
-rwxr-xr-x 1 root root 6948 Sep 3 2020 rabbitmq-env
-rwxr-xr-x 1 root root 1250 Sep 3 2020 rabbitmq-plugins
-rwxr-xr-x 1 root root 1249 Sep 3 2020 rabbitmq-queues
-rwxr-xr-x 1 root root 7042 Sep 3 2020 rabbitmq-server
-rwxr-xr-x 1 root root 1250 Sep 3 2020 rabbitmq-upgrade
1.4修改配置
官方配置,https://www.rabbitmq.com/configure.html#config-file
默认没有配置文件
有三个配置文件,分别为
主配置文件(rabbitmq.conf),
Erlang术语格式配置文件(advanced.config)、
环境变量配置文件(rabbitmq-env.conf)
https://github.com/rabbitmq/rabbitmq-server/blob/master/deps/rabbit/docs/rabbitmq.conf.example
vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.8/sbin/rabbitmq-defaults
# Specifies new style config file location
CONFIG_FILE=/etc/rabbitmq/rabbitmq.conf
vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.8/sbin/rabbitmq-defaults
# Specifies new style config file location
CONFIG_FILE=/etc/rabbitmq/rabbitmq.conf
该文件默认也不存在/etc/rabbitmq/目录下手动创建
- 新版格式
# A new style format snippet. This format is used by rabbitmq.conf files.
ssl_options.cacertfile = /path/to/ca_certificate.pem
ssl_options.certfile = /path/to/server_certificate.pem
ssl_options.keyfile = /path/to/server_key.pem
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = true
# A new style format snippet. This format is used by rabbitmq.conf files.
ssl_options.cacertfile = /path/to/ca_certificate.pem
ssl_options.certfile = /path/to/server_certificate.pem
ssl_options.keyfile = /path/to/server_key.pem
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = true
- 旧版本格式
%% A classic format snippet, now used by advanced.config files.
[
{rabbit, [{ssl_options, [{cacertfile, "/path/to/ca_certificate.pem"},
{certfile, "/path/to/server_certificate.pem"},
{keyfile, "/path/to/server_key.pem"},
{verify, verify_peer},
{fail_if_no_peer_cert, true}]}]}
].
%% A classic format snippet, now used by advanced.config files.
[
{rabbit, [{ssl_options, [{cacertfile, "/path/to/ca_certificate.pem"},
{certfile, "/path/to/server_certificate.pem"},
{keyfile, "/path/to/server_key.pem"},
{verify, verify_peer},
{fail_if_no_peer_cert, true}]}]}
].
1.5添加用户
#创建账号
rabbitmqctl add_user admin 123
#设置用户角色
rabbitmqctl set_user_tags admin administrator
#设置用户权限
set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
#户 user_admin 具有/vhost1 这个 virtual host 中所有资源的配置、写、读权限
#当前用户和角色
rabbitmqctl list_users
#创建账号
rabbitmqctl add_user admin 123
#设置用户角色
rabbitmqctl set_user_tags admin administrator
#设置用户权限
set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
#户 user_admin 具有/vhost1 这个 virtual host 中所有资源的配置、写、读权限
#当前用户和角色
rabbitmqctl list_users
7.容器安装
docker run -di --net=host --restart=always -v /data/data_rabbitmq:/var/lib/rabbitmq --name mq -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=ad45good6ad -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 1883:1883 rabbitmq:management
docker run -di --net=host --restart=always -v /data/data_rabbitmq:/var/lib/rabbitmq --name mq -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=ad45good6ad -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 1883:1883 rabbitmq:management
8.命令
启动
#启动
[root@master software]# service rabbitmq-server start
#查看状态
[root@master software]# service rabbitmq-server status
#停止
[root@master software]# service rabbitmq-server stop
#开机自启动
[root@master software]# chkconfig rabbitmq-server on
#启动
[root@master software]# service rabbitmq-server start
#查看状态
[root@master software]# service rabbitmq-server status
#停止
[root@master software]# service rabbitmq-server stop
#开机自启动
[root@master software]# chkconfig rabbitmq-server on
重置
#关闭应用的命令为
rabbitmqctl stop_app
#清除的命令为
rabbitmqctl reset
#重新启动命令为
rabbitmqctl start_app
#关闭应用的命令为
rabbitmqctl stop_app
#清除的命令为
rabbitmqctl reset
#重新启动命令为
rabbitmqctl start_app