CentOS-7下ZooKeeper的过程
1.简要介绍
ZooKeeper诞生于Yahoo,后转入Apache孵化,最终孵化成Apache的顶级项目,是Hadoop和Hbase的重要组件。ZooKeeper是一种集中式服务,用于维护配置信息、命名、提供分布式同步和提供组服务。所有这些类型的服务都以分布式应用程序的某种形式使用。由于实现上述需求都需要做很多工作来修复不可避免的错误和竞争条件。因此,这些服务的实现变得非常困难,即使这些服务顺利完成,管理和运维的成本也非常高,所以zookeeper以救世主的身份出现,解决上述技术难题,降低了分布式应用程序的开发难度和工作量,让程序员专注于分布式架构的设计
2.ZooKeeper的安装
1.实验物料
三台CentOS7的虚拟机,JDK1.8,zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
2.ZooKeeper安装过程
1.首先安装JDK,尽量选用1.8及以上的JDK,关于JDK的安装,这里不再赘述,不会的同学可以看我上一篇文章《CentOS-7下安装JDK1.8的过程》;
2.下载Zookeeper的软件安装包,这里我选zookeeper-3.4.14.tar.gz;
wget https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
3.解压缩
tar xf zookeeper-3.4.14.tar.gz
4.移动到opt下
mv zookeeper-3.4.14 /opt/
5.创建配置文件
在conf下,创建zoo.cfg。我直接采用复制里面样例的方式创建:
cp zoo_sample.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=/var/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
server.1=192.168.15.20:2888:3888
server.2=192.168.15.21:2888:3888
server.3=192.168.15.22:2888:3888
6.创建myid
在/var/zookeeper目录下,创建myid文件,里面填写数字1
vi /var/zookeeper/myid
7.配置环境变量
vi /etc/profile
配置内容如下:
export ZOOKEEPER_HOME=/opt/zookeeper-3.4.14
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin/$JAVA_HOME:$PATH:$ZOOKEEPER_HOME/bin
8.刷新配置文件
source /etc/profile
9.文件同步
将在192.168.15.20中安装的文件,同步到其他两台机器上:
scp -r ./opt/zookeeper-3.4.14/ root@192.168.15.21:/opt/zookeeper-3.4.14/
scp -r ./opt/zookeeper-3.4.14/ root@192.168.15.22:/opt/zookeeper-3.4.14/
然后在192.168.15.21上也创建/var/zookeeper目录和myid文件,里面填写数字2;
然后在192.168.15.22上也创建/var/zookeeper目录和myid文件,里面填写数字3;
10.启动
在三台机器上都执行以下命令:
zkServer.sh start
这样就完成了安装。