参考尚硅谷07_尚硅谷_zk_本地_安装_哔哩哔哩_bilibili,感谢尚硅谷!
安装
以Cent OS 7(CentOS-7-x86_64-DVD-2009)和ZooKeeper-3.5.7(https://wwrj.lanzoue.com/i7fqz0tfeula 密码是dqp9)为例。
我以集群部署为例,目前有三台主机,分别为hadoop1、hadoop2和hadoop3,他们的ip地址分别为(192.168.117.128,192.168.117.129,192.168.117.130)。
-
安装JDK(各种方式都可以),我这里采用yum安装
使用yum命令
yum install -y java-1.8.0-openjdk.x86_64
. -
将ZooKeeper-3.5.7压缩包拷贝到
/opt/software
下 -
使用解压缩命令,将这个压缩包解压到
/opt/module
下,tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module
-
因为原ZooKeeper文件名过长 ,所以进行重命名操作
mv apache-zookeeper-3.5.7-bin/ zookeeper-3.5.7
,此步骤也可以省略。 -
进入zookeeper-3.5.7文件夹,新建一个
zkData
目录,用于存储ZooKeeper的信息,即/opt/module/zookeeper-3.5.7/zkData
.- 在该目录下创建一个文件
myid
,随后向myid
写入编号,该编号唯一标识集群中的ZooKeeper,这里,hadoop1,2,3的myid
分别为1,2,3
- 在该目录下创建一个文件
-
进入
/opt/module.zookeeper-3.5.7/conf
目录下,使用命令mv zoo_sample.cfg zoo.cfg
,将sample的配置文件改成正式的 -
将
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=/opt/module/zookeeper-3.5.7/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.1=192.168.117.128:2888:3888 server.2=192.168.117.129:2888:3888 server.3=192.168.117.130:2888:3888
-
其中server.1标识的就是
myid
为1的ZooKeeper服务器的地址和具体端口。
三台服务器的配置都是一样的,除了/opt/module/zookeeper-3.5.7/zkData
文件夹下myid
文件的内容不一致。例如hadoop1服务器下的myid
是:
启动集群
分别到hadoop1,2,3中,ZooKeeper的bin目录下,使用zkServer.sh start
即可。