以下是zookeeper在一臺虛擬機上的僞集羣配置:(zoo.cfg配置文件)
[root@localhost conf]# more 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=/tmp/zookeeper4 #某個zookeeper集羣數據文件的目錄,如果該zookeeper節點在最先面cluster的配置爲server.4,則需要在該目錄下創建一個myid文件,裏面 #的值爲4,當然每個zookeeper節點都必須要在myid文件中寫入對應的id
# the port at which the clients will connect
clientPort=2184 #既然是在同一臺機器上就需要配置集羣的幾個zookeeper實例不要共用同一個端口
# 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
#cluster
server.1=localhost:2886:3886 #這是具體的幾個zookeeper節點集羣的通信配置
server.2=localhost:2887:3887
server.3=localhost:2888:3888
server.4=localhost:2889:3889
至此,上述四個zookeeper節點集羣配置完成,通過zookeeper自帶的客戶端(位於{Zookeeper_HOme}/bin/zkCli.sh),例如:./bin/zkCli.sh -server 127.0.0.1:2184連接相應的zookeeper服務器,
用 create /zk_test
則集羣環境中的所有zookeeper節點在客戶端連入之後都能同過命令: ls / 看到在之前的zookeeper節點下創建的 /zk_test 節點