04-基于CentOS7安装RabbitMQ3.10.7
RabbitMQ安装与入门
安装与启动
我实在是找不到这么老的版本了, 直接用最新版本的, 按照道理来说, 新版本是兼容老版本的
官网地址
https://www.rabbitmq.com/
Erlang安装
下载
https://github.com/erlang/otp/releases/download/OTP-25.1/otp_src_25.1.tar.gz
上传到linux
# 解压 tar -zxvf otp_src_25.1.tar.gz # 安装依赖 yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ kernel-devel m4 ncurses-devel tk tc tz # 进入文件夹 cd otp_src_25.1/ # 创建安装目录 mkdir /usr/local/erlang # 在执行这个的时候 最后出现了很多错误, 不过都不用管 ./configure --prefix=/usr/local/erlang make && make install vi /etc/profile
修改配置
# Erlang environment ERLANG_HOME=/usr/local/erlang/ export PATH=$PATH:$ERLANG_HOME/bin export ERLANG_HOME
重新加载profile
source /etc/profile
可以输入erl命令来验证Erlang是否安装成功,如果出现类似以下的提示即表示安装成功:
erl
安装RabbitMQ
下载(github网不太好)
https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.10.7
上传到Linux
xz -d rabbitmq-server-generic-unix-3.10.7.tar.xz tar xvf rabbitmq-server-generic-unix-3.10.7.tar mv rabbitmq_server-3.10.7/ /usr/local/rabbitmq cd /usr/local/rabbitmq/ vi /etc/profile
修改配置文件
# RabbitMQ environment export PATH=$PATH:/usr/local/rabbitmq/sbin/ export RABBITMQ_HOME=/usr/local/rabbitmq/
重建加载配置
source /etc/profile
修改hostname配置
vi /etc/hostname
# 内容
localhost.localdomain
centos142
修改host映射
vi /etc/hosts # 内容 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.247.142 centos142
启动RabbitMQ
在修改完/etc/profile配置文件之后,可以任意打开Shell窗口,输入如下命令以运行RabbitMQ服务:
rabbitmq-server -detached
rabbitmq-server命令后面添加一个"-detached"参数是为了让RabbitMQ服务以守护进程的方式在后台运行,这样就不会因为当前Shell窗口的关闭而影响服务。
# 查看状态
rabbitmqctl status
如果RabbitMQ正常启动,会输出如下信息。当然也可以通过rabbitmqctl cluster_status命令来查看集群信息,目前只有一个RabbitMQ服务节点,可以看做单节点的集群:
Status of node rabbit@localhost ... Runtime OS PID: 42770 OS: Linux Uptime (seconds): 4 Is under maintenance?: false RabbitMQ version: 3.10.7 Node name: rabbit@localhost Erlang configuration: Erlang/OTP 25 [erts-13.1] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] Crypto library: OpenSSL 1.0.2k-fips 26 Jan 2017 Erlang processes: 266 used, 1048576 limit Scheduler run queue: 1 Cluster heartbeat timeout (net_ticktime): 60 Plugins Enabled plugin file: /usr/local/rabbitmq/etc/rabbitmq/enabled_plugins Enabled plugins: Data directory Node data directory: /usr/local/rabbitmq/var/lib/rabbitmq/mnesia/rabbit@localhost Raft data directory: /usr/local/rabbitmq/var/lib/rabbitmq/mnesia/rabbit@localhost/quorum/rabbit@localhost Config files Log file(s) * /usr/local/rabbitmq/var/log/rabbitmq/rabbit@localhost.log * /usr/local/rabbitmq/var/log/rabbitmq/rabbit@localhost_upgrade.log * <stdout> Alarms (none) Memory Total memory used: 0.0807 gb Calculation strategy: rss Memory high watermark setting: 0.4 of available memory, computed to: 0.7632 gb code: 0.0294 gb (36.47 %) other_proc: 0.0181 gb (22.46 %) other_system: 0.012 gb (14.82 %) allocated_unused: 0.0108 gb (13.37 %) reserved_unallocated: 0.0058 gb (7.14 %) other_ets: 0.0028 gb (3.53 %) atom: 0.0013 gb (1.65 %) binary: 0.0002 gb (0.27 %) mnesia: 0.0001 gb (0.11 %) metrics: 0.0001 gb (0.07 %) plugins: 0.0 gb (0.05 %) msg_index: 0.0 gb (0.04 %) quorum_ets: 0.0 gb (0.01 %) quorum_queue_dlx_procs: 0.0 gb (0.0 %) stream_queue_procs: 0.0 gb (0.0 %) stream_queue_replica_reader_procs: 0.0 gb (0.0 %) connection_channels: 0.0 gb (0.0 %) connection_other: 0.0 gb (0.0 %) connection_readers: 0.0 gb (0.0 %) connection_writers: 0.0 gb (0.0 %) mgmt_db: 0.0 gb (0.0 %) queue_procs: 0.0 gb (0.0 %) queue_slave_procs: 0.0 gb (0.0 %) quorum_queue_procs: 0.0 gb (0.0 %) stream_queue_coordinator_procs: 0.0 gb (0.0 %) File Descriptors Total: 2, limit: 65438 Sockets: 0, limit: 58892 Free Disk Space Low free disk space watermark: 0.05 gb Free disk space: 2.3965 gb Totals Connection count: 0 Queue count: 0 Virtual host count: 1 Listeners Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication Interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
默认情况下,访问RabbitMQ服务的用户名和密码都是"guest",这个账户有限制,默认只能通过本地网络(如localhost)访问,远程网络访问受限,所以在实现生产和消费消息之前,需要另外添加一个用户,并设置相应的访问权限。
添加新用户,用户名为"root",密码为"123456":
rabbitmqctl add_user root
为root用户设置所有权限:
rabbitmqctl set_permissions -p / root ".*" ".*" ".*"
设置root用户为管理员角色:
rabbitmqctl set_user_tags root administrator
安装rabbitmq_management插件:
cd /usr/local/rabbitmq/
rabbitmq-plugins enable rabbitmq_management
访问控制台
通过浏览器访问RabbitMQ控制台:
http://192.168.247.142:15672
访问之前记得关闭防火墙
root 123456
安装成功