1. Zookeeper服务集群规模不小于三个节点,要求各服务之间系统时间要保持一致。
2. 在m1的usr/local目录下,解压缩zookeeper(执行命令tar –zvxf zookeeper.tar.gz)
3. 设置环境变量
打开/etc/profile文件!内容如下:
- #set java & hadoop
- export JAVA_HOME=/usr/local/program/jdk
- export HADOOP_HOME=/usr/local/program/hadoop
- export ZOOKEEPER_HOME=/usr/local/program/zookeeper
- export PATH=.:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$JAVA_HOME/bin:$PATH
注:修改完后profile记得执行source /etc/profile
4. 在解压后的zookeeper的目录下进入conf目录修改配置文件(zk版本为:zookeeprer-3.4.6)
更名操作:mv zoo_sample.cfg zoo.cfg
5. 编辑zoo.cfg (vi zoo.cfg)
修改dataDir=/usr/local/program/zookeeper/data/
新增server.0=m1:2888:3888
server.1=s1:2888:3888
server.2=s2:2888:3888
文件如下:
- # 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/program/zookeeper/data
- # 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.0=m1:2888:3888
- server.1=s1:2888:3888
- server.2=s2:2888:3888
注:
- server.0=m1:2888:3888
- server.1=s1:2888:3888
- server.2=s2:2888:3888
这三行为配置zookeeper集群的机器(m1、s1、s2)分别用server.0和server.1、server.2标识,2888和3888为端口号(zookeeper集群包含一个leader(领导)和多个fllower(随从),启动zookeeper集群时会随机分配端口号,分配的端口号为2888的为leader,端口号为3888的是fllower)
6. 创建文件夹mkdir /usr/local/program/zookeeper/data
7. 在data目录下,创建文件myid,值为0 (0用来标识m1这台机器的zookeeper )
到此为止 m1上的配置就已经完成;接下来配置s1和s2.
8. 把zookeeper目录复制到s1和s2中(scp –r /usr/local/program/zookeeper s1:/usr/local/program/zookeeper)
9. 把修改后的etc/profile文件复制到s1和s2中
(复制完后记得在s1和s2中执行命令source /etc/profile)
10. 把s1中相应的myid中的值改为1,s2中相应的myid中的值改为2
11. 启动,在三个节点上分别执行命令zkServer.sh start
12. 检验,在三个节点上分别执行命令zkServer.sh status
zookeeper的shell操作
启动zookeeper:zkServer.sh start
进入zookeeper:zkCli.sh