Ubuntu 安装zookeeper

时间:2023-03-08 16:13:28

下载zookeeper   Zookeeper下载

下载以后将文件迁移到/home/Hadoop/文件夹下面

hongdada@ubuntu:~/Downloads$ sudo mv zookeeper-3.4.9.tar.gz /home/Hadoop

tar -zxvf解压

hongdada@ubuntu:/home/Hadoop$ sudo tar -zxvf zookeeper-3.4.9.tar.gz

将文件夹zookeeper-3.4.9改成zookeeper

hongdada@ubuntu:/home/Hadoop$ sudo mv zookeeper-3.4.9 zookeeper

解压以后conf文件夹中创建zoo_sample.cfg的副本zoo.cfg

hongdada@ubuntu:/home/Hadoop$ cd zookeeper
hongdada@ubuntu:/home/Hadoop/zookeeper$ cd conf
hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ mp zoo_sample.cfg zoo_cfg
mp:未找到命令
hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ cp zoo_sample.cfg zoo.cfg
cp: 无法创建普通文件'zoo.cfg': 权限不够
hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ sudo cp zoo_sample.cfg zoo.cfg
hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ sudo gedit zoo.cfg

原始的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=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# 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=1

修改为:

# 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/Hadoop/zookeeper/data # 数据持久化路径
dataLogDir=/home/Hadoop/zookeeper/log #日志保存路径
server.1=192.168.1.203:2888:3888 # the port at which the clients will connect
clientPort=2181
# 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=1

说明:

syncLimit=5 # Leader与Follower之间的最大响应时间单位,响应超过syncLimit*tickTime,Leader认为Follwer死掉,从服务器列表中删除Follwer。
initLimit=10 # 投票选举新leader的初始化时间。
tickTime=2000 # Zookeeper服务器心跳时间,单位毫秒
clientPort=2181 # 连接端口
dataDir=/home/Hadoop/zookeeper/data # 数据持久化路径
dataLogDir=/home/Hadoop/zookeeper/log # 日志保存路径
server.1=10.10.100.10:2888:3888

设置环境变量:

hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ export ZOOKEEPER_HOME=/home/Hadoop/zookeeper
hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ export PATH=$PATH:$ZOOKEEPER_HOME/bin

启动zookeeper:

hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ cd .
hongdada@ubuntu:/home/Hadoop/zookeeper/conf$ cd ../
hongdada@ubuntu:/home/Hadoop/zookeeper$ cd bin
hongdada@ubuntu:/home/Hadoop/zookeeper/bin$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/Hadoop/zookeeper/bin/../conf/zoo.cfg
mkdir: 无法创建目录"/home/Hadoop/zookeeper/data # 数据持久化路径": 权限不够
Starting zookeeper ... /home/Hadoop/zookeeper/bin/zkServer.sh: 行 140: ./zookeeper.out: 权限不够
/home/Hadoop/zookeeper/bin/zkServer.sh: 行 149: /home/Hadoop/zookeeper/data # 数据持久化路径/zookeeper_server.pid: 没有那个文件或目录
FAILED TO WRITE PID
hongdada@ubuntu:/home/Hadoop/zookeeper/bin$ sudo zkServer.sh start
[sudo] hongdada 的密码:
sudo: zkServer.sh:找不到命令
hongdada@ubuntu:/home/Hadoop/zookeeper/bin$ sudo ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/Hadoop/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

启动是./zkServer.sh start

http://jingyan.baidu.com/article/456c463b60bd380a5931446f.html

http://blog.****.net/cruise_h/article/details/19046357