zookeeper安装及使用
来源:互联网 发布:scx4321扫描软件 编辑:程序博客网 时间:2024/06/14 17:48
一、zookeeper下载安装
1、下载zookeeper-3.4.6安装包
cd/usr/developSoft/
wget http://www.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
2、解压到 /usr/local/ 目录下
tar -zxvf zookeeper-3.4.6.tar.gz -C /usr/local/
进入/usr/local/zookeeper-3.4.6/bin目录
./zkServer.sh start 启动服务
./zkServer.sh stop 停止服务
二、zookeeper独立模式(开发及测试)配置
1、进入/usr/local/zookeeper-3.4.6/conf中修改zoo.cfg 配置
cd /usr/local/zookeeper-3.4.6/conf
vi zoo.cfg
2、独立模式 可修改zoo.cfg配置如下:
# The number of milliseconds of each tick#ZK中的一个时间单元。ZK中所有时间都是以这个时间单元为基础,进行整数倍配置的tickTime=2000 # The number of ticks that the initial# synchronization phase can takeinitLimit=10# The number of ticks that can pass between# sending a request and getting anacknowledgementsyncLimit=5 #leader与learner(follower、obverser)直接心跳检测时间间隔# the directory where the snapshot isstored.# do not use /tmp for storage, /tmp here isjust# example sakes.#存储快照文件snapshot的目录。默认情况下,事务日志也会存储在这里。建议同时配置参数dataLogDir, 事务日志的写性能直接影响zk性能。dataDir=/usr/local/zookeeper-3.4.6/zk_data# dataLogDir事务日志输出目录。尽量给事务日志的输出配置单独的磁盘或是挂载点,这将极大的提升ZK性能dataLogDir=/usr/local/zookeeper-3.4.6/zk_dataLog# the port at which the clients willconnectclientPort=2181# the maximum number of client connections.# increase this if you need to handle moreclients#maxClientCnxns=60## Be sure to read the maintenance sectionof the# administrator guide before turning onautopurge.##http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain indataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to "0" to disable autopurge feature#autopurge.purgeInterval=1
cd bin
./zkServer.sh start-foreground #以前台程序启动服务
或者
./zkServer.sh start #以后台程序启动zkServer 服务器
./zkServer.shstop #停止zkServer服务器三、zookeeper集群模式(可用于生产)配置
准备三台机器,搭建3个节点的zookeeper集群。
(为简便起见,我在一台虚拟机中搭建了3个zookeeper实例并使用不同的端口,模拟三台物理机。实际生产环境下强烈建议使用不同物理机)
1、 下载安装zookeeper-3.4.6,参上不再赘述。
2、 在/usr/local解压了 zookeeper-3.4.6_1, zookeeper-3.4.6_2, zookeeper-3.4.6_3 作为Cluster中3个zookeeper节点实例。
修改每个zookeeper服务节点的zoo.cfg配置和myid文件,以第一个节点为例:
zookeeper-3.4.6_1/conf/zoo.cfg 如下
# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial# synchronization phase can takeinitLimit=10# The number of ticks that can pass between# sending a request and getting anacknowledgementsyncLimit=5# the directory where the snapshot isstored.# do not use /tmp for storage, /tmp here isjust# example sakes.dataDir=/usr/local/zookeeper-3.4.6_1/zk_datadataLogDir=/usr/local/zookeeper-3.4.6_1/zk_log # the port at which the clients willconnectclientPort=2182# the maximum number of client connections.# increase this if you need to handle moreclients#maxClientCnxns=60## Be sure to read the maintenance sectionof the# administrator guide before turning onautopurge.##http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain indataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to "0" to disable autopurge feature#autopurge.purgeInterval=1server.1=localhost:2881:3881server.2=localhost:2882:3882server.3=localhost:2883:3883
3 配置myId
在dataDir里会放置一个myid文件,里面就一个数字,用来唯一标识这个服务。这个id是很重要的,一定要保证整个集群中唯一。zookeeper会根据这个id来取出server.x上的配置。比如当前id为1,则对应着zoo.cfg里的server.1的配置。
echo 1 > /usr/local/zookeeper-3.4.6_1/zk_data/myid
第二个和第三个节点的配置(zoo.cfg 、myid文件)与第一个节点类似,不同的仅是dataDir dataLogDir myid文件内容。
第二个节点zoo.cfg配置
# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/usr/local/zookeeper-3.4.6_2/zk_datadataLogDir=/usr/local/zookeeper-3.4.6_2/zk_log# the port at which the clients will connectclientPort=2183# 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=1server.1=localhost:2881:3881server.2=localhost:2882:3882server.3=localhost:2883:3883
myid 文件
echo 2 > /usr/local/zookeeper-3.4.6_2/zk_data/myid
第三个节点zoo.cfg配置:
# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/usr/local/zookeeper-3.4.6_3/zk_datadataLogDir=/usr/local/zookeeper-3.4.6_3/zk_log# the port at which the clients will connectclientPort=2184# 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=1server.1=localhost:2881:3881server.2=localhost:2882:3882server.3=localhost:2883:3883
myid 文件
echo 3 > /usr/local/zookeeper-3.4.6_3/zk_data/myid
ok,依次启动3个几点
cd /usr/local/zookeeper-3.4.6_1/bin/
./zkServer.sh start
cd /usr/local/zookeeper-3.4.6_2/bin/
./zkServer.sh start
cd /usr/local/zookeeper-3.4.6_3/bin/
./zkServer.sh start
四、zookeeper 客户端命令
./zkCli.sh -server127.0.0.1:2181
显示根目录下文件
ls / //查看当前节点数据
ls2 / //查看当前节点数据并能看到更新次数等数据
创建文件, 并设置初始内容:
create /config"test" //创建一个新的节点并设置关联值
create /config“” //创建一个新的空节点
获取文件内容
get /brokers //获取节点内容
修改文件内容
set /zk"zkbak" //对 zk 所关联的字符串进行设置
删除文件
delete /brokers //删除节点
rmr /brokers //删除节点及子节点
- zookeeper安装及使用
- zookeeper安装及使用
- zookeeper的安装及php使用zookeeper
- 从Paxos到ZooKeeper-ZooKeeper安装及简单使用
- ZooKeeper伪分布式集群安装及使用
- ZooKeeper伪分布式集群安装及使用
- ZooKeeper伪分布式集群安装及使用
- ZooKeeper伪分布式集群安装及使用
- ZooKeeper伪分布式集群安装及使用
- ZooKeeper伪分布式集群安装及使用
- zookeeper的php扩展安装及使用
- ZooKeeper伪分布式集群安装及使用
- Zookeeper01 - Zookeeper简介及安装使用
- Zookeeper(二)安装及使用
- ZooKeeper伪分布式集群安装及使用
- [Zookeeper]介绍及Linux下安装使用
- ZooKeeper伪分布式集群安装及使用
- zookeeper的php扩展安装及使用
- 【CC2640R2】SIMPLELINK_CC2640R2_SDK 1.30.00.25发行说明
- 深入Collection之LinkedList
- 【敏捷开发每日一贴】敏捷实践Showcase的七宗罪
- 通达OA 开发工作流触发器碰到的一个特殊现象
- 学习Linux的决心书
- zookeeper安装及使用
- 去除红色字体
- lintcode(501)迷你推特
- adb操作命令详解及大全
- 欢迎使用CSDN-markdown编辑器
- 算法优化之一:求解子串最大和
- 本地端口模拟ajax异步请求php文件
- 科锐课堂笔记:2017/5/9 树、二叉树
- ARM day1 上位机linux配置