[转载]ZooKeeper集群部署管理详细版

1. 约定:
a. ZooKeeper Server,[server1]的ip为192.168.1.201,[server2]的ip为192.168.1.202,[server3]的ip为192.168.1.203。
b. [zk_dir]表示ZooKeeper的根目录,假设为/home/user/zookeeper
c. [zk_data]表示ZooKeeper数据文件存放地址,假设为/home/user/zk_data
d. [zk_trlog]表示ZooKeeper的Transaction Log目录,假设为/home/user/zk_trlog
e. [zk_logs]表示ZooKeeper的一半log目录,假设为/home/user/zk_logs
2. 服务端环境要求:
a. Linux或者其他类UNIX系统(Windows及Mac OS只能作为开发环境,不能做生产环境)
b. JDK 1.6或更高
c. Server管理需要netcat或者telnet
3. 获得ZooKeeper发行版:
访问:http://hadoop.apache.org/zookeeper/releases.html,目前ZooKeeper的最新版本为3.3.1版本(2010年5月17日发行)
4. 修改配置文件:
因为ZooKeeper的配置文件设计目标是可供所有机器使用的通用配置文件,因此可以现在一台机器上写完,然后复制到其他server上。在[zk_dir]/conf下新建zoo.cfg文件,详细参数说明参见附录,这里给出一个配置文件的例子:
# BASIC SETTINGS
 
# The number of milliseconds of each tick
tickTime=2000
 
# the port at which the clients will connect
clientPort=2181
 
# the directory where the snapshot is stored.
dataDir=/home/user/zk_logs/zk_data
 
# the directory where the transaction log is stored
dataLogDir=/home/user/zk_logs/zk_trog
 
# BASIC SETTINGS END
 
##########################################################
 
# CLUSTER SETTINGS
 
# 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
 
# CLUSTER SERVER CONFIG
server.1=192.168.1.201:2888:3888
server.2=192.168.1.202:2888:3888
server.3=192.168.1.203:2888:3888
 
# CLUSTER SETTINGS END
其中的# CLUSTER SERVER CONFIG部分为集群的三台机器的ip
5. 为每台服务器设置id:
在[server1]的[zk_data]目录下新建myid文件,纯文本ASCII编码文件即可,内容为1,也就是配置文件中server.x中的x的值。其他两台机器上依此类推,也新建内容为自己id的myid文件。
6. 配置log文件信息:
ZooKeeper采用log4j记录日志,log4j.properties文件在[zk_dir]/conf目录下,编辑[zk_dir]/conf/log4j.properties文件,按需要配置,这里给出一个在文件里记录DEBUG, INFO, ERROR等级,并且文件每天重命名一次的例子:
#
# ZooKeeper Logging Configuration
#
 
log4j.rootLogger=INFO, DEBUG, ERROR
 
# DEBUG
log4j.appender.DEBUG=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DEBUG.Threshold=DEBUG
log4j.appender.DEBUG.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUG.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
log4j.appender.DEBUG.datePattern='.'yyyy-MM-dd'.log'
log4j.appender.DEBUG.append=true
log4j.appender.DEBUG.File=/home/user/zk_logs/zk_debug.log
 
# INFO
log4j.appender.INFO=org.apache.log4j.DailyRollingFileAppender
log4j.appender.INFO.Threshold=INFO
log4j.appender.INFO.layout=org.apache.log4j.PatternLayout
log4j.appender.INFO.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
log4j.appender.INFO.datePattern='.'yyyy-MM-dd'.log'
log4j.appender.INFO.append=true
log4j.appender.INFO.File=/home/user/zk_logs/zk_error.log
 
# ERROR
log4j.appender.ERROR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ERROR.Threshold=ERROR
log4j.appender.ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.ERROR.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
log4j.appender.ERROR.datePattern='.'yyyy-MM-dd'.log'
log4j.appender.ERROR.append=true
log4j.appender.ERROR.File=/home/user/zk_logs/zk_error.log
7. Server简单管理命令:
现在可以启动ZooKeeper服务器了:
# Server启动命令
$ [zk_dir]/bin/zkServer.sh start
# Server重启
$ [zk_dir]/bin/zkServer.sh restart
# Server停止
$ [zk_dir]/bin/zkServer.sh stop
# Server基本状态查看,需要netcat
$ [zk_dir]/bin/zkServer.sh status
8. ZooKeeper的管理命令:
需要使用telnet或者netcat连接到ZooKeeper Server的clientPort端口,命令均为4个字母,命令及功能如下:
conf
3.3.0新增: 打印server配置文件内容
cons
3.3.0新增:列出连接到本Server的Client的完整连接及Session信息。包括分组发送/接收信息,session id,操作延时,最后一个操作的执行等
crst
3.3.0新增: 重置所有连接/session
dump
Lists the outstanding sessions and ephemeral nodes. 只在leader server上有效。
envi
屏幕打印server的环境变量
ruok
测试server是否处于无错状态。 如果状态健康则返回”imok”,否则无任何结果。
A response of “imok” does not necessarily indicate that the server has joined the quorum, just that the server process is active and bound to the specified client port. Use “stat” for details on state wrt quorum and client connection information.
srst
Reset server statistics.
srvr
3.3.0新增: Lists full details for the server.
stat
Lists brief details for the server and connected clients.
wchs
3.3.0新增: Lists brief information on watches for the server.
wchc
3.3.0新增: Lists detailed information on watches for the server, by session. This outputs a list of sessions(connections) with associated watches (paths). Note, depending on the number of watches this operation may be expensive (ie impact server performance), use it carefully.
wchp
3.3.0新增: Lists detailed information on watches for the server, by path. This outputs a list of paths (znodes) with associated sessions. Note, depending on the number of watches this operation may be expensive (ie impact server performance), use it carefully.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值