参考http://kaibinyuan.blog.51cto.com/7304008/1616454

参考http://luchunli.blog.51cto.com/2368057/1681841

1.安装zookeeper单机模式

配置java环境

[root@zookeeper ~]# wget https://www.reucon.com/cdn/java/jdk-8u45-linux-x64.tar.gz[root@zookeeper ~]# tar xf jdk-8u45-linux-x64.tar.gz[root@zookeeper ~]# cp -r jdk1.8.0_45 /usr/local/[root@zookeeper ~]# cat /etc/profile.d/java.shJAVA_HOME=/usr/local/jdk1.8.0_45JAVA_BIN=/usr/local/jdk1.8.0_45/binJRE_HOME=/usr/local/jdk1.8.0_45/jrePATH=$PATH://usr/local/jdk1.8.0_45/bin:/usr/local/jdk1.8.0_45/jre/binCLASSPATH=/usr/local/jdk1.8.0_45/jre/lib:/usr/local/jdk1.8.0_45/lib:/usr/local/jdk1.8.0_45/jre/lib/charsets.jar[root@zookeeper ~]# source /etc/profile.d/java.sh[root@zookeeper ~]# java -versionjava version "1.8.0_45"Java(TM) SE Runtime Environment (build 1.8.0_45-b14)Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

下载软件包

[root@zookeeper ~]# wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

安装

[root@zookeeper ~]# tar xf zookeeper-3.4.6.tar.gz -C /usr/local/[root@zookeeper ~]# ln -s /usr/local/zookeeper-3.4.6/ /usr/local/zookeeper[root@zookeeper conf]# pwd/usr/local/zookeeper/conf[root@zookeeper conf]# cp zoo_sample.cfg zoo.cfg#修改配置文件[root@zookeeper conf]# egrep -v "^#|^$" /usr/local/zookeeper/conf/zoo.cfg tickTime=2000initLimit=10syncLimit=5dataDir=/data/zookeeper/buildclientPort=2181dataLogDir=/data/zookeeper/logs#tickTime: 这个时间是作为Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔, 也就是每个tickTime时间就会发送一个心跳#dataDir: 顾名思义就是Zookeeper保存数据的目录, 默认情况下, Zookeeper将写数据的日志也保存在这个目录里#clientPort: 这个端口就是客户端连接Zookeeper服务器的端口, Zookeeper会监听这个端口, 接受客户端的访问请求

启动zookeeper

[root@zookeeper ~]# /usr/local/zookeeper/bin/zkServer.sh startJMX enabled by defaultUsing config: /usr/local/zookeeper/bin/../conf/zoo.cfgStarting zookeeper ... STARTED#查看结果[root@zookeeper ~]# netstat -tunlp |grep 2181tcp        0      0 :::2181                     :::*                        LISTEN      1444/java

2.安装zookeeper集群

zookeeper-1    192.168.3.19

zookeeper-2    192.168.3.20

zookeeper-1操作:

#停止zookeeper服务[root@zookeeper ~]# /usr/local/zookeeper/bin/zkServer.sh stopJMX enabled by defaultUsing config: /usr/local/zookee#修改配置文件/usr/local/zookeeper/conf/zoo.cfg[root@zookeeper ~]# egrep -v "^$|^#" /usr/local/zookeeper/conf/zoo.cfg tickTime=2000initLimit=10syncLimit=5dataDir=/data/zookeeper/buildclientPort=2181dataLogDir=/data/zookeeper/logsserver.1 = 192.168.3.19:2888:3888server.2 = 192.168.3.20:2888:3888#配置myid[root@zookeeper ~]# cat /data/zookeeper/build/myid 1

zookeeper-2需要安装java和zookeeper,过程请看上文

#配置文件内容如下[root@zookeeper-2 conf]# egrep -v "^$|^#" /usr/local/zookeeper/conf/zoo.cfg tickTime=2000initLimit=10syncLimit=5dataDir=/data/zookeeper/buildclientPort=2181dataLogDir=/data/zookeeper/logsserver.1 = 192.168.3.19:2888:3888server.2 = 192.168.3.20:2888:3888#启动服务[root@zookeeper-2 ~]# /usr/local/zookeeper/bin/zkServer.sh startJMX enabled by defaultUsing config: /usr/local/zookeeper/bin/../conf/zoo.cfgStarting zookeeper ... STARTED

最后验证集群状态

#zookeeper-1[root@zookeeper ~]# /usr/local/zookeeper/bin/zkServer.sh statusJMX enabled by defaultUsing config: /usr/local/zookeeper/bin/../conf/zoo.cfgMode: leader#zookeeper-2[root@zookeeper-2 ~]# /usr/local/zookeeper/bin/zkServer.sh statusJMX enabled by defaultUsing config: /usr/local/zookeeper/bin/../conf/zoo.cfgMode: follower

通过客户端脚本验证

[root@zookeeper ~]# /usr/local/zookeeper/bin/zkCli.sh[zk: localhost:2181(CONNECTED) 2] ls /[zookeeper]                # 第一次部署Zookeeper集群,默认创建名为/zookeeper的节点[zk: localhost:2181(CONNECTED) 3] ls /zookeeper[quota]# 读取znode数据[zk: localhost:2181(CONNECTED) 5] get /zookeeper/quota   cZxid = 0x0ctime = Thu Jan 01 08:00:00 CST 1970mZxid = 0x0mtime = Thu Jan 01 08:00:00 CST 1970pZxid = 0x0cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 0numChildren = 0# 创建znode[zk: localhost:2181(CONNECTED) 6] create /zk-book 123Created /zk-book[zk: localhost:2181(CONNECTED) 7] ls /[zk-book, zookeeper][zk: localhost:2181(CONNECTED) 8] get /zk-book123cZxid = 0x300000004ctime = Tue Aug 11 14:46:48 CST 2015mZxid = 0x300000004mtime = Tue Aug 11 14:46:48 CST 2015pZxid = 0x300000004cversion = 0dataVersion = 0            # version的版本为0aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 0# 更新znode的值[zk: localhost:2181(CONNECTED) 9] set /zk-book 456cZxid = 0x300000004ctime = Tue Aug 11 14:46:48 CST 2015mZxid = 0x300000005mtime = Tue Aug 11 14:47:45 CST 2015pZxid = 0x300000004cversion = 0dataVersion = 1            # 更新后version的版本为1aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 0#在zookeeper-2上查看结果[root@zookeeper-2 ~]# /usr/local/zookeeper/bin/zkCli.sh [zk: localhost:2181(CONNECTED) 1] get /zk-book456cZxid = 0x300000004ctime = Tue Aug 11 14:46:48 CST 2015mZxid = 0x300000005mtime = Tue Aug 11 14:47:45 CST 2015pZxid = 0x300000004cversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 0#在zookeeper-2上删除/zk-book[zk: localhost:2181(CONNECTED) 2] delete /zk-book[zk: localhost:2181(CONNECTED) 3] ls /[zookeeper]#在zookeeper-1上查看结果[zk: localhost:2181(CONNECTED) 10] ls /[zookeeper]

安装metaq

这里要安装2台meatq,在2个zookeeper上各安装一个

参考http://linuxblind.blog.51cto.com/7616603/1266752

[root@zookeeper ~]# wget http://fnil.net/downloads/metaq-server-1.4.6.2.tar.gz[root@zookeeper ~]# tar xf metaq-server-1.4.6.2.tar.gz[root@zookeeper ~]# mv taobao /usr/local/[root@zookeeper ~]# groupadd metaq[root@zookeeper ~]# useradd metaq -g metaq#修改后的配置文件为[root@zookeeper ~]# egrep -v "^$|^;" /usr/local/taobao/metamorphosis-server-wrapper/conf/server.ini [system]brokerId=0        #注意:brokerid 确保是集群中唯一的,可选取:1/2/3numPartitions=1serverPort=8123dashboardHttpPort=8120unflushThreshold=0unflushInterval=10000maxSegmentSize=1073741824maxTransferSize=1048576deletePolicy=delete,168deleteWhen=0 0 6,18 * * ?flushTxLogAtCommit=1stat=truedataPath=/data/metaq/datadataLogPath=/data/metqa/logupdateConsumerOffsets=true[zookeeper]                        #注意一定要配置的是集群而非集群中一台ip和端口zk.zkConnect=192.168.3.19:2181,192.168.3.20:2181zk.zkSessionTimeoutMs=30000zk.zkConnectionTimeoutMs=30000zk.zkSyncTimeMs=5000[topic=test][topic=meta-test]