wendu 发表于 2019-1-8 12:34:06

zookeeper+activemq配置消息中间件集群

  需求:
  1、将大量的WebService请求报文发送到mq集群之中,并保持消息先后顺序
  2、保证每个消息的可靠性
  3、维护MQ服务器的可扩展性
  综合考虑,决定使用Apache的 activemq。接触的时候,新的activemq 5.10已经出,所以,本项目使用的是activemq5.10。activemq5.10要求jdk6+,由于项目立项比较老,所以将项目整体迁移到jdk1.7进行部署,并引入activemq服务器。OK,废话不多说,开始。
  首先,选三台服务器。
  之所以选三台,是因为zookeeper推荐最低三台配置,这样可以保持最大的可用服务器数,具体的这里不多说,可以查阅zookeeper的安装配置,以后有机会,详细讲解zookeeper。
  我这里选择三台Linux服务器,ip地址分别为:192.168.120.241,192.168.120.242,192.168.120.171。系统均使用centos6.4
  1、创建账号
  useradd amqbroker;//默认会创建amqbroker的群组,并且amqbroker会自动加入amqbroker群组。
  passwd amqbroker;修改密码
  cd /home/amqbroker切换目录
  2、下载zookeeper
  wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz
  tar -xvfzookeeper-3.3.6.tar.gz
  修改配置,mv zoo_sample.cfg zoo.cfg
  vi zoo.cfg,内容如下:
  1 # The number of milliseconds of each tick
  2 tickTime=2000
  3 # The number of ticks that the initial
  4 # synchronization phase can take
  5 initLimit=10
  6 # The number of ticks that can pass between
  7 # sending a request and getting an acknowledgement
  8 syncLimit=5
  9 # the directory where the snapshot is stored.
  10 # do not use /tmp for storage, /tmp here is just
  11 # example sakes.
  12
  13 dataDir=/home/amqbroker/zkdir/data
  14 dataLogDir=/home/amqbroker/zkdir/log
  15 # the port at which the clients will connect
  16 clientPort=2181
  17 # the maximum number of client connections.
  18 # increase this if you need to handle more clients
  19 #maxClientCnxns=60
  20 #
  21 # Be sure to read the maintenance section of the
  22 # administrator guide before turning on autopurge.
  23 #
  24 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  25 #
  26 # The number of snapshots to retain in dataDir
  27 #autopurge.snapRetainCount=3
  28 # Purge task interval in hours
  29 # Set to "0" to disable auto purge feature
  30 #autopurge.purgeInterval=1
  31
  32
  33 ##three servers of this cluster
  34 server.1=192.168.120.241:2888:3888
  35 server.2=192.168.120.242:2888:3888
  36 server.3=192.168.120.171:2888:3888
  dataDir=/home/amqbroker/zkdir/data
  dataLogDir=/home/amqbroker/zkdir/log这两行说明了,需要创建一个文件夹,分别存放data以及log,所以,在/home/amqbroker下创建文件夹zkdir,也可以创建在其他地方,只要配置中指定就好
  在zkdir/data下,创建myid文件,并写入与ip地址相称的服务器编号,比如,192.168.120.241,写入 1;echo 1>myid;
  其他两台机器配置相同,不过myid文件写入相应的id号
  启动服务:
  cd /home/amqbroker/zookeeper-3.3.6/bin
  ./zkServer.sh start
  可以使用zookeeper自带的客户端测试:
  ./zkCli.sh -server 192.168.120.241:2181
  其他两台一样配置
  3、下载activemq-5.10
  wgethttp://archive.apache.org/dist/activemq/5.10.1/apache-activemq-5.10.1-bin.tar.gz
  tar -xvf apache-activemq-5.10.1-bin.tar.gz
  vi apache-activemq-5.10.1/conf/activemq.xml

[*]  11   Unless required by applicable law or agreed to in writing, software
[*]  12   distributed under the License is distributed on an "AS IS" BASIS,
[*]  13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
[*]  14   See the License for the specific language governing permissions and
[*]  15   limitations under the License.
[*]  16 -->
[*]  17
[*]  18
[*]  23
[*]  24   
[*]  25   
[*]  26         
[*]  27             file:${activemq.conf}/credentials.properties
[*]  28         
[*]  29   
[*]  30
[*]  31   
[*]  32   
[*]  38   
[*]  41   
[*]  42
[*]  43         
[*]  44            
[*]  45               

[*]  46            
[*]  47               
[*]  48                     
[*]  49                           
[*]  50                        
[*]  51                     
[*]  52               
[*]  53               
[*]  54                     
[*]  55                        
[*]  56                           
[*]  57                     
[*]  58                  
[*]  59               
[*]  60                     
[*]  68                  
[*]  69                     
[*]  70                  
[*]  71               
[*]  72               
[*]  73            
[*]  74         
[*]  75
[*]  76
[*]  77         
[*]  84         
[*]  85            
[*]  86         
[*]  87
[*]  88         
[*]  95
[*]  96      
[*]  101      
[*]  102         
[*]  111      
[*]  112
[*]  113         
[*]  118         
[*]  119            
[*]  120               
[*]  121                     
[*]  122               
[*]  123               
[*]  124                     
[*]  125               
[*]  126               
[*]  127                     
[*]  128               
[*]  129            
[*]  130         
[*]  131
[*]  132         
[*]  138         
[*]  139            
[*]  140            
[*]  141            
[*]  142            
[*]  143            
[*]  144            
[*]  145         
[*]  146
[*]  147         
[*]  148         
[*]  149            
[*]  150         
[*]  151
[*]  152   
[*]  153
[*]  154   
[*]  160   
[*]  161
[*]  162
  以上是192.168.120.241的activemq的activemq.xml配置文件配置。因为使用的是zookeeper,所以注意persistenceAdapter这个节点配置,如果有zkpassword,则填写,否则不要填写。按照上边的配置,zkpassword是不需要写的。
  还有broker配置中,有一些policyEntity,是定制的,比如DLQ的配置,是因为针对不同的队列,重发机制的最大次数重发完以后,如果还有异常,则进入该队列定制的DLQ之中,详细的一些参数设置,请参考activemq官方文档。
  另外,配置中应该有安全配置,目前没有写入,后续在说
  另外两台服务器的配置与该文档相似,唯一不同就是    hostname="192.168.120.241"这里,需要写入各自的ip地址
  启动activemq服务器
  cd /home/amqbroker/activemq***/bin
  ./activemq start
  三台服务器启动类似
  然后,在浏览器地址栏里输入:
  http://192.168.120.241:8161/admin/queues.jsp
  http://192.168.120.242:8161/admin/queues.jsp
  http://192.168.120.171:8161/admin/queues.jsp
  因为使用zookeeper做负载均衡,三台只有一台是master,其他两台处于等待状态,所以只有其中一台提供服务,但一旦这台服务器宕机以后,会有另外一台顶替上来,所以其他几个ip地址是打不开的,只有一台能打开
  在客户端使用的时候,使用 failover进行配置的,如下:
  ##使用replicaDB方式来搭建activemq,使用zookeeper集群进行负载均衡以及数据同步
  mq.broker.url=failover:(tcp://192.168.120.241:61616,tcp://192.168.120.242:61616,tcp://192.168.120.171:61616)?initialReconnectDelay=1000
  本文出自http://blog.csdn.net/icecream0/article/details/44101987

页: [1]
查看完整版本: zookeeper+activemq配置消息中间件集群