java面试题网站:www.javaoffers.com
我的电脑是linux,并且已经在网上下载好了zookeeper-3.4.5.tar.gz,上传到集群的node1节点

scp -r zookeeper-3.4.5.tar.gz  root@node:/home/soft

登陆到node1解压

tar -zxvf  zookeeper-3.4.5.tar.gz

先在node1配置好,然后再同步到其他节点上 node2 node3,zk节点不需要太多,我们只需要3台,分别是 node1 node2 node3
vi ~/zookeeper-3.4.5/conf/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.
#注意这里改成自己的~/zookeeper-3.4.5/data
dataDir=/home/soft/zookeeper-3.4.5/data
# the port at which the clients will connect
clientPort=2181
#
# 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=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888

然后建立data

mkdir ~/zookeeper-3.4.5/data

创建zk集群部署脚本

vi scp_zk.sh

内容如下

#!/bin/bash
#集群安装zk
IPS="node2 node3"
i=1
for IP in $IPS
do
   let i=$i+1
   echo "正在同步Zk到${IP}"
   echo ${i} > /home/soft/zookeeper-3.4.5/data/myid
   scp -r /home/soft/zookeeper-3.4.5 root@$IP:/home/soft/
done

echo 1 > /home/soft/zookeeper-3.4.5/data/myid

echo '集群同步zk以完成'

echo '准备启动所有zk'

IPS="node1 node2 node3"
for IP in $IPS
do
   ssh root@$IP 'source /etc/profile;bash /home/soft/zookeeper-3.4.5/bin/zkServer.sh start'
done

echo "zk 集群已经启动"
echo '查看zk启动的状态'

for IP in $IPS
do 
  ssh root@$IP 'source /etc/profile;bash /home/soft/zookeeper-3.4.5/bin/zkServer.sh status'
done

执行脚本

./scp_zk.sh

脚本执行结果的部分内容

集群同步zk以完成
准备启动所有zk
JMX enabled by default
Using config: /home/soft/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /home/soft/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /home/soft/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
zk 集群已经启动

启动完成后记得检查一下他们的状态,以保证正确启动所有zk

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐