【RabbitMQ】安裝

煎雞蛋湯發表於2018-07-01

RabbitMQ可以安裝在很多作業系統上,我的系統:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@localhost ~]# 

安裝erlang

RabbitMQ依賴於erlang,所以在安裝RabbitMQ前,我們先安裝erlang,yum源參考:erlang yum(我使用Erlang 20.x on CentOS 7)

Erlang 20.x on CentOS 7:

# In /etc/yum.repos.d/rabbitmq-erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
[root@localhost ~]# vi /etc/yum.repos.d/rabbitmq-erlang.repo # 新增erlang repos,填入以上內容
[root@localhost ~]# yum update
[root@localhost ~]# yum install -y erlang

等待安裝完成即可

安裝其他依賴

除了erlang外,rabbitmq還依賴於“socat”,使用以下命令即可安裝完成

[root@localhost ~]# yum install -y socat

安裝rabbitmq

rabbitmq-server-3.7.6-1.el7.noarch.rpm下載rabbitmq的rpm包

[root@localhost ~]# wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.6/rabbitmq-server-3.7.6-1.el7.noarch.rpm

[root@localhost ~]# rpm -ivh rabbitmq-server-3.7.6-1.el7.noarch.rpm

rabbitmq安裝完成

如果你是其他作業系統,請參考官網:Downloading and Installing RabbitMQ

啟動rabbitmq

[root@localhost ~]# systemctl start rabbitmq-server.service

[root@localhost ~]# systemctl status rabbitmq-server.service 
● rabbitmq-server.service - RabbitMQ broker
   Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-06-30 20:22:03 PDT; 6min ago
  Process: 85394 ExecStop=/usr/sbin/rabbitmqctl shutdown (code=exited, status=0/SUCCESS)
 Main PID: 85518 (beam.smp)
   Status: "Initialized"
    Tasks: 83
   CGroup: /system.slice/rabbitmq-server.service
           ├─85518 /usr/lib64/erlang/erts-9.3.3/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db...
           ├─85859 erl_child_setup 1024
           ├─85873 inet_gethost 4
           └─85874 inet_gethost 4

Jun 30 20:22:01 localhost.localdomain rabbitmq-server[85518]: ##  ##
Jun 30 20:22:01 localhost.localdomain rabbitmq-server[85518]: ##  ##      RabbitMQ 3.7.6. Copyright (C) 2007-2018 Pivotal Software, Inc.
Jun 30 20:22:01 localhost.localdomain rabbitmq-server[85518]: ##########  Licensed under the MPL.  See http://www.rabbitmq.com/
Jun 30 20:22:01 localhost.localdomain rabbitmq-server[85518]: ######  ##
Jun 30 20:22:01 localhost.localdomain rabbitmq-server[85518]: ##########  Logs: /var/log/rabbitmq/rabbit@localhost.log
Jun 30 20:22:01 localhost.localdomain rabbitmq-server[85518]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
Jun 30 20:22:01 localhost.localdomain rabbitmq-server[85518]: Starting broker...
Jun 30 20:22:03 localhost.localdomain rabbitmq-server[85518]: systemd unit for activation check: "rabbitmq-server.service"
Jun 30 20:22:03 localhost.localdomain systemd[1]: Started RabbitMQ broker.
Jun 30 20:22:04 localhost.localdomain rabbitmq-server[85518]: completed with 0 plugins.
[root@localhost ~]#

啟動成功之後,我們為了後續測試方便,先建立一個使用者

[root@localhost ~]# rabbitmqctl add_user <username> <password>
[root@localhost ~]# rabbitmqctl set_permissions -p / <username> ".*" ".*" ".*"

說明:

  • rabbitmq預設建立了guest使用者,但只允許通過localhost訪問
  • 每個使用者訪問rabbitmq都需要使用vhost(許可權控制)
  • rabbitmq預設建立了/ vhost,需要給新建的使用者設定許可權,不然會報錯:no access to this vhost

防火牆

rabbitmq預設使用5672埠,如果rabbitmq不是安裝在本機,記得開放tcp/5672,centos 7開放tcp/5672的命令:

[root@localhost anys]# firewall-cmd --zone=public --add-port=5672/tcp --permanent
[root@localhost anys]# firewall-cmd --reload

相關文章