查看Zookeeper版本:

yum install -y nc

echo stat |nc 127.0.0.1 2181


安装Zookeeper需要jdk支持

1.安装jdk

mkdir /data1/software

mkdir /data1/zookeeper/data -p

mkdir /data1/zookeeper/log

mkdir /usr/local/java

cd /data1/software

tar -zxvf jdk-8u73-linux-x64.tar.gz -C /usr/local

mv /usr/local/jdk1.8.0_73 /usr/local/java

vim /etc/profile:


export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
#export KE_HOME=/data1/src/kafka-eagle-1.0.4
#export PATH=$PATH:$KE_HOME/bin


source /etc/profile

java -version #验证java是否安装成功

2.安装Zookeeper:

tar -zxvf zookeeper-3.4.8.tar.gz -C /usr/local
mv /usr/local/zookeeper-3.4.8 /usr/local/zookeeper
cd /usr/local/zookeeper/conf/
cp zoo_sample.cfg zoo.cfg

vim zoo.cfg 


tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data1/zookeeper/data
dataLogDir=/data1/zookeeper/log
clientPort=2181
autopurge.snapRetainCount=3
autopurge.purgeInterval=1

#配置集群
server.1=10.10.201.82:2881:3881
server.2=10.10.201.83:2881:3881
server.3=10.10.201.84:2881:3881


echo 1 > /data1/zookeeper/data/myid  #每台机器上执行

echo 2 > /data1/zookeeper/data/myid #每台机器上执行

echo 3 > /data1/zookeeper/data/myid #每台机器上执行

启动Zookeeper服务:

/usr/local/zookeeper/bin/zkServer.sh start


 3.设置Zookeeper开机自启动

在/etc/init.d/下新建文件 zookeeper,内容如下:

CentOS安装jdk和Zookeeper_jarCentOS安装jdk和Zookeeper_jdk_02


#!/bin/bash
#chkconfig: 345 20 90
#description: zookeeper
#processname: zookeeper

# Source java env
for commandline in $(cat /etc/profile.d/java.sh);do
export ${commandline}
done

# Source function library.

# Source networking configuration.

# Check networking is up.
[ "$NETWORKING" = "no" ] && exit 0

RETVAL=0
PROG=zookeeper
ZK_SERVER="/usr/local/zookeeper/bin/zkServer.sh"
ZK_LOGDIR="/data1/zookeeper/log"
LOCKFILE="${ZK_LOGDIR}/zookeeper.lock"
PID_FILE="/data1/zookeeper/data/zookeeper_server.pid"

start() {
echo -n $"Starting $PROG: "

cd ${ZK_LOGDIR} && $ZK_SERVER start

RETVAL=$?
if [ $RETVAL -eq 0 ]; then
success;echo;touch $LOCKFILE
else
failure;echo
fi
return $RETVAL
}

stop() {
echo -n $"Stopping $PROG: "

if [ -f $PID_FILE ] ;then
read PID < "$PID_FILE"
else
failure;echo;
echo -n $"$PID_FILE not found.";failure;echo
return 1;
fi

if checkpid $PID; then
cd ${ZK_LOGDIR} && $ZK_SERVER stop
RETVAL=$?
if [ $RETVAL -eq 0 ] ;then
success;echo
echo -n "Waiting for ${PROG} to shutdown .."
while checkpid $PID;do
echo -n "."
sleep 1;
done
success;echo;rm -f $LOCKFILE
else
failure;echo
fi
else
echo -n $"${PROG} is dead and $PID_FILE exists.";failure;echo
RETVAL=7
fi
return $RETVAL
}


status() {
cd ${ZK_LOGDIR} && $ZK_SERVER status
}

case $1 in
start)
start
;;

stop)
stop
;;

status)
status
;;

restart)
stop
start
;;

*)
echo "require start|stop|status|restart"
;;
esac

View Code

chmod a+x zookeeper

chkconfig --add zookeeper

chkconfig zookeeper on

在/etc/profile.d下新建文件java.sh,内容如下;


JAVA_HOME=/usr/local/java
JRE_HOME=/usr/local/java/jre
JAVA_BIN=/usr/local/java/bin
CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_BIN:$PATH


service zookeeper start|stop|restart