1、安裝(Linux,集群,3臺機(jī)器)
- java環(huán)境,安裝jdk,至少需要1.6版本
- 下載zookeeper,進(jìn)入zookeeper/conf目錄,拷貝zoo_sample.cfg,重命名為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.6/data
dataLogDir=/usr/local/zookeeper-3.4.6/dataLog
# 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
server.1=192.168.236.128:2888:3888
server.3=192.168.236.130:2888:3888
server.5=192.168.236.137:2888:3888
然后在dataDir對應(yīng)的目錄中,新建myid文件填入ID值,對應(yīng)如下圖server后面的數(shù)字
完了之后通過bin目錄下面的zkServer.sh腳本可以開啟和關(guān)閉服務(wù),通過ps命令可以驗證zk開啟成功,通過bin目錄下面的zkCli.sh腳本可以開啟zk的命令終端,然后使用zk命令操作
Java API操作