(一)安装前准备
检查ssh免密登录实现与否
[offcn@node-1 ~]$ ssh node-2
检查jdk的安装是否成功
[offcn@node-1 ~]$ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
检查时钟是否同步 三台机器统一执行date命令
(二)安装配置
1.安装包 链接:https://pan.baidu.com/s/1AGLG_lrgn4V9rz7w4Xy-KA 提取码:zhxm 2、上传解压重命名:
cd /home/offcn/software/
tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C ../apps/
cd /home/offcn/apps/
mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
3、创建zk数据存储目录:
cd /home/offcn/data/
mkdir zookeeper-3.5.7
4、创建myid
cd /home/offcn/data/zookeeper-3.5.7
echo 1 > myid
5、重命名配置文件:
cd /home/offcn/apps/zookeeper-3.5.7/conf/
mv zoo_sample.cfg zoo.cfg
6、修改核心配置文件
vim zoo.cfg
(1)指定数据存储目录
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/offcn/data/zookeeper-3.5.7/
(2)添加集群信息(节点、监听端口、选举端口)
server.1=node-1:2888:3888
server.2=node-2:2888:3888
server.3=node-3:2888:3888
zk端口说明: 2181:对clent端提供服务 2888:集群内机器通讯使用(Leader监听此端口) 3888:选举leader使用 (4)修改zk日志输出目录
cd /home/offcn/apps/zookeeper-3.5.7/bin
vim zkEnv.sh
if [ "x${ZOO_LOG_DIR}" = "x" ]
then
# ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
ZOO_LOG_DIR="$HOME/logs/zookeeper-3.5.7/"
fi
(5)分发安装包以及修改myid
cd /home/offcn/apps/
scp -r zookeeper-3.5.7/ node-2:$PWD
scp -r zookeeper-3.5.7/ node-3:$PWD
cd /home/offcn/data/
scp -r zookeeper-3.5.7/ node-2:$PWD
scp -r zookeeper-3.5.7/ node-3:$PWD
注意:修改node-2、node-3的myid (6)修改环境变量(可选)
sudo vim /etc/profile
#zookeeper-3.5.7
export ZOOKEEPER_HOME=/home/offcn/apps/zookeeper-3.5.7
export PATH=$PATH:$ZOOKEEPER_HOME/bin
同步环境变量到其他节点
sudo scp /etc/profile node-2:/etc
sudo scp /etc/profile node-3:/etc
三台机器全部执行
source /etc/profile
(三)服务启停
1、服务端启停
zkServer.sh start
zkServer.sh stop
zkServer.sh status
2、客户端启停
zkCli.sh
3、一键启停脚本
cd
mkdir bin
vim zk.sh
chmod 777 zk.sh
zk.sh
#!/bin/bash
echo -e "\e[1;35m Zookeeper $1 .... \e[0m"
export ScriptsPath=`pwd`
for host in node-1 node-2 node-3
do
echo "===================$host $1====================="
if [ $1 = status ]
then
ssh $host "source /etc/profile;zkServer.sh $1" | grep "Mode"
elif [ $1 = restart ]
then
sh $ScriptsPath/$0 stop;sleep 3;sh $ScriptsPath/$0 start;break
else
ssh $host "source /etc/profile;nohup zkServer.sh $1>/dev/null 2>&1 &"
fi
done
最后启动结果
|