Step1.安装Erlang
fug@omnisky:~$ sudo apt-get update
fug@omnisky:~$ sudo apt-get install -y erlang-nox erlang-dev erlang-src
检验是否安装成功:fug@omnisky:~$ erl
输出:Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:16:16] [async-threads:10] [kernel-poll:false]
Eshell V7.3 (abort with ^G)
1>
得到以上输出代表Erlang安装成功
Step 2:安装RabbitMQ
①fug@omnisky:~$ echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list
输出为:deb http://www.rabbitmq.com/debian/ testing main
②fug@omnisky:~$ wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
输出为:
--2019-11-05 14:14:52-- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
Resolving www.rabbitmq.com (www.rabbitmq.com)... 2606:4700:10::6814:ae0, 2606:4700:10::6814:be0, 104.20.10.224, ...
Connecting to www.rabbitmq.com (www.rabbitmq.com)|2606:4700:10::6814:ae0|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: ‘STDOUT’
- [ <=> ] 3.11K 5.10KB/s in 0.6s
2019-11-05 14:14:54 (5.10 KB/s) - written to stdout [3187]
OK
③fug@omnisky:~$ sudo apt-get install rabbitmq-server
④fug@omnisky:~$ service rabbitmq-server start
⑤查看状态,验证是否安装成功:fug@omnisky:~$ service rabbitmq-server status
输出为:
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2019-11-05 14:15:44 CST; 39s ago
Main PID: 17602 (beam.smp)
Status: "Initialized"
CGroup: /system.slice/rabbitmq-server.service
├─17602 /usr/lib/erlang/erts-7.3/bin/beam.smp -W w -A 256 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/li
├─17690 /usr/lib/erlang/erts-7.3/bin/epmd -daemon
├─18062 inet_gethost 4
└─18063 inet_gethost 4
⑥手动添加配置文件,允许远程登录:sudo vim /etc/rabbitmq/rabbitmq.config
在文件中添加一行:[{rabbit,[{loopback_users,[]}]}].
⑦添加新用户并设置密码:先cd /usr/sbin,然后 sudo ./rabbitmqctl add_user 此处为用户名 此处为密码
输出:Creating user 你的用户名
⑧为用户添加管理员权限及资源访问权限:fug@omnisky:/usr/sbin$ sudo ./rabbitmqctl set_user_tags 用户名 administrator
输出:Setting tags for user 用户名 to [administrator]
fug@omnisky:/usr/sbin$ sudo ./rabbitmqctl set_permissions -p "/" 用户名 ".*" ".*" ".*"
输出:Setting permissions for user 用户名 in vhost "/"
⑨重启RabbitMQ: fug@omnisky:/usr/sbin$ service rabbitmq-server restart
⑩开启web管理插件: fug@omnisky:/usr/sbin$ sudo ./rabbitmq-plugins enable rabbitmq_management
Step3:修改节点名
fug@omnisky:/etc/rabbitmq$ sudo vim /etc/rabbitmq/rabbitmq-env.conf
文件内容: NODENAME=rabbit@节点名(如:NODENAME=rabbit@rabbitmq1)
配置节点的hosts文件
文件路径:sudo vim /etc/hosts
文件内容:ip 节点名(如:123.45.67.89 rabbitmq1)
Step4:将每一台主机都按Step2、3部署
setp5 搭建集群
①修改.erlang中的cookie值,所有节点的值都与主节点一致:
路径在$HOME中或者在/var/lib/rabbitmq中,文件名称为.erlang.cookie,他是一个隐藏文件。
在主节点cd 到/var/lib/rabbitmq 然后输入,sudo cat .erlang.cookie,会看到主节点的cookie值
②在从节点中,执行fug@omnisky:/usr/sbin$ sudo vim /var/lib/rabbitmq/.erlang.cookie
将文件中的cookie值替换为上一步得到的主节点的rookie值
然后重启RabbitMQ: fug@omnisky:/usr/sbin$ service rabbitmq-server restart
③停止从节点,fug@omnisky:/usr/sbin$ sudo ./rabbitmqctl stop_app
④将从节点加入集群 fug@omnisky:/usr/sbin$ sudo ./rabbitmqctl join_cluster 此处为要加入的集群主节点(我的是rabbit@rabbitmq1)
输出:Clustering node rabbit@rabbitmq3 with rabbit@rabbitmq1 ... 则代表添加成功了
⑤重启从节点服务,fug@omnisky:/usr/sbin$ service rabbitmq-server restart
⑥对每个要加入集群的从节点,重复上面五步。