前言
这里记录一下第一次搭建的过程,此次搭建的是3.4.6版本的,只是单IP多端口的实践,如果想要多个IP搭建的话,可以多安装几个虚拟机
环境
JDK1.6或者1.6以上
步骤
1.修改操作系统的/etc/hosts vi /etc/hosts
在文件中添加
192.168.126.129 edu-provider-01前面的IP是虚拟机的IP地址
2.下载zookeeper安装包
执行命令:
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
3.解压zookeeper到指定安装目录
$ tar –zxvf zookeeper-3.4.6.tar.gz –C /usr/local/zookeeper3.4.6/zookeeper-3.4.64.在安装目录下创建一下文件
$ cd /usr/local/zookeeper3.4.6/zookeeper-3.4.65.将/usr/local/zookeeper3.4.6/zookeeper-3.4.6/conf 目录下的 zoo_sample.cfg 文件拷贝一份,命名为为zoo.cfg
$mkdir data
$ mkdir logs
cp zoo_sample.cfg zoo.cfg6.修改zoo.cfg配置文件
# The number of milliseconds of each tick7.复制两份zoo.cfg
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=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/data
dataLogDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/logs
# 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=edu-provider-01:2888:3888
server.2=edu-provider-01:2889:3889
server.3=edu-provider-01:2890:3890
cp zoo.cfg zoo1.cfg将里面clientPort依次改为2182和2183
cp.zoo.cfg zoo2.cfg
dataDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/datazoo1.cfg的data改为data1,zoo2.cfg里的data改为data2
8. 在 dataDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/data 下创建 myid 文件,编辑 myid 文件
vi myid9.复制dataDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/data 下的data文件夹两份
1
cp -r /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data110.修改data1和data2中的myid文件,将data1中的值改为2,将data2的值改为3
cp -r /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data2
11.关闭防火墙CentOS7中关闭防火墙
$ systemctl disable firewalld.service至此环境就已经搭建完成了,接下来就是启动测试验证了
进入bin目录下挨个启动
$./zkServer.sh start zoo.cfg
$./zkServer.sh start zoo1.cfg
$./zkServer.sh start zoo2.cfg
查看状态
小结
虽然这些步骤看起来不难,真正在实践过程中才会知道你会遇到什么错误,也能够体会问题解决后的喜悦!