RabbitMQ集群与Redis集群 之2台云服务器多机的坑

我只有一台服务器的时候找集群的文章都是多台服务器的 我去买了台服务器然后搜又全是单机或者虚拟机的 这是被针对了吧 而且同样是云服务器 为什么腾讯云比别的慢

 

1.Redis

      redis搭建集群需要至少6个节点  所以得拷贝redis.conf到一个cluster的文件夹的不同端口号的子文件夹下

[root@rabbitMq1 cluster]# cp ../redis.conf  /opt/redis-4.0.9/cluster/7001/redis.conf
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# cp ../redis.conf  /opt/redis-4.0.9/cluster/7002/redis.conf
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# cp ../redis.conf  /opt/redis-4.0.9/cluster/7003/redis.conf

复制之前提前修改好redis里面的配置

以网上常见的7000端口为例

#端口7000,7001,7002 是我们选定要启动的端口,这里选择启动7000

port 7000

#默认ip为127.0.0.1,需要改为其他节点机器可访问的ip,否则创建集群时无法访问对应的端口,无法创建集群 (注意这里填ifconfig 出来的eth0的ip地址 不然打死没办法启动)

bind 192.168.252.101

#redis后台运行

daemonize yes 

#启动日志注意 /redis不存在 需要自己先mkdir一下

logfile "/var/log/redis/redis.log"

#开启集群,把注释#去掉

cluster-enabled yes

#集群的配置,配置文件首次启动自动生成 7000,7001,7002

cluster-config-file nodes_7000.conf

#请求超时,默认15秒,可自行设置

cluster-node-timeout 10100

#aof日志开启,有需要就开启,它会每次写操作都记录一条日志 appendonly yes

 

然后分别启动它们,这样就有6个redis实例啦:

[root@rabbitMq1 cluster]# ../src/redis-server ./7001/redis.conf 
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# ps -ef| grep redis
root     26226     1  0 21:27 ?        00:00:00 ../src/redis-server 172.27.0.11:7001 [cluster]
root     26238 21091  0 21:27 pts/1    00:00:00 grep --color=auto redis
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# ../src/redis-server ./7002/redis.conf 
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# 
[root@rabbitMq1 cluster]# ../src/redis-server ./7003/redis.conf 
 

这里省略外面博客到处都是的安装ruby,以及redis和ruby连接,当然如果提示redis requires Ruby version >= 2.2.2的话,

https://blog.csdn.net/FengYe_YuLu/article/details/77628094?utm_source=blogxgwz4 这篇博客还是不错的

 

然后创建集群:[root@localhost ~]# redis-trib.rb create --replicas 1  192.168.0.164:7001 192.168.0.164:7002 192.168.0.164:7003 192.168.0.170:7004 192.168.0.170:7005 192.168.0.170:7006
[ERR] Sorry, can't connect to node ip:7001 这时候就需要 vi nodes-7001.conf  ip:7003@17003把你的ip配置进去 然后再启动就能顺利的启动

 

2.坑2:集群设置密码 https://www.cnblogs.com/linjiqin/p/7462822.html 这里的大神说的挺好的 

看成功啦 坑爹的

 

 

2.RabbitMQ的坑:

RabbitMq集群过程中的坑:

1.erlange.code的复制(因为通信是靠这个来完成的)  需要从一个云服务器复制到另一个云服务器上 注意保持文件的权限一致 我先全部设成777 复制成功后才改成了400 部分可能提示没有权限什么的(检查下密码 更改下文件的权限授权什么的)

 

2.需要修改/etc/hosts 定义2台服务器的地址和对应的hostname

修改/host文件:

 

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

ip2 rabbitMq2

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

#172.16.16.4 instance-m7bri80u instance-m7bri80u.novalocal

ip1 rabbitMq1

ip2 rabbitMq2

 

修改hostname文件:

[root@rabbitMq2 ~]# vi /etc/hostname

rabbitMq2

 

然后用hostname命令修改 之后重启

 

这样前置工作就完成了.

下面是是后面遇到的错误

rabbitmqctl status

Status of node rabbit@rabbitMq1 ...

Error: unable to perform an operation on node 'rabbit@rabbitMq1'. Please see diagnostics information and suggestions below.

Most common reasons for this are:

* Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)

* CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)

* Target node is not running

 

In addition to the diagnostics info below:

 

* See the CLI, clustering and networking guides on http://rabbitmq.com/documentation.html to learn more

* Consult server logs on node rabbit@rabbitMq1

DIAGNOSTICS

===========

attempted to contact: [rabbit@rabbitMq1]

rabbit@rabbitMq1:

* connected to epmd (port 4369) on rabbitMq1

* epmd reports: node 'rabbit' not running at all

no other nodes on rabbitMq1

* suggestion: start the node

Current node details:

* node name: 'rabbitmqcli-3376-rabbit@rabbitMq1'

* effective user's home directory: /var/lib/rabbitmq

* Erlang cookie hash: DOniGsghWeOCIJ0+N0z3VA==

 

这时候运行rabbitmqctl命令会出错,这是因为旧的rabbitmq服务还在运行,用ps命令查看所有在运行的rabbitmq服务,然后kill掉,然后再用service rabbirmq-service命令启动rabbitmq服务,

再用

rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster rabbit@rmq-broker-test-2 rabbitmqctl start_app

来进行操作 注意谁是主,谁是从.

#加入时候设置节点为内存节点(性能好)(默认加入的为磁盘节点(可以保存))

[root@mq-testvm1 ~]# rabbitmqctl join_cluster rabbit@rmq-broker-test-1 --ram

 

#也通过下面方式修改的节点的类型

[root@mq-testvm1 ~]# rabbitmqctl changeclusternode_type disc | ram

 

但是添加集群之后发现之前添加的用户不见了,也不知道什么鬼,所以重新添加用户并设置密码:

 

rabbitmqctl add_user admin 123456

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

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

修改用户角色(加入administrator用户组)

rabbitmqctl set_user_tags admin administrator

看成功啦 而且管理台里面也显出了2个node 队列也是同步的 很棒!

 

 

 

 

 

 


版权声明:本文为qq1782原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。