Linux 安装Zookeeper
1.下载安装包
http://zookeeper.apache.org/releases.html选择版本下载
选择版本后,获取下载链接:3.4.14版本
cd /usr/local/
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar -zxvf zookeeper-3.4.14.tar.gz
# 更改为更短的包名
mv zookeeper-release-3.4.14/ zookeeper
2.修改配置
# 配置ZOOKEEPER_HOME
vim /etc/profile
# ZOOKEEPER_HOME=/usr/local/zookeeper
# export ZOOKEEPER_HOME
cd /usr/local/zookeeper/conf
# zoo.cfg为个人配置文件
cp zoo_sample.cfg zoo.cfg
# 创建data文件夹
mkdir /usr/local/zookeeper/data
# 修改zoo.cfg配置:dataDir=/usr/local/zookeeper/data
# 修改zookeeper启动端口:clientPort=2181,默认为2181
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=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
# 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.
#
# 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
# 集群模式取消以下注释 确保hosts文件内有slave-01等对应的ip地址 参考http://zookeeper.apache.org/doc/r3.4.14/zookeeperStarted.html#sc_RunningReplicatedZooKeeper
# initLimit=5
# server.1=slave-01:2888:3888
# server.2=slave-02:2888:3888
# server.3=slave-03:2888:3888
3.启动zookeeper
cd /usr/local/zookeeper/bin
./zkServer.sh start
4.查看状态
cd /usr/local/zookeeper/bin
# 查看状态
./zkServer.sh status
# 查看进程
ps -ef | grep zookeeper
5.zookeeper自启
cd /etc/init.d
# 编写脚本
vim zookeeper
# 脚本编写后启动
chkconfig --add zookeeper
脚本内容如下
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
ZK_PATH=/usr/local/zookeeper
export JAVA_HOME=jdk路径,自行决定
su root ${ZOOKEEPER_HOME}/bin/zkServer.sh "$1"
#或者
#case $1 in
# start) sh $ZK_PATH/bin/zkServer.sh start;;
# stop) sh $ZK_PATH/bin/zkServer.sh stop;;
# status) sh $ZK_PATH/bin/zkServer.sh status;;
# restart) sh $ZK_PATH/bin/zkServer.sh restart;;
# *) echo "require start|stop|status|restart" ;;
#esac
6.愉快使用
service zookeeper start
service zookeeper status
service zookeeper restart
service zookeeper stop
7.客户端操作节点
# 进入客户端,默认操作本机 更多参考./zkCli.sh -timeout 0 -r -server ip:port
/usr/local/zookeeper/bin/zkCli.sh
# 查看/ 下的节点
ls /
# 创建节点
create /com
# 创建带值节点
create /com/node1 hello
# 更新值
set /com/node1 hello.set
# 获取值
get /com/node1
# 删除节点
delete /com/node1
delete /com
# 退出
quit