主机名称 | 主机IP | 节点 | (集群内通讯端口|选举leader|cline端提供服务)端口 |
docker0 | 192.168.1.100 | node-0 |
2888 | 3888 | 2181 |
docker1 | 192.168.1.101 | node-1 |
2888 | 3888 | 2181 |
docker2 | 192.168.1.102 | node-1 |
2888 | 3888 | 2181 |
集群为大于等于3个基数,如 3、5、7…,不宜太多,集群机器多了选举和数据同步耗时时长长,不稳定。目前觉得,三台选举+N台observe很不错
Index of /dist/zookeeper/zookeeper-3.9.0 最新版下载
[root@www tools]# wget https://archive.apache.org/dist/zookeeper/zookeeper-3.9.0/apache-zookeeper-3.9.0-bin.tar.gz
查看是否已经下载:
在docker0节点上,分发该包到各个服务器上的:/usr/local/tools目录,然后创建/usr/local/zookeeper目录,准备再docker0节点同时安装其他两台服务器的ZK;
[root@www tools]# mkdir -p /usr/local/zookeeper
首先,使其他两台服务(docker1,docker2)处于docker0控制的状态,如下图所示:
(可以参考:Centos7卸载|安装JDK1.8|Xshell7批量控制多个终端)
[root@www tools]# sudo yum install rsync -y
rsync和scp区别:用rsync做文件的复制要比scp的速度快,rsync只对差异文件做更新。scp是把所有文件都复制过去。
在主目录创建bin
目录:
[root@www tools]# mkdir ~/bin
创建分发脚本文件:xsync 脚本内容
[root@www tools]# cat ~/bin/xsync
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2. 遍历集群所有机器
for host in docker0 docker1 docker2
do
echo ==================== $host ====================
#3. 遍历所有目录,挨个发送
for file in $@
do
#4. 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exists!
fi
done
done
节点docker0上执行解压命令: 由于其他两台机器docker1,docker2与docker0主机直接相互处于Xshell控制状态,在任何一个节点的相关命令都会同步到其他机器上
下面我们来看看docker0上的节点上的 ~/bin/xsync
[root@www bin]# ll
总用量 4
-rwxr-xr-x 1 root root 736 8月 21 20:53 xsync
1.3 将jdk分发到docker1,docker2服务器上
[root@www bin]# ./xsync /usr/local/tools/jdk-8u371-linux-x64.tar.gz
==================== docker0 ====================
sending incremental file list
sent 66 bytes received 12 bytes 156.00 bytes/sec
total size is 139,219,380 speedup is 1,784,863.85
==================== docker1 ====================
sending incremental file list
jdk-8u371-linux-x64.tar.gz
sent 139,253,473 bytes received 35 bytes 39,786,716.57 bytes/sec
total size is 139,219,380 speedup is 1.00
==================== docker2 ====================
sending incremental file list
jdk-8u371-linux-x64.tar.gz
sent 139,253,473 bytes received 35 bytes 39,786,716.57 bytes/sec
total size is 139,219,380 speedup is 1.00
该脚本已生效:
二: 在节点docker0上解压zk安装包:
[root@www zookeeper]#
tar -zxvf /usr/local/tools/apache-zookeeper-3.9.0-bin.tar.gz -C /usr/local/zookeeper/
cd ~/bin/
[root@www bin]# ./xsync /usr/local/zookeeper/
将解压后的zookeeper文件全拷贝到docker1|docker2机器:
[root@www bin]# ./xsync /usr/local/zookeeper/
==================== docker0 ====================
sending incremental file list
sent 61,605 bytes received 227 bytes 123,664.00 bytes/sec
total size is 390,744,347 speedup is 6,319.45
==================== docker1 ====================
sending incremental file list
sent 61,613 bytes received 235 bytes 123,696.00 bytes/sec
total size is 390,744,347 speedup is 6,317.82
==================== docker2 ====================
sending incremental file list
sent 61,613 bytes received 235 bytes 123,696.00 bytes/sec
total size is 390,744,347 speedup is 6,317.82
后续补充完整.............