可以直接把旧节点的目录直接全部拷贝过来
1. 安装Java环境
# 安装OpenJDK 8
apt-get update
apt-get install openjdk-8-jdk -y
2. 下载并安装ZooKeeper
# 下载指定版本
cd /data
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
# 解压安装
tar -zxf apache-zookeeper-3.6.2-bin.tar.gz
mv apache-zookeeper-3.6.2-bin zookeeper
# 创建必要目录
mkdir -p /data/zookeeper/data
mkdir -p /data/zookeeper/logs
3. 配置环境变量
创建环境变量配置文件
vim /etc/profile.d/zookeeper.sh
添加以下配置
# ZooKeeper Environment
export ZOOKEEPER_HOME=/data/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
# Java Environment
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
# ZooKeeper Security Configuration
export ZK_CLIENT_OPTS="-Djava.security.auth.login.config=/data/zookeeper/conf/zookeeper_jaas.conf"
export JVMFLAGS="-Djava.security.auth.login.config=/data/zookeeper/conf/zookeeper_jaas.conf"
使环境变量生效
source /etc/profile.d/zookeeper.sh
4、配置文件确认
如果是拷贝了目录就需要清空data和logs目录,如果有数据会出现No snapshot found, but there are log entries. Something is broken!
- 需要清理数据后启动服务,
- 需要写入节点id
# 1. 停止ZK服务
zkServer.sh stop
# 2. 清理数据目录(保险起见先备份)
cd /data/zookeeper
mv data data_backup
mv logs logs_backup
# 3. 重新创建目录
mkdir -p data logs
# 4. 设置正确的myid
echo "5" > /data/zookeeper/data/myid
# 5. 重启服务
zkServer.sh start
zoo.cfg
# 基础配置
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
clientPort=2181
admin.serverPort=8081
# 监听配置
quorumListenOnAllIPs=true
# 集群配置(使用实际IP)
server.1=172.24.77.10:2888:3888
server.2=172.24.77.11:2888:3888
server.3=172.24.77.12:2888:3888
server.4=172.24.77.13:2888:3888
# 启用四字母命令
4lw.commands.whitelist=*
# 自动清理配置
autopurge.snapRetainCount=3
autopurge.purgeInterval=1
# 会话超时配置
maxSessionTimeout=60000
minSessionTimeout=4000
# admin server配置
#admin.enableServer=true
#admin.serverAddress=0.0.0.0
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
requireClientAuthScheme=sasl
jaasLoginRenew=3600000
zookeeper_jaas.conf
Server {
org.apache.zookeeper.server.auth.DigestLoginModule required
user_super="super_password"
user_kafka="kafka_password";
};
Client {
org.apache.zookeeper.server.auth.DigestLoginModule required
username="super"
password="super_password";
};
5、确认新节点状态状态
zkServer.sh status
- 其他节点也要在配置文件中新增节点的配置
- 检查所有节点状态,确认只有一个leader
- 修改配置文件后,依次重启fllower节点,最后重启leader节点(最后重启时因为其他节点已经是最新的节点信息,leader节点重启时,主会漂移,最终整个集群状态更新)
步骤1:启动新节点,验证配置
Node4 (新) → 启动,验证配置正确性
Node5 (新) → 启动,验证配置正确性
步骤2:逐个重启follower
Node2 (Follower) → 重启
Node3 (Follower) → 重启
步骤3:最后重启leader
Node1 (Leader) → 重启