地表最强之Zookeeper的配置以及集群的时间同步配置

Zookeeper的简介

ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。

Zookeeper的安装和环境变量配置

tar -zxvf Zookeeper的安装包名 -C /opt
  • 配置环境变量vi /etc/profile在其中添加
export ZK_HOME=/opt/zookeeper-3.4.6
export PATH=$PATH:$ZK_HOME/bin
  • 使用source /etc/profile让配置文件生效

Zookeeper的配置

  • 输入cd /opt/zookeeper-3.4.6/conf/进入conf文件夹
  • 复制一份zoo_sample.cfg文件并命名为zoo.cfg并打开修改
[root@zcy01 conf]# cp zoo_sample.cfg  zoo.cfg
[root@zcy01 conf]# vi zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
#初始化最小进程数:50
initLimit=50
# 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=/opt/zookeeper/zookeeperdata
# 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=0
#
# 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
#配置三台以上的奇数台可用机器主机名或者ip,注如果不配集群不需要添加以下内容
server.1=zcy01:2888:3888
server.2=zcy02:2888:3888
server.3=zcy03:2888:3888
  • 创建上面设置的数据目录mkdir /opt/zookeeper/zookeeperdata检查ntp服务是否安装
  • 创建myid文件,输入对应机器主机名对应的server.后面的数字

配置Zookeeper的时间同步

  • 配置原因:如果Hadoop集群没有配置时间同步,会导致一些意想不到的错误,所以为了避免这些错误,需要配置时间同步
  • 先检查ntp服务是否安装rpm -qa | grep ntp,若有的话使用yum -y remove相关文件名命令卸载
  • 如果没有的话用yum -y install ntp来安装
  • 修改/etc目录下的ntp.conf文件vi /etc/ntp.conf
#当前节点IP地址
restrict 192.168.174.91 nomodify notrap nopeer noquery
#集群所在网段的网关(Gateway),子网掩码(Genmask)
restrict 192.168.174.1 mask 255.255.255.0 nomodify notrap
  • 选择一个机器当你的主机并输入
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 127.127.1.0
Fudge 127.127.1.0 stratum 10

注意这里要将server的内容全部注释掉

  • 其他不适主机的机器这里全部指向主机的IP
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.174.91
Fudge 192.168.174.91 stratum 10

  • 启动ntp服务service ntpd start并且设置开机自动启动chkconfig ntpd on
  • 输入ntpstat查看
#主机的运行结果
[root@zcy01 etc]# ntpstat
synchronised to local net (127.127.1.0) at stratum 6
   time correct to within 7948 ms
   polling server every 64 s
#副机的运行结果
[root@zcy02 hadoop]# ntpstat
unsynchronised
  time server re-starting
   polling server every 8 s

启动Zookeeper

  • 在/opt/zookeeper/bin目录下输入./zkServer.sh start
[root@zcy01 bin]# ./zkServer.sh start
JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
  • 输入jps验证
[root@zcy01 bin]# jps
22259 JobHistoryServer
23749 QuorumPeerMain
23769 Jps
17711 GetConf

如果有QuorumPeerMain说明启动成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值