Linux(centos)下ZooKeeper集群环境搭建

本文详细介绍在CentOS环境下,如何使用zookeeper-3.4.5版本搭建三节点集群,包括软件上传、环境变量配置、配置文件修改、文件夹创建、服务启动及客户端操作等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本人使用的环境是CentOS-6.4-x86_64-bin-DVD1.rar,zookeeper-3.4.5.tar.gz,jdk-7u67-linux-x64.tar.gz,apache-tomcat-7.0.29.tar.gz。三台机器ip:192.168.1.123,192.168.1.124,192.168.1.125。同时关闭三台虚拟机的防火墙:chkconfig iptables off(永久关闭防火墙)

第一步:上传zookeeper-3.4.5.tar.gz文件到/usr/local/software下,并解压到/usr/local
                  tar -zxvf zookeeper-3.4.5.tar.gz -C /usr/local/
                  重命名:mv zookeeper-3.4.5/* zookeeper/
第二部:配置环境变量 vim /etc/profile
                  export ZOOKEEPER_HOME=/usr/local/zookeeper
                  export PATH=.:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH

第三步:修改配置文件
              cd /usr/local/zookeeper/conf
              mv zoo_sample.cfg zoo.cfg   //重命名
              vim zoo.cfg
                  dataDir=/usr/local/zookeeper/data
                  //最后添加
                  server.0=192.168.1.123:2888:3888
                  server.1=192.168.1.124:2888:3888
                  server.2=192.168.1.125:2888:3888 

# 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
# the port at which the clients will connect
clientPort=2181
#
# 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
server.0=192.168.1.123:2888:3888
server.1=192.168.1.124:2888:3888
server.2=192.168.1.125:2888:3888

 第四步:创建文件夹
                   mkdir /usr/local/zookeeper/data
               在/usr/local/zookeeper/data下创建文件myid,并填写文件内容0或1或2
                   vim myid //在123上填写内容为0,在124上填写内容为1,在125上填写内容为2

第五步:启动zookeeper
            zkServer.sh start  //启动服务
            zkServer.sh status    //查看状态    

 

第六步:进入客户端
            zkCli.sh //进入客户端
            根据提示命令进行操作
            查找: ls / ls /zookeeper
            创建并赋值:create /ss shensheng
            获取:get /ss
            设值:set /ss wey
            可以看到集群数据的一致性
            rmr /path 递归删除节点
            delete /path/child 删除指定某个节点
            创建节点有两种类型:短暂(ephemeral)长久(persistent) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值