Zookeeper相关配置
在上一小节中,我们已经把Zookeeper的安装包成功解压至/export/servers目录下。接下来,我们开始配置Zookeeper集群。
1.修改Zookeeper的配置文件
首先,进入Zookeeper解压目录下的conf目录,复制配置文件zoo_sample.cfg并重命名为zoo.cfg,具体命令如下:
$ cp zoo_sample.cfg zoo.cfg
其次,修改配置文件zoo.cfg,分别设置dataDir目录,配置服务器编号与主机名映射关系,设置与主机连接的心跳端口和选举端口,具体配置内容如下:
# 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=/export/data/zookeeper/zkdata**
\# 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
**#** **配置ZK集群的服务器编号以及对应的主机名、通信端口号(心跳端口号)、选举端口号**
**server.1=hadoop01:2888:3888**
**server.2=hadoop02:2888:3888**
**server.3=hadoop03:2888:3888**
2.创建myid文件
首先,根据配置文件zoo.cfg中设置的dataDir目录,创建zkdata文件夹,具体命令如下:
$ mkdir -p /export/data/zookeeper/zkdata
其次,在zkdata文件夹下创建myid文件,该文件里面的内容就是服务器编号(hadoop01服务器对应编号1,hadoop02服务器对应编号2,hadoop03服务器对应编号3),具体命令如下:
$ cd /export/data/zookeeper/zkdata
$ echo 1 > myid
3.配置环境变量
Linux系统目录/etc下的文件profile里面的内容都是与Linux环境变量相关的。所以,我们一般配置环境变量都是在profile文件里面。执行命令vi /etc/profile对profile文件进行修改,添加Zookeeper的环境变量,具体命令如下:
export ZK_HOME=/export/servers/zookeeper-3.4.10
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZK_HOME/bin
4.分发Zookeeper相关文件至其他服务器
首先,将Zookeeper安装目录分发至hadoop02、hadoop03服务器上。具体命令如下:
$ scp -r /export/servers/zookeeper-3.4.10/ hadoop02:/export/servers/
$ scp -r /export/servers/zookeeper-3.4.10/ hadoop03:/export/servers/
其次,将myid文件分发至hadoop02、hadoop03服务器上,并且修改myid的文件内容,依次对应服务器号进行设置,分别为2、3。具体命令如下:
$ scp -r /export/data/zookeeper/ hadoop02:/export/data/
$ scp -r /export/data/zookeeper/ hadoop03:/export/data/
最后,将profile文件也分发至hadoop02、hadoop03服务器上。具体命令如下:
$ scp /etc/profile hadoop02:/etc/profile
$ scp /etc/profile hadoop03:/etc/profile
5.环境变量生效
分别在hadoop01、hadoop02、hadoop03服务器上刷新profile配置文件,使环境变量生效。具体命令如下:
$ source /etc/profile