Zookeeper单机版安装

x33g5p2x  于2021-03-14 发布在 Zookeeper  
字(2.2k)|赞(0)|评价(0)|浏览(323)

Java环境

Zookeeper安装需要依赖Java,因此确保Java环境已经准备就绪。

java -version

Zookeeper安装

  1. 下载Zookeeper压缩包
   http://zookeeper.apache.org/releases.html

zookeeper-3.4.14.tar.gz为例

  1. 解压Zookeeper压缩包
   tar -zxvf zookeeper-3.4.14.tar.gz -C /usr/local/
  1. 创建data目录
   cd /usr/local/zookeeper-3.4.14
   mkdir data

/usr/local/zookeeper-3.4.14/data

  1. 创建配置文件
   cp /usr/local/zookeeper-3.4.14/conf/zoo_sample.cfg /usr/local/zookeeper-3.4.14/conf/zoo.cfg

默认值:

tickTime=2000

initLimit=10

syncLimit=5

clientPort=2181

dataDir=/tmp/zookeeper

修改dataDir的值为第3步创建的目录data

   sed -i '/dataDir=/cdataDir=\/usr\/local\/zookeeper-3.4.14\/data' /usr/local/zookeeper-3.4.14/conf/zoo.cfg

Zookeeper启停[服务器]

/usr/local/zookeeper-3.4.14/bin/zkServer.sh start

ZooKeeper JMX enabled by default

Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

/usr/local/zookeeper-3.4.14/bin/zkServer.sh stop

ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

Zookeeper启动[客户端]

/usr/local/zookeeper-3.4.14/bin/zkCli.sh

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

Zookeeper集群版安装

  1. 修改zoo.cfg配置文件
   server.A=B:C:D

尾部新增如上配置。A为一个节点编号,如012。B为节点ip地址。C为Leader选举端口。D为数据同步端口。

   server.1=192.168.8.101:2888:3888
   server.2=192.168.8.102:2888:3888
   server.3=192.168.8.103:2888:3888
   echo "server.1=192.168.8.101:2888:3888" >>/usr/local/zookeeper-3.4.14/conf/zoo.cfg
   echo "server.2=192.168.8.102:2888:3888" >>/usr/local/zookeeper-3.4.14/conf/zoo.cfg
   echo "server.3=192.168.8.103:2888:3888" >>/usr/local/zookeeper-3.4.14/conf/zoo.cfg
  1. 创建myid文件

    在文件中键入A(节点编号),如012,保存至参数dataDir指定目录。

   echo "1" >/usr/local/zookeeper-3.4.14/data/myid    # 在第1台服务器上执行
   echo "2" >/usr/local/zookeeper-3.4.14/data/myid    # 在第2台服务器上执行
   echo "3" >/usr/local/zookeeper-3.4.14/data/myid    # 在第3台服务器上执行

开放端口

firewall-cmd --add-port=2888/tcp --permanent
firewall-cmd --add-port=3888/tcp --permanent
firewall-cmd --add-port=2181/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-port

查看状态

/usr/local/zookeeper-3.4.14/bin/zkServer.sh start    # 启动
/usr/local/zookeeper-3.4.14/bin/zkServer.sh status   # 查看状态
/usr/local/zookeeper-3.4.14/bin/zkServer.sh stop     # 停止
/usr/local/zookeeper-3.4.14/bin/zkServer.sh restart  # 重启

相关文章