ZooKeeper运维相关

集群

1、配置zoo.cfg文件,通过git管理zoo.cfg配置文件

2、在dataDir所配置的目录下创建myid文件,里面记录上当前机器编号

3、启动zk:

%ZK_HOME%/bin/zkServer.sh start

4、验证服务器:

1
2
telnet 127.0.0.1 2181
stat

单机

特殊的集群:只有一台机器的集群。

stat输出区别:
Mode: standalone/leader

伪集群模式

集群所有的机器都在一台机器上,但是还是以集群的特性来对外提供服务。配置基本一样,只不过服务器的IP都是同一个IP,但是使用不同的端口号。

zoo.cfg配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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/zookeeper
dataDir=/usr/local/zookeeper/zookeeper-3.4.8/data
# the port at which the clients will connect
clientPort=2181
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
# 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

在同一台计算机创建几个目录,分别解压zookeeper,并把上面的zoo.cfg文件替换配置文件,注意,每个配置文件的clientPort需要不一样;

然后通过telnet或者客户端连接:

./zkCli.sh –server 127.0.0.1:2181

接下来就可以通过客户端连接编程实现各种炫酷的功能啦.