Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3785334
  • 博文数量: 880
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 6155
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-11 09:12
个人简介

To be a better coder

文章分类

全部博文(880)

文章存档

2022年(5)

2021年(60)

2020年(175)

2019年(207)

2018年(210)

2017年(142)

2016年(81)

分类: LINUX

2020-07-02 16:37:20

环境准备

基于centos7.5,自动分区,基础设施服务,两个虚机

配置ip route dns


以下以node1为例,node2同理

[root@localhost /]# hostname node1

[root@localhost /]# hostname

node1

[root@localhost /]#

[root@localhost /]# cat etc/hosts

#在node1hosts文件里增加:

192.168.27.124 node1

192.168.27.157 node2

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4  node1

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6  node1

[root@localhost /]#


安装rabbitmq

[root@localhost /]#

[root@localhost /]# ip route add default via 192.168.27.1

[root@localhost /]# vi etc/resolv.conf

[root@localhost /]#

[root@localhost /]#

[root@localhost /]# ping

PING (220.181.38.149) 56(84) bytes of data.

64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=1 ttl=52 time=2.44 ms

^C

--- ping statistics ---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 2.446/2.446/2.446/0.000 ms

[root@localhost /]# wget

--2020-07-02 13:49:20-- 

正在解析主机 ()... 104.20.11.224, 104.20.10.224, 172.67.16.25, ...

正在连接 ()|104.20.11.224|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 301 Moved Permanently

位置:https:///releases/erlang/erlang-18.3-1.el7.centos.x86_64.rpm [跟随至新的 URL]

--2020-07-02 13:49:21--  https:///releases/erlang/erlang-18.3-1.el7.centos.x86_64.rpm

正在连接 ()|104.20.11.224|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:18345424 (17M) [application/x-redhat-package-manager]

正在保存至: erlang-18.3-1.el7.centos.x86_64.rpm


100%[======================================================================================================================================================================================>] 18,345,424  52.9KB/s 用时 3m 2s 


2020-07-02 13:52:24 (98.6 KB/s) - 已保存 “erlang-18.3-1.el7.centos.x86_64.rpm [18345424/18345424])


[root@localhost /]# wget https:///rabbitmq-signing-key-public.asc

--2020-07-02 13:52:27--  https:///rabbitmq-signing-key-public.asc

正在解析主机 ()... 104.20.10.224, 172.67.16.25, 104.20.11.224, ...

正在连接 ()|104.20.10.224|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:未指定 [text/plain]

正在保存至: rabbitmq-signing-key-public.asc


    [ <=>                                                                                                                                                                                   ] 1,702       --.-K/s 用时 0s     


2020-07-02 13:52:28 (33.0 MB/s) - “rabbitmq-signing-key-public.asc” 已保存 [1702]


[root@localhost /]# wget http:///releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm

--2020-07-02 13:52:38--  http:///releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm

正在解析主机 ()... 104.20.11.224, 104.20.10.224, 172.67.16.25, ...

正在连接 ()|104.20.11.224|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 301 Moved Permanently

位置:https:///releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm [跟随至新的 URL]

--2020-07-02 13:52:39--  https:///releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm

正在连接 ()|104.20.11.224|:443... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:5088884 (4.9M) [application/x-redhat-package-manager]

正在保存至: rabbitmq-server-3.6.1-1.noarch.rpm


100%[======================================================================================================================================================================================>] 5,088,884    210KB/s 用时 22s   


2020-07-02 13:53:03 (230 KB/s) - 已保存 “rabbitmq-server-3.6.1-1.noarch.rpm [5088884/5088884])


[root@localhost /]# ls

bin  boot  dev  erlang-18.3-1.el7.centos.x86_64.rpm  etc  home  lib  lib64  media  mnt  opt  proc  rabbitmq-server-3.6.1-1.noarch.rpm  rabbitmq-signing-key-public.asc  root  run  sbin  srv  sys  tmp  usr  var

[root@localhost /]#

[root@localhost /]#

[root@localhost /]# rpm --import rabbitmq-signing-key-public.asc

[root@localhost /]# rpm -Uvh erlang-18.3-1.el7.centos.x86_64.rpm rabbitmq-server-3.6.1-1.noarch.rpm

准备中...                          ################################# [100%]

正在升级/安装...

   1:erlang-18.3-1.el7.centos         ################################# [ 50%]

   2:rabbitmq-server-3.6.1-1          ################################# [100%]

[root@localhost /]# firewall-cmd --permanent --add-port=15672/tcp

success

[root@localhost /]# firewall-cmd --reload

success

[root@localhost /]# chkconfig rabbitmq-server on

[root@localhost /]# service rabbitmq-server start

Starting rabbitmq-server (via systemctl):                  [  确定  ]

[root@localhost /]# rabbitmq-plugins enable rabbitmq_management

The following plugins have been enabled:

  mochiweb

  webmachine

  rabbitmq_web_dispatch

  amqp_client

  rabbitmq_management_agent

  rabbitmq_management


Applying plugin configuration to rabbit@localhost... started 6 plugins.

[root@localhost /]# rabbitmqctl add_user admin admin

Creating user "admin" ...

[root@localhost /]# rabbitmqctl set_user_tags admin administrator

Setting tags for user "admin" to [administrator] ...

[root@localhost /]#  rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

Setting permissions for user "admin" in vhost "/" ...

[root@localhost /]# rabbitmqctl delete_user guest

Deleting user "guest" ...

[root@localhost /]# netstat -anp | grep 5672

tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      11306/beam.smp     

tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      11306/beam.smp     

tcp        0      0 127.0.0.1:50755         127.0.0.1:25672         TIME_WAIT   -                  

tcp        0      0 127.0.0.1:57398         127.0.0.1:25672         TIME_WAIT   -                  

tcp        0      0 127.0.0.1:44745         127.0.0.1:25672         TIME_WAIT   -                  

tcp6       0      0 :::5672                 :::*                    LISTEN      11306/beam.smp     

[root@localhost /]#

[root@localhost /]#


[root@localhost /]#

[root@localhost /]# history

    1  cd /

    2  ip route add default via 192.168.27.1

    3  vi etc/resolv.conf

    4  ping

    5  wget

    6  wget https:///rabbitmq-signing-key-public.asc

    7  wget http:///releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm

    8  ls

    9  rpm --import rabbitmq-signing-key-public.asc

   10  rpm -Uvh erlang-18.3-1.el7.centos.x86_64.rpm rabbitmq-server-3.6.1-1.noarch.rpm

   11  firewall-cmd --permanent --add-port=15672/tcp

   12  firewall-cmd --reload

   13  chkconfig rabbitmq-server on

   14  service rabbitmq-server start

   15  rabbitmq-plugins enable rabbitmq_management

   16  rabbitmqctl add_user admin admin

   17  rabbitmqctl set_user_tags admin administrator

   18   rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

   19  rabbitmqctl delete_user guest

   20  netstat -anp | grep 5672

   21  history

[root@localhost /]#

集群设置:

在两个节点上rabbitmqctl stop

node1中的 erlang.cookie 复制到 node2中:

[root@node1 ~]# find / -name ".erlang.cookie"
/var/lib/rabbitmq/.erlang.cookie
[root@node1 ~]# cat /var/lib/rabbitmq/.erlang.cookie
XXZDFERERTFDFSEEM

[root@node1 ~]# scp /var/lib/rabbitmq/.erlang.cookie root@node2:/var/lib/rabbitmq

关闭防火墙(否则提示连接不上)

systemctl stop firewalld

systemctl disable firewalld

在两个节点上 rabbitmq-server -detached

查看集群状态

[root@node1 ~]# rabbitmqctl cluster_status

Cluster status of node rabbit@node1 ...

[{nodes,[{disc,[rabbit@node1]}]},

 {running_nodes,[rabbit@node1]},

 {cluster_name,<<"rabbit@node1">>},

 {partitions,[]},

 {alarms,[{rabbit@node1,[]}]}]

[root@node1 ~]#

node2

     rabbitmqctl stop_app

     rabbitmqctl reset

     rabbitmqctl join_cluster --ram rabbit@node1

     rabbitmqctl start_app

其中–ram指的是作为内存节点,要是想做为磁盘节点的话,就不用加–ram这个参数了,把第3行写成这样就好了

PS:只要在节点列表里包含了本身,它就成为一个磁盘节点。在RabbitMQ集群里,必须至少有一个磁盘节点存在

查看集群状态

[root@node1 ~]# rabbitmqctl cluster_status

Cluster status of node rabbit@node1 ...

[{nodes,[{disc,[rabbit@node1,rabbit@node2]}]},

 {running_nodes,[rabbit@node2,rabbit@node1]},

 {cluster_name,<<"rabbit@node1">>},

 {partitions,[]},

 {alarms,[{rabbit@node2,[]},{rabbit@node1,[]}]}]

[root@node1 ~]#



添加用户

由于guest这个用户,只能在本地访问,所以我们要新增一个用户并赋予权限

添加管理员账号(用户名密码都为admin):

rabbitmqctl add_user admin admin

添加权限(使admin用户对虚拟主机“/” 具有所有权限):

rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"

分配用户标签(管理员组):

rabbitmqctl set_user_tags admin administrator

查看列举用户列表:

rabbitmqctl list_users

配置之后,然后就可以远程访问了,然后可直接配置用户权限等信息,到此,就可以通过 使用admin admin 进行登陆了。

到这里的话,每个节点是作为单独的一台RabbitMQ存在的,也可以正常提供服务了。

如果有需要修改密码操作如下(后两个参数为用户名和密码):

rabbitmqctl  change_password  Username  Newpassword

此时就可以使用账号远程登录了:

注意:这里添加用户后,登录任意一台集群环境web端都可以进去,也就是用户是针对所有集群机器的

问题:

启动失败 service rabbitmq-server start 报错

[root@node1 ~]#  systemctl status rabbitmq-server

rabbitmq-server.service - LSB: Enable AMQP service provided by RabbitMQ broker

   Loaded: loaded (/etc/rc.d/init.d/rabbitmq-server; bad; vendor preset: disabled)

   Active: failed (Result: exit-code) since 四 2020-07-02 14:18:39 CST; 2min 32s ago

     Docs: man:systemd-sysv-generator(8)

  Process: 13131 ExecStop=/etc/rc.d/init.d/rabbitmq-server stop (code=exited, status=0/SUCCESS)

  Process: 15650 ExecStart=/etc/rc.d/init.d/rabbitmq-server start (code=exited, status=1/FAILURE)


7月 02 14:18:38 node1 systemd[1]: Starting LSB: Enable AMQP service provided by RabbitMQ broker...

7月 02 14:18:38 node1 su[15727]: (to rabbitmq) root on none

7月 02 14:18:39 node1 su[15879]: (to rabbitmq) root on none

7月 02 14:18:39 node1 su[15878]: (to rabbitmq) root on none

7月 02 14:18:39 node1 rabbitmq-server[15650]: Starting rabbitmq-server: FAILED - check /var/log/rabbitmq/startup_{log, _err}

7月 02 14:18:39 node1 rabbitmq-server[15650]: rabbitmq-server.

7月 02 14:18:39 node1 systemd[1]: rabbitmq-server.service: control process exited, code=exited status=1

7月 02 14:18:39 node1 systemd[1]: Failed to start LSB: Enable AMQP service provided by RabbitMQ broker.

7月 02 14:18:39 node1 systemd[1]: Unit rabbitmq-server.service entered failed state.

7月 02 14:18:39 node1 systemd[1]: rabbitmq-server.service failed.

[root@node1 ~]#

解决办法:

1)   ps -aux|grep rabbitmq   //杀掉除grep外的pid


阅读(1062) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~