0


Zookeeper+ActiveMQ集群搭建

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!

$ mv zoo_sample.cfg zoo.cfg

  • 编辑zoo.cfg文件

$ vim zoo.cfg

The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. #这个地方的目录地址改一下 dataDir=/usr/local/zookeeper-3.4.5/data #日志目录 dataLogDir=/usr/local/zookeeper-3.4.5/logs # the port at which the clients will connect clientPort=2181 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to “0” to disable auto purge feature #autopurge.purgeInterval=1 #配置三个server server.0=192.168.192.130:2888:3888 server.1=192.168.192.131:2888:3888 server.2=192.168.192.134:2888:3888

  • 在zookeeper-3.4.5目录下创建data文件夹和logs文件夹

$ cd /usr/local/zookeeper-3.4.5

$mkdir data

$mkdir logs

  • 在三个虚拟机下的data文件夹下创建三个myid文件,并且三个文件里面分别写入0,1,2

$ cd /usr/local/zookeeper-3.4.5/data

#192.168.192.130下 vim myid 在文件里面写入0,保存退出 #192.168.192.131下 vim myid 在文件里面写入1,保存退出 #192.168.192.134下 vim myid 在文件里面写入2,保存退出

  • 启动三个zookeeper

$ zkServer.sh start

[root@localhost data]# zkServer.sh start JMX enabled by default Using config: /usr/local/zookeeper-3.4.5/bin/…/conf/zoo.cfg Starting zookeeper … STARTED [root@localhost data]#

  • ps:常用命令:

启动: zkServer.sh start

停止: zkServer.sh stop

重启: zkServer.sh restart

查看服务状态: zkServer.sh status

  • 遇到的问题1:

用zkServer.sh start启动报错说zkServer.sh:未找到命令 就用 ./zkServer.sh start 来启动

  • 遇到的问题2:

三台虚拟机启动后用zkServer.sh status查看状态发现有错误

[root@localhost conf]# zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.4.5/bin/…/conf/zoo.cfg Error contacting service. It is probably not running.

然后用$zkServer.sh start-foreground命令来启动查看启动日志 发现日志报错

java.net.NoRouteToHostException: No route to host at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:354) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:388) at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:765) at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:716) 2016-11-13 18:00:35,602 [myid:0] - WARN [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@368] - Cannot open channel to 1 at election address /192.168.192.131:3888

java.net.NoRouteToHostException: No route to host at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:354) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:388) at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:765) at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:716) 2016-11-13 18:00:36,035 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@774] - Notification time out: 800 2016-11-13 18:00:36,837 [myid:0] - WARN [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@368] - Cannot open channel to 2 at election address /192.168.192.134:3888

初步断定是防火墙的问题,我们关闭防火墙试试看能不能解决问题

#关闭防火墙

$ systemctl stop firewalld.service

重新启动zookeeper我们发现可以使用了。问题解决

3、搭建ActiveMQ并和Zookeeper建立集群

搭建三个ActiveMQ,分在三个服务器上,每一个服务器上一个。192.169.192.130是node1,192.168.192.131是node2,192.168.192.134是node3

(1) 解压 tar -zxvf apache-activemq-5.14.1-bin.tar.gz

(2) 创建文件夹mkdir /usr/local/activemq-cluster

(3) 将第一步解压的文件夹移动到activemq-cluster下

(4) 改名文件夹 mv apache-activemq-5.14.1 node1 (其他两台服务器也如此操作并分别改名为node2,node3)

(5) 修改conf/activemq.xml文件 vim activemq.xml。修改其中的bind、zkAddress、bhotname、zkPath。

(6) node1第一处修改:brokerName=“active-cluster”

(7)node1 第二处修改:

(8)node1 第三处修改:修改name=“openwire”

(9) node2 第一处修改

(10) node2第二处修改

(11) node2第三处修改参考

(12) node3第一处修改

面试题总结

其它面试题(springboot、mybatis、并发、java中高级面试总结等)

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!
kKuCnkjO-1714771889385)]

[外链图片转存中…(img-FwfU5N5Z-1714771889386)]

[外链图片转存中…(img-HCmsdgcA-1714771889386)]

《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门,即可获取!


本文转载自: https://blog.csdn.net/2301_78850344/article/details/138432664
版权归原作者 2301_78850344 所有, 如有侵权,请联系我们删除。

“Zookeeper+ActiveMQ集群搭建”的评论:

还没有评论