1、环境CentOS6.8 + jdk1.8.0_151(jdk安装请参考CentOS 搭建JDK环境 )
2、下载zookeeper-3.4.11.tar.gz,下载地址:https://www.apache.org/dyn/closer.cgi/zookeeper/
3、安装
3.1、上传zookeeper-3.4.11.tar.gz至/usr/dev/zookeeper安装目录下
3.2、在zookeeper创建三个子目录zookeeper1、zookeeper2、zookeeper3
3.3、将zookeeper-3.4.11.tar.gz解压至zookeeper目录
tar -zxvf zookeeper-3.4.11.tar.gz
3.4、将解压后的目录拷贝至zookeeper1、zookeeper2、zookeeper3
4、修改zookeeper配置文件
4.1、修改zookeeper1中的zoo.cfg文件,zookeeper2、zookeeper3参考zookeeper1进行修改
cd /usr/dev/zookeeper/zookeeper1/zookeeper-3.4.11/conf cp zoo_simple.cfg zoo.cfg vi 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=/usr/dev/zookeeper/zookeeper1/zookeeper-3.4.11/data dataLogDir=/usr/dev/zookeeper/zookeeper1/zookeeper-3.4.11/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=192.168.117.128:2881:3881 server.2=192.168.117.128:2882:3882 server.3=192.168.117.128:2883:3883
说明:
initLimit=10: 对于从节点最初连接到主节点时的超时时间,单位为tick值的倍数。
syncLimit=5:对于主节点与从节点进行同步操作时的超时时间,单位为tick值的倍数。
dataDir: 用于配置内存数据库保存的模糊快照的目录。即刚刚创建的data文件夹就是在此目录中。文件信息都存放在data目录下。
clientPort=2181: 表示客户端所连接的服务器所监听的端口号,默认是2181。即zookeeper对外提供访问的端口号。
server.1=192.168.117.128:2881:3881
server.2=192.168.117.128:2882:3882
server.3=192.168.117.128:2883:3883
server.X=A:B:C X-代表服务器编号 A-代表ip B和C-代表端口,这个端口用来系统之间通信
同理配置
4.2、设置zookeeper1中的myid,zookeeper2、zookeeper3参考zookeeper1进行修改
在/usr/dev/zookeeper/zookeeper1/zookeeper-3.4.11/data目录下创建myid文件,myid的内容为server.X中X的值,即zookeeper1下的myid内容为1
cd /usr/dev/zookeeper/zookeeper1/zookeeper-3.4.11/data vi myid
5、启动zookeeper,/zookeeper-3.4.11/bin目录下
zkServer.sh start (启动)
zkServer.sh restart (重启)
zkServer.sh status (查看状态)
zkServer.sh stop (关闭)
zkServer.sh start-foreground (以打印日志方式启动)
注意:启动前请先配置防火墙,将配置文件中的端口设置为允许访问
cd /usr/dev/zookeeper/ ./zookeeper1/zookeeper-3.4.11/bin/zkServer.sh start ./zookeeper2/zookeeper-3.4.11/bin/zkServer.sh start ./zookeeper3/zookeeper-3.4.11/bin/zkServer.sh start