Linux下zookeeper的搭建使用
apache版本地址:
cdh版本地址:
http://archive.cloudera.com/cdh5/cdh/5/
##推荐在cdh版本地址下,搜索 zookeeper-3.4.5-cdh5.13.1.tar.gz 进行下载;
##除非特别说明,否则以下所有操作均在3台机器一样执行;
1.zookeeper集群规划
机器ip | hostname | zookeeper | myid | user |
192.168.x.20 | hadoop01 | √ | 1 | hadoop |
192.168.x.21 | hadoop02 | √ | 2 | hadoop |
192.168.x.22 | hadoop03 | √ | 3 | hadoop |
2.前提准备
a.关闭防护墙
systemctl stop firewalld.service
systemctl disable firewalld.service
b.在root用户下新建普通用户hadoop
useradd hadoop
echo hadoop | passwd --stdin hadoop ##设置用户密码
su - hadoop ##切换到hadoop用户下,之后的所有操作均在hadoop下
c.添加jdk(请自行下载jdk1.8版本的tar.gz包并解压到/home/hadoop下重命名为jdk)
vi ~/.bashtc
source ~/.bashrc
java -version
3.搭建zookeeper
a.下载zookeeper
cd /home/hadoop
wget http://archive.cloudera.com/cdh5/cdh/5/zookeeper-3.4.5-cdh5.13.1.tar.gz
tar -xvf zookeeper-3.4.5-cdh5.13.1.tar.gz
mv zookeeper-3.4.5-cdh5.13.1.tar.gz zookeeper
b.配置环境变量
vi ~/.bashtc ##添加并修改为:
c.核心配置文件zoo.cfg修改配置
vi ./zookeeper/conf/zoo.cfg
dataDir=/home/haodoop/zookeeper/data
dataLogDir=/home/hadoop/zookeeper/datalog
# the port at which the clients will connect
clientPort=2181
tickTime=2000
initLimit=40
syncLimit=20
maxClientCnxns=10000
minSessionTimeout=4000
maxSessionTimeout=180000
autopurge.purgeInterval=24
autopurge.snapRetainCount=5
server.1=192.168.x.20:2888:3888
server.2=192.168.x.21:2888:3888
server.3=192.168.x.22:2888:3888
mkdir /home/hadoop/zookeeper/data
mkdir /home/hadoop/zookeeper/datalog
echo 1 > /home/hadoop/zookeeper/data/myid ##192.168.x.20节点
echo 2 > /home/hadoop/zookeeper/data/myid ##192.168.x.21节点
echo 3 > /home/hadoop/zookeeper/data/myid ##192.168.x.22节点
d.设置zk进程最大能使用的内存大小
vi ./zookeeper/conf/java.env
#!/bin/sh
export JAVA_HOME=$JAVA_HOME
# heap size MUST be modified according to cluster environment
export JVMFLAGS="-Xms8192m -Xmx8192m $JVMFLAGS"
e.配置zk滚动生成日志。
vi ~/.bashrc
export ZOO_LOG4J_PROP=INFO,ROLLINGFILE
vi zookeeper/conf/log4j.properties
# Copyright 2012 The Apache Software Foundation
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Define some default values that can be overridden by system properties
zookeeper.root.logger=INFO,ROLLINGFILE
zookeeper.console.threshold=INFO
zookeeper.log.dir=.
zookeeper.log.file=zookeeper-1.log
zookeeper.log.threshold=INFO
zookeeper.log.maxfilesize=2048MB
zookeeper.log.maxbackupindex=10
zookeeper.tracelog.dir=.
zookeeper.tracelog.file=zookeeper_trace.log
log4j.rootLogger=${zookeeper.root.logger}
#
# console
# Add "console" to rootlogger above if you want to use this
#
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
#
# Add ROLLINGFILE to rootLogger to get log file output
#
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
log4j.appender.ROLLINGFILE.MaxFileSize=${zookeeper.log.maxfilesize}
log4j.appender.ROLLINGFILE.MaxBackupIndex=${zookeeper.log.maxbackupindex}
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
#
# Add TRACEFILE to rootLogger to get log file output
# Log TRACE level and above messages to a log file
#
log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
log4j.appender.TRACEFILE.Threshold=TRACE
log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
### Notice we are including log4j's NDC here (%x)
log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n
4.启动并查看zookeeper
zkServer.sh start ##启动zk
zkServer.sh status ##查看zk运行状态
或者:
echo stat | nc 192.168.x.20 2181
5.zookeeper基本使用
下一篇: tar命令参数详解