时间同步及zookeeper安装
时间同步
第一步:安装ntp:yum -y install ntp
第二步:配置/etc/ntp.conf
# 这里修改为本机的IP地址
restrict 本机IP地址 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 profer
第三步:
启动ntp服务:service ntpd start
设置开机自启:chkconfig ntpd on
第四步:
查看是否设置成功:ntpq -p
查看是否同步成功:ntpstat
三台显示同步(synchronised)就同步成功了
zookeeper安装
第一步:上传压缩包并解压
第二步:配置conf/zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
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/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 #快照清理时间,每小时
# 这里配置三台结点,后面的端口是固定的
server.0=num01:2287:3387
server.1=num02:2287:3387
server.2=num03:2287:3387
该文件原名是zoo.sample.cfg,配置完成后改名为zoo.cfg
第三步:创建上面的dataDir文件夹,并在这个文件夹下面创建myid文件(没有后缀),里面写zoo.cfg文件中对应的server后面的数字即可
第四步:启动服务,运行bin目录下面的zkServer.sh:./zkServer.sh start
启动完成后:运行jps可以看到
执行命令./zkServer.sh status
:可以看到
Mode为foollower的是从结点,Leader是主结点。