①创建安装目录
mkdir -p /usr/local/zookeeper
②将tar包解决到安装目录下
tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz -C /usr/local/zookeeper/
③创建数据目录data,日志目录log
mkdir -p /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/data mkdir -p /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/log
④修改配置文件(conf目录),默认启动配置文件为zoo.cfg
(复制zoo_sample.cfg一份修改名称为zoo.cfg)
# 进入配置文件 cd /user/local/zookeeper/apache-zookeeper-3.6.1-bin/conf/ # zookeeper 启动默认加载名为 zoo.cfg的配置文件,所以复制一份命名为 zoo.cfg cp zoo_sample.cfg zoo.cfg # 修改配置文件 vim zoo.cfg
⑤配置dataDir和dataLogdir
# 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/apache-zookeeper-3.6.1-bin/data dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.6.1-bin/log # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # 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 ## Metrics Providers
在bin目录下启动zookeeper
./zkServer.sh start
可以直接通过bin目录下的zkcli.sh进行连接
./zkCli.sh
下图为连接成功
ls /
创建解压目录
①先创建一个目录
mkdir -p /usr/local/zookeeper/zk1
②将文件解压到该目录
tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz -C /usr/local/zookeeper/zk1/
③创建data目录和log目录,data目录下添加myid文件,myid中只写一个1就行
mkdir /usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/data
mkdir /usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/log
cd /usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/data
vim myid
复制zoo_sample.cfg,并将文件重命名为zoo.cfg
cp zoo_sample.cfg zoo.cfg
修改zk1配置的zoo.cfg
vim zoo.cfg
dataDir=/usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/data dataLogDir=/usr/local/zookeeper/zk1/apache-zookeeper-3.6.1-bin/log
# 集群配置 # server.1中的1是myid文件中的内容,2888,2889,2890用于集群内部通信,3888,3889,3890用于选择leader server.1=192.168.152.100:2888:3888 server.2=192.168.152.100:2889:3889 server.3=192.168.152.100:2890:3890
将zk1文件夹复制两份为zk2/zk3
cd /usr/local/zookeeper/
cp -Rf zk1/ zk2
cp -Rf zk1/ zk3
修改zk2的配置文件zoo.cfg
dataDir=/usr/local/zookeeper/zk2/apache-zookeeper-3.6.1-bin/data dataLogDir=/usr/local/zookeeper/zk2/apache-zookeeper-3.6.1-bin/log clientPort=2182
修改zk2中data目录下的myid文件 —把1改成2
cd /usr/local/zookeeper/zk2/apache-zookeeper-3.6.1-bin/data
vim myid
把1改成2 (同理在zk3中把myid改成3)
注意:这里的myid和配置文件中有关
如果没有改可能会出现以下错误
修改zk3的配置文件zoo.cfg(和zk2相似)
dataDir=/usr/local/zookeeper/zk3/apache-zookeeper-3.6.1-bin/data dataLogDir=/usr/local/zookeeper/zk3/apache-zookeeper-3.6.1-bin/log clientPort=2183
启动
注意:这里需要把三台**全部启动,再查看状态**
原因:涉及到Leader(Master)选举的问题
cd /usr/local/zookeeper/ zk1/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start zk2/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start zk3/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start
查看状态
cd /usr/local/zookeeper/ zk1/apache-zookeeper-3.6.1-bin/bin/zkServer.sh status zk2/apache-zookeeper-3.6.1-bin/bin/zkServer.sh status zk3/apache-zookeeper-3.6.1-bin/bin/zkServer.sh status