启动ZooKeeper
ZooKeeper服务的启动方式分为三种,即单机模式、伪分布式模式、分布式模式,这里针对三种模式均做逐一讲解。
Tips 调试过程建议尽量使用分布式模式,单机模式不推荐在生产环境下使用,伪分布式模式实质上是在一个进程内派生多个线程模拟分布式形态,由于操作系统的内部结构设计,容易造成一些问题,建议与其解决问题不如切换到分布式模式。生产环境下建议一定采用分布式模式,如果机器不够,推荐采用虚拟机方式。 |
(1). Module1 单机模式
采用单机模式,意味着只有一台机器或者一个节点,因此流程较为简单。首先,在conf目录下面可以通过自己创建zoo.cfg文件的方式完成ZooKeeper的配置,如清单1-7所示,ZooKeeper服务会读取该配置文件,具体的读取代码会在第四章介绍。
注意,ZooKeeper自带了zoo_sample.cfg文件,这个是配置文件的模板文件,可以打开看看具体的内容,也可以作为zoo.cfg的创建内容范例。
清单1-7 ZooKeeper配置文件
[root@localhost zookeeper-3.4.7]# cd conf
[root@localhost conf]# ls -rlt
total 12
-rw-rw-r--. 1 1000 1000 922 Nov 1022:32 zoo_sample.cfg
-rw-rw-r--. 1 1000 1000 2161 Nov 10 22:32 log4j.properties
-rw-rw-r--. 1 1000 1000 535 Nov 1022:32 configuration.xsl
[root@localhost conf]# cat zoo_sample.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/zookeeper
# 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.