您的位置:首页 > 其它

RabbitMQ 系列之集群搭建

2017-07-13 00:00 246 查看
摘要: RabbitMQ集群

###安装webadmin
默认的guest只允许localhost访问需要添加一个可以远程访问的用户需要授予管理员权限

[root@izwz96fsxeqvr01uj5tfpnz ~]# rabbitmqctl add_user 3doyen 189*****
Creating user "3doyen"
[root@izwz96fsxeqvr01uj5tfpnz ~]# rabbitmqctl set_user_tags 3doyen administrator
Setting tags for user "3doyen" to [administrator]
[root@izwz96fsxeqvr01uj5tfpnz ~]# rabbitmqctl set_permissions -p / 3doyen ".*" ".*" ".*"
Setting permissions for user "3doyen" in vhost "/"
[root@izwz96fsxeqvr01uj5tfpnz ~]#

输入IP地址:15672
如果顺利就能看到图片,有故障看下根据上一章内容启动下rabbitmq服务或者防火墙的问题。



###两个主机互相ssh免登陆
在每台主机上运行,以root为例。

[root@izwz96fsxeqvr01uj5tfpnz ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? t^Ht^H^H^C
[root@izwz96fsxeqvr01uj5tfpnz ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
fa:33:21:4b:2d:c0:a5:95:8b:55:d9:72:68:bb:9c:42 root@izwz96fsxeqvr01uj5tfpnz
The key's randomart image is:
+--[ RSA 2048]----+
|       o.+       |
|      = = o      |
|   . * o +       |
|    = E .        |
|     o oSo       |
|      =.*        |
|     ..= .       |
|      ..o        |
|        .o       |
+-----------------+

把key传到需要登录的主机,记得要输入密码,-p表示端口号,两台机器上分别执行一遍。执行完测试登录是否成功。
ssh -p '端口号' 'root@ip地址'

[root@izwz96fsxeqvr01uj5tfpnz ~]# ssh-copy-id -i  ~/.ssh/id_rsa.pub -p 361 root@39.*.*.53
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@39.*.*.53's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '361' 'root@39.*.*.53'"
and check to make sure that only the key(s) you wanted were added.

[root@izwz96fsxeqvr01uj5tfpnz ~]# ssh -p '361' 'root@39.*.*.53'
Last login: Thu Jul 13 07:41:48 2017 from 39.*.*.53

Welcome to Alibaba Cloud Elastic Compute Service !

[root@izwz94pap18irvvpr4aphrz ~]# exit
logout
Connection to 39.*.*.53 closed.
[root@izwz96fsxeqvr01uj5tfpnz ~]#

###设置 Erlang Cookie
/var/lib/rabbitmq/.erlang.cookie

从主节点复制内容到其他节点。



###组成rabbitmq集群
节点1处理

[root@izwz96fsxeqvr01uj5tfpnz ~]# rabbitmqctl stop
Stopping and halting node rabbit@izwz96fsxeqvr01uj5tfpnz
[root@izwz96fsxeqvr01uj5tfpnz ~]# rabbitmq-server -detached
Warning: PID file not written; -detached was passed.

节点2处理

[root@rabbit2 ~]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbit2
[root@rabbit2 ~]# rabbitmqctl join_cluster rabbit@rabbit1
Clustering node rabbit@rabbit2 with rabbit@rabbit1
[root@rabbit2 ~]#  rabbitmqctl start_app
Starting node rabbit@rabbit2

设置队列镜像

[root@rabbit2 ~]# rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "^" to "{\"ha-mode\":\"all\"}" with priority "0"
[root@rabbit2 ~]#

###正常的话就能看到管理界面显示

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: