Linux下的ZooKeeper安装(单机环境和集群以及启动时出现的异常)

一、下载最新的稳定版并zookeeper-3.4.5.tar.gz,放到/home/文件夹下面,解压

#tar -zxvf zookeeper-3.4.5.tar.gz

二、生成配置

conf/目录下有个zoo_sample.cfg,是样板配置文件, 复制一份成zoo.cfg,里面有两个比较重要的配置:

dataDir=/var/lib/zookeeper # 数据存放位置,可根据需要修改

clientPort=2181 # 服务监听端口,可根据需要修改

# cd zookeeper-3.4.5

# cp conf/zoo_sample.cfg conf/zoo.cfg

# vi conf/zoo.cfg

# vi conf/zoo.cfg

# 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=/home/zookeeper-3.4.5/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

"conf/zoo.cfg" 25L, 820C written

# mkdir data(新建文件夹)

三、启动、关闭服务,查看服务状态

# ./bin/zkServer.sh start(启动服务)

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

# ./bin/zkServer.sh status(查看服务状态)

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Mode: standalone

# ./bin/zkServer.sh stop(停止服务)

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Stopping zookeeper ... STOPPED\

#./bin/zkCli.sh -server(连接服务)


      2zookeeper集群安装

一、准备3台linux机器,IP如下

192.168.153.132

192.168.153.131

192.168.153.130

二、分别拷贝zookeeper-3.4.5.tar.gz到每台机器上,进行如下设置:

修改zoo.cfg文件,参考单机版

[[email protected]]# vi conf/zoo.cfg

tickTime=2000

initLimit=10

syncLimit=5

dataDir=/usr/zookeeper-3.4.6/data

clientPort=2181

dataLogDir=/usr/zookeeper-3.4.6/logs

server.1=192.168.153.132:2888:5000  

server.2=192.168.153.131:2888:5000

server.3=192.168.153.130:2888:5000

#注意(2888  和  5000 随意写 不合2181重复就行 )

每个当前节点要把自己的IP地址设置为0.0.0.0

  假如 当前节点 为 192.168.153.132

server.1=0.0.0.0:2888:5000  

server.2=192.168.153.131: 2888:5000

server.3=192.168.153.130: 2888:5000

  以此类推

三、设置myid(/在 usr/zookepper-3.4.6/data 创建文件  touch  myid  )

设置192.168.153.132:上data文件夹下myid内容为1;

设置192.168.153.131:上data文件夹下myid内容为2;

设置192.168.153.130:上data文件夹下myid内容为3;

#注意(myid内容要和server.x的值保持一致,) 



四、启动集群

分别在三台机器上启动zookeeper:

[root@zyz zookeeper-3.4.6]# ./bin/zkCli.sh  start

如果启动异常 还可以以 如下方式启动zookepper服务

[root@zyz zookeeper-3.4.6]# ./bin/zkServer.sh start-foreground


连接zookepper 服务

[root@zyz zookeeper-3.4.6]# ./bin/zkCli.sh -server     192.168.153.128:2181




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章