如何启动ZooKeeper(上)

启动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.

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值