欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-05-27 16:38:14
...

本人使用的环境是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

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

第三步:修改配置文件
              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    //查看状态    

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

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