一、环境准备
1、需安装Java环境并配置环境变量
https://jdk.java.net/java-se-ri/11
2、下载Zookeeper(3.6.3)
压缩包并解压 https://zookeeper.apache.org/releases.html
3、配置防火墙,开放相关端口.
二、修改配置
进入Zookeeper目录下的conf目录,修改zoo_sample.cfg配置文件内容为
修改以下配置,
# 数据目录dataDir=/var/lib/zookeeper/# 集群各节点信息server.1=192.168.0.11:2888:3888server.2=192.168.0.12:2888:3888server.3=192.168.0.13:2888:3888
三、启动
进入bin目录下,执行以下命令
在各个不同的服务器分别执行,启动多个服务。
./zkServer.sh startZookeeper会根据配置文件中的各节点信息,自动完成选举,并组建集群
四、设置开机启动
创建文件 /etc/rc.d/init.d/zookeeper
写入以下内容
#!/bin/bash## zookeeper --- this script is used to start and stop zookeeper## chkconfig: - 80 12# description: zookeeper is a centralized service for maintaining configuration information,naming,providing distributed synchronization,and providing group services.# processname: zookeeperEXEC=/usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.shPIDFILE=/var/lib/zookeeper/zookeeper_server.pidcase "$1" instart)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed"elseecho "Starting Zookeeper server..."$EXEC startecho "Zookeeper server started"fi;;stop)if [ ! -f $PIDFILE ]thenecho "$PIDFILE does not exist, process is not running"elsePID=$(cat $PIDFILE)echo "Stopping ..."$EXEC stopwhile [ -x /proc/${PID} ]doecho "Waiting for Zookeeper to shutdown ..."sleep 1doneecho "Zookeeper stopped"fi;;*)echo "Please use start or stop as first argument";;esac
添加可执行权限
chmod +x /etc/rc.d/init.d/zookeeper
注册为系统服务
chkconfig --add zookeeper
添加开机自启动
chkconfig zookeeper on