主要安装步骤如下:
一、安装Erlang
**注意:**安装版本要求,可参考RabbitMQ Erlang Version Requirements
二、安装rabbitmq
step1. Add apt repositories
echo "deb https://dl.bintray.com/rabbitmq/debian xenial main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list
step2. Next add our public key to your trusted key list using apt-key(8):
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
step3. Run the following command to update the package list:
sudo apt-get update
step4. Install rabbitmq-server package:
sudo apt-get install rabbitmq-server
**注意:**安装的Erlang版本,rabbitmq版本,操作系统要相一致。可参考Installing on Debian / Ubuntu
三、启动rabbitmq
启动rabbitmq:
service rabbitmq-server start
四、查看rabbitmq状态
可以运行命令查看rabbitmq.
sudo service rabbitmq-server status
五、开启web管理接口
rabbitmq既可以命令行操作,也可以用rabbitmq自带的web管理界面,只需要启动插件便可以使用。
sudo rabbitmq-plugins enable rabbitmq_management
然后通过浏览器访问,如果是本机则可以输入http://127.0.0.1:15672打开登录界面,输入用户名和密码访问web管理界面了。默认用户名guest密码guest。
更多可参考Management Plugin
后记
rabbitmq配置
一般使用默认配置就好了,具体配置可参考RabbitMQ Configuration。
rabbitmq端口
以下为rabbitmq的默认端口,如果这些端口被其他程序占用,rabbitmq就会出错。
- 4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
- 5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
- 25672: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). See networking guide for details.
- 35672-35682: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as Erlang dist port + 10000 through dist port + 10010). See networking guide for details.
- 15672: HTTP API clients and rabbitmqadmin (only if the management plugin is enabled)
- 61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled)
- 1883, 8883: (MQTT clients without and with TLS, if the MQTT plugin is enabled
- 15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
- 15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
运行sudo netstat -tlnpe
命令可以看到rabbitmq默认的监听端口。
因为上面运行了sudo rabbitmq-plugins enable rabbitmq_management
,所以这里可以看到15672这个端口。
如果相冲突的话,可以参考Networking and RabbitMQ更改rabbitmq配置或者去down掉占用端口的那个应用程序或进程吧。
rabbitmq常用命令
sudo chkconfig rabbitmq-server on #添加开机启动(chkconfig一般只有redhat系统有)RabbitMQ服务
sudo service rabbitmq-server start # 启动服务
sudo service rabbitmq-server status # 查看服务状态
sudo service rabbitmq-server stop # 停止服务
sudo rabbitmqctl stop # 停止服务
sudo rabbitmqctl status # 查看服务状态
sudo rabbitmqctl list_users # 查看当前所有用户
sudo rabbitmqctl list_user_permissions guest # 查看默认guest用户的权限
sudo rabbitmqctl delete_user guest# 删掉默认用户(由于RabbitMQ默认的账号用户名和密码都是guest。为了安全起见, 可以删掉默认用户)
sudo rabbitmqctl add_user username password # 添加新用户
sudo rabbitmqctl set_user_tags username administrator# 设置用户tag
sudo rabbitmqctl set_permissions -p / username ".*" ".*" ".*" # 赋予用户默认vhost的全部操作权限
sudo rabbitmqctl list_user_permissions username # 查看用户的权限
更多命令参考rabbitmqctl。想学习更多请参考官网。
下一篇:RabbitMQ基础