4. 设置zookeeper启动参数 1. 准备工作 这里将zookeeper解压在zookeeper下 新建两个文件夹,后面用 mkdir data mkdir dataLog cd zookeeper-3.4.6/conf/ 可以看到里面有三个文件,我们将zoo_sample.cfg进行复制。 cp zoo_sample.cfg zoo.cfg,注意名字需要一致,zookeeper会自动解析zoo.cfg文件 2. vim zoo.cfg
#tickTime是时间的单位,这里的意思是指后面的时间单位为2s tickTime=2000 # The number of ticks that the initial # synchronization phase can take #启动时间最长20s initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement #响应最长时间10s syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. #指向上面新建的data文件夹的路径,存放zk数据 dataDir=/home/xieyw/zookeeper/data #指向上面新建的dataLog文件夹的路径,存放zk日志 dataLogDir=/home/xieyw/zookeeper/dataLog # 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 #配置zk集群的主机路径。1表示主机的唯一标识,要求唯一,可以随便设置 server.1=vm01:2888:3888 server.2=vm02:2888:3888 server.3=vm03:2888:3888回到zookeeper下的data目录,新建myid文件,并赋值为2(当前主机为vm02),myid的值需要和zoo.cfg里面配置的zk集群主机的server后面的值对应,zk通过扫描dataDir路径下的myid文件来确定当前主机的身份 5. 关闭防火墙 CentOS的防火墙不是iptables,而是firewall,所以需要对防火墙进行关闭需要执行以下命令: systemctl stop firewalld.service 关闭开机启动防火墙: systemctl disable firewalld.service 6. 启动zk集群 在bin下,执行./zkServer.sh start启动zk 查看状态./zkServer.sh status 注意这里三台机器zk的启动需要在20s(initLimit=10)内完成
complete!