版权声明:欢迎转载,转载请说明出处. 大数据Github项目地址https://github.com/SeanYanxml/bigdata。 https://blog.csdn.net/u010416101/article/details/88759045
前言
重新安装了下ZooKeeper
,仍然遇到了一些问题.将操作流程记录如下.
基本操作
- 前提条件: JDK.
基本机器:
- 192.168.31.60
- 192.168.31.61
- 192.168.31.62
对于ZooKeeper而言, Master
与Follower
结点是通过选举选举出来的.所以集群的各个结点的配置基本一致.(除了myid
文件)
- 通过集群脚本,创建安装目录. 分发安装包.并且解压.
- 修改配置文件,并且拷贝.
- 在数据存放目录分别创建
myid
文件.
详细步骤
我们详细的说明与讲解下集群操作脚本.
(PS:如果你对于集群操作较为陌生的话,你可以先看下我的这篇文章.Linux 集群脚本基础)
- 通过集群脚本,创建安装目录. 分发安装包.并且解压.集群脚本及注释如下:
#!/bin/bash
# 需要安装的结点
cluster_nodes="192.168.31.60,192.168.31.61,192.168.31.62"
# 逗号分割
cluster_nodes=${cluster_nodes//,/ }
# 安装文件(和脚本放在同一目录)
apps_tar_name="zookeeper-3.4.6.tar.gz";
# 安装路径
install_folder="/opt/apps/zookeeper"
# 集群远程操作
for i in ${cluster_nodes}; do
# make dir
# 远程创建文件夹
ssh root@${i} "mkdir -p ${install_folder};"
# 远程传递安装包文件
scp ${apps_tar_name} root@${i}:${install_folder}/
# 远程解压文件夹(对于复杂文件,我们还可以创建软链接&重命名)
ssh root@${i} "cd ${install_folder};tar -zxvf zookeeper-3.4.6.tar.gz;"
done
- 修改配置文件
./zookeeper/zoo.cfg
. 其中最主要的配置为:
# 数据日志
dataDir=/opt/apps/zookeeper/data
# 结点日志记录(非zookeeper运行日志)
dataLogDir=/opt/apps/zookeeper/logs
# 开放端口
clientPort=2181
# 内部通信端口
server.1=192.168.31.60:2888:3888
server.2=192.168.31.61:2888:3888
server.3=192.168.31.62:2888:3888
详细配置文件如下:
[root@sean60 conf]# cat 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.
#dataDir=/tmp/zookeeper
dataDir=/opt/apps/zookeeper/data
dataLogDir=/opt/apps/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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=192.168.31.60:2888:3888
server.2=192.168.31.61:2888:3888
server.3=192.168.31.62:2888:3888
随后,可以通过scp
命令.将配置文件分别传递给其他结点.
scp zoo.cfg [email protected]:/opt/apps/zookeeper/zookeeper-3.4.6/conf/
- 创建数据存放目录,并创建
myid
文件.在三台机器上分别进行如下操作:
mkdir -p /opt/apps/zookeeper/data
mkdir -p /opt/apps/zookeeper/logs
# myid 各个结点分别为 (1,2,3)
# 192.168.31.60
echo "1" >> /opt/apps/zookeeper/data/myid
# 192.168.31.61
echo "2" >> /opt/apps/zookeeper/data/myid
# 192.168.31.62
echo "3" >> /opt/apps/zookeeper/data/myid
- 分别启动 / 停止 (也可以写成脚本)
[root@sean60 zookeeper]# cat start-all.sh
#!/bin/bash
cluster_nodes="192.168.31.60,192.168.31.61,192.168.31.62"
#cluster_nodes="192.168.31.61,192.168.31.62"
cluster_nodes=${cluster_nodes//,/ }
jdk_tar_name="zookeeper-3.4.6.tar.gz";
install_folder="/opt/apps/zookeeper"
for i in ${cluster_nodes}; do
# make dir
ssh root@${i} "/opt/apps/zookeeper/zookeeper-3.4.6/bin/zkServer.sh start"
done
[root@sean60 zookeeper]# cat stop-all.sh
#!/bin/bash
cluster_nodes="192.168.31.60,192.168.31.61,192.168.31.62"
#cluster_nodes="192.168.31.61,192.168.31.62"
cluster_nodes=${cluster_nodes//,/ }
jdk_tar_name="zookeeper-3.4.6.tar.gz";
install_folder="/opt/apps/zookeeper"
for i in ${cluster_nodes}; do
# make dir
ssh root@${i} "/opt/apps/zookeeper/zookeeper-3.4.6/bin/zkServer.sh stop"
done
- 验证(随便链接一台机器)
cd /opt/zookeeper/bin
./zkCli.sh -timeout 5000 -server 192.168.31.61:2181
Tips
- 网络防火墙情况.
CentOS 7
firewalld的基本使用
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
- 异常
Cannot open channel to 2 at election address /192.168.100.61:3888 java.net.SocketTimeoutException: c
- 异常
Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing
仔细排查1. 网络情况 2.磁盘是否使用满. 3.zoo.cfg
与myid
配置信息是否配置错误.
Unable to read additional data from server sessionid 0x0
java.net.NoRouteToHostException: No route to host解决方法
To Be Continue
后续的任务,仍然需要将其自动配置zoo.cfg
文件与myid
文件的配置自动化.