Zookeeper(单机版)的安装&启动

安装

  • 官网:https://www.apache.org/dyn/closer.cgi/zookeeper/

  • 镜像:http://mirror.bit.edu.cn/apache/zookeeper/

  • 1.获取tar包

okamideMBP:zookeeper root# ll
total 73488
-rw-r--r--@ 1 okami  staff  37191810 11  3 01:05 zookeeper-3.4.13.tar.gz
  • 2.解压
okamideMBP:zookeeper root# tar -xzvf zookeeper-3.4.13.tar.gz 
  • 3.修改zoo.cfg

启动

  • 1.直接启动
# 启动服务
okamideMBP:zookeeper-3.4.13 root# zkServer start
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED

# 查看服务状态
okamideMBP:zookeeper-3.4.13 root# zkServer status
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Mode: standalone

# 停止服务
okamideMBP:zookeeper-3.4.13 root# zkServer stop
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Stopping zookeeper ... STOPPED
  • 2.指定配置文件
./zkServer.sh start zoo1.cfg
  • 3.开机启动
cd /etc/rc.d/init.d
touch zookeeper
chmod +x zookeeper
vi zookeeper
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
case $1in
  start) su root /usr/local/softwear/zookeeper/bin/zkServer.sh start;;
  stop) su root /usr/local/softwear/zookeeper/bin/zkServer.sh stop;;
  restart) su root /usr/local/softwear/zookeeper/bin/zkServer.sh restart;;
  status) su root /usr/local/softwear/zookeeper/bin/zkServer.sh status;;
  *) echo "require start|stop|restart|status" ;;
esac
  • 此时就可以使用service zookeeper start/stop来启动/停止服务
  • 添加到开机启动
chkconfig --add zookeeper
  • 检查是否成功添加到开机启动列表
chkconfig --list
  • 最后重启服务器生效

Zookeeper客户端 - zkCli

okamideMBP:zookeeper-3.4.13 root# zkCli 
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is enabled

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] 

配置文件说明

  • 文件名可以任意,不是非得改为zoo.cfg
  • tickTime: zookeeper中使用的基本时间单位, 毫秒
  • dataDir: 内存数据快照的保存目录;如果没有自定义Log也使用该目录
  • clientPort: 监听Cli连接的端口号

你可能感兴趣的:(Zookeeper(单机版)的安装&启动)