ZooKeeper安装与配置

下载

先去官网下一个ZooKeeper安装包。
我这里是zookeeper-3.4.13.tar

解压

我的用户是czq
首先在/home/czq/下新建一个ZooKeeper目录

mkdir zookeeper

然后进入安装包所在的目录

tar -zxvf zookeeper-3.4.13.tar.gz -C ~/zookeeper

配置

进入ZooKeeper目录可以看到一个conf,里面放的都是配置文件
其中有一个zoo_sample.cfg文件,就是样例配置文件,教你怎么配置。
你需要做的是把他名字改成zoo.cfg
这样框架才认识那个是配置文件。
为了以后还能阅读样例文件,我们这里直接复制并改名

cp zoo_sample.cfg zoo.cfg  #复制并改名
vim 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.快照的存储路径,请不要使用/tmp路径,这里只是样例,linux重启后/tmp里面的数据就会消失。注意这个目录需要事先建好
dataDir=/tmp/zookeeper
# the port at which the clients will connect设置ZooKeeper服务端口
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要在dataDir中保留的快照数
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
#最后需要设置集群配置,server.id=hostname:2888:3888。2888是通讯端口,3888是选举端口。
server.1=Ubuntu1:2888:3888

所以我们需要做的就是,修改dataDir,增加集群配置。其他就默认吧。
先建好目录~/zookeeper/data
设置dataDir=/home/czq/zookeeper/data
设置
server.1=Ubuntu1:2888:3888
server.2=Ubuntu2:2888:3888

然后你需要在每台主机的dataDir目录(也就是我的~/zookeeper/data)下建一个叫做myid的文件,告诉ZooKeeper当前主机的id,id和zoo.cfg的要一样。

cd ~/zookeeper/data
echo 1 > myid

启动服务

启动的脚本存放在ZooKeeper的bin目录下。
开启超过一半的ZooKeeper主机,就开启服务了。

./zkServer.sh start

可以通过status查看状态

./zkServer.sh status

zkCli.sh可以进入ZooKeeper客户端

./zkCli.sh
#使用help命令查看帮助,ZooKeeper里面的都比较简单。

配置环境变量

如果嫌每次都要进文件夹麻烦,可以配置一下环境变量,前面有一些java和hadoop的路径,大家不要照搬。

export ZOOKEEPER_HOME=/home/czq/zookeeper/zookeeper-3.4.13
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin

你可能感兴趣的:(Hadoop)