参考与:https://blog.csdn.net/pucao_cug/article/details/71240246
安装环境centos7.4,zookeeper版本是3.4.12,JDK我事先已经安装好了
1.下载zookeeper:wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12.tar.gz -P /usr/soft
2.解压到/opt目录下 tar -xzvf zookeeper-3.4.12.tar.gz -C /opt
3.cd /opt & mv zookeeper-3.4.12 zookeeper
4.cd zookeeper 进入zookeeper目录
5.cp conf/zoo_sample.cfg conf/zoo.cfg copy配置文件
6.创建日志和data目录 mkdri -p /opt/zookeeper/{logs,data}
7.这边有三台机器部署的集群,
echo "1" > /opt/zookeeper/data/myid
8.配置环境变量
vim /etc/profile 进入编辑页面
export ZOOKEEPER_HOME=/opt/zookeeper
export PATH=$PATH:$JAAV_HOME/bin:$ZOOKEEPER_HOME/bin
:wq 保存 退出
刷新profile source /etc/profile
9.编辑 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=/opt/zookeeper/data
dataLogDir=/opt/zookeeper/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=500
# Purge task interval in hours
# Set to "0" to disable auto purge feature
autopurge.purgeInterval=24
server.1=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888
server.1 这个1 要在对应的ip上的zookeeper进行设置
10.启动zookeeper
/opt/zookeeper/bin/zkServer.sh start
启动成功之后通过zkServer.sh status 查看状态
11.配置开机启动
cd /etc/rc.d/init.d
创建名字为zookeeper的文件
touch zookeeper 然后使用vim进行编辑
#!/bin/bash
#chkconfig: 2345 10 90
#description: service zookeeper
export JAVA_HOME=/usr/java/jdk1.8.0_131
export ZOO_LOG_DIR=/opt/zookeeper/logs
ZOOKEEPER_HOME=/opt/zookeeper
case "$1" in
start) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start;;
start-foreground) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start-foreground;;
stop) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh stop;;
status) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh status;;
restart) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh restart;;
upgrade)su root ${ZOOKEEPER_HOME}/bin/zkServer.sh upgrade;;
print-cmd)su root ${ZOOKEEPER_HOME}/bin/zkServer.sh print-cmd;;
*) echo "requirestart|start-foreground|stop|status|restart|print-cmd";;
esac
保存
添加到开机启动列表中
chkconfig --add zookeeper
添加之后可以通过ckconfig --list进行查看