Zookeeper集群搭建记录 | 云计算[CentOS7] | Zookeeper集群搭建(上)

本文涉及的产品
云原生网关 MSE Higress,422元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
注册配置 MSE Nacos/ZooKeeper,118元/月
简介: 写在前面step1 Zookeeper安装包的下载step2 关闭防火墙step3 解压配置Zookeeper1 解压并创建修改/conf/zoo.cfg文件2 创建并修改/data/myidstep4 配置文件传送到其他节点

写在前面


本系列文章索引以及一些默认好的条件在 传送门


在配置Zookeeper 之前,建议先配置Hadoop集群,具体的操作流程博主已更新完成,链接


step1 Zookeeper安装包的下载


Zookeeper的安装包版本不太相同,大致分为有编译过的和没有编译过的(如有错请留言指正

一般情况下对于我们在解压配置就能使用的情况下,我们可以下载编译之后的版本,比如在官网上:

a780c43e36c740cdbf591f25667a9fc8.png


下面代表着源代码,我们应该选择不在红框之内的

Zookeeper仓库

本文以3.5.9为例,应该下载上方连接中的:

f4b4c9492bee4b1dad9c6a4a9d0559d0.png


这个版本的解压后和其他未编译过的有个显著的不同:在解压后有一个lib文件夹,通常里面保存着应该会用到的文件等

下载速度较快,不再网盘分享


step2 关闭防火墙


如果防火墙处于打开的状态,会影响到虚拟机之间的互相访问,以及从主机通过web浏览器查看各个服务器节点的状态

命令:

systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld


step3 解压配置Zookeeper


1 解压并创建修改/conf/zoo.cfg文件


将下载好的文件放到master节点的/usr/local/之下

然后解压文件,命令:

tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz


解压之后,将文件夹的名字去掉版本号:

mv apache-zookeeper zookeeper

然后跳转到./zookeeper/conf下,将官方给的zoo.cfg示例文件改名:

cp zoo_sample.cfg zoo.cfg


然后编辑zoo.cfg

大致改为:

7798beac9f63447cb1c6e488ea434069.png


切勿盲目CV,记得修改为自己的主机名

# 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=/usr/local/zookeeper/data/
# the port at which the clients will connect
clientPort=2181
# master
server.1=0.0.0.0:2881:3881
server.2=slave01-315:2881:3881
server.3=slave02-315:2881:3881


2 创建并修改/data/myid


在zookeeper根目录下,我们再创建一个data文件夹

mkdir -p /usr/local/zookeeper/data

然后创建并编辑myid文件

cd /usr/local/zookeeper/data
touch myid
vim myid


在master节点的myid中,写入一个数字1

注意不得加任何空格,任何注释,必须单纯一行一列一个字符’1’


step4 配置文件传送到其他节点


我们需要将从master的文件放到slave1,slave2上

scp -r /usr/local/zookeeper slave1:/usr/local
scp -r /usr/local/zookeeper slave2:/usr/local


在slave1上,我们需要把/data/myid中的内容改为2

在slave2上,我们需要把/data/myid中的内容改为3

注意不得加任何空格,任何注释,必须单纯一行一列一个字符’1’

在slave1上,我们需要把/conf/zoo.cfg改成:

34dd21bb763a4602a32a5c347b2c6adc.png


切勿盲目CV,记得修改为自己的主机名

# 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=/usr/local/zookeeper/data/
# the port at which the clients will connect
clientPort=2181
server.1=master315:2881:3881
server.2=0.0.0.0:2881:3881
server.3=slave02-315:2881:3881


在slave2下,我们需要将/conf/zoo.cfg文件修改为:

6dbd7a647d99470a9734960357080ba2.png


切勿盲目CV,记得修改为自己的主机名

# 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=/usr/local/zookeeper/data/
# the port at which the clients will connect
clientPort=2181
server.1=master315:2881:3881
server.2=slave01-315:2881:3881
server.3=0.0.0.0:2881:3881


如果是小白从头开始配的话,应该不会出现2181端口被占用的情况,如果说自己的2181端口被占用,可以kill -9该进程

查看进程是否被占用:

netstat -nltp | grep 2181

若显示空白则恭喜你不需要进行任何操作

若显示除了某进程占用该端口,应该kill -9 进程号


相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
目录
相关文章
|
2月前
|
Java Shell Linux
Zookeeper单机&集群安装
Zookeeper单机&集群安装
36 1
|
2月前
|
存储 分布式计算 资源调度
Hadoop【环境搭建 04】【hadoop-2.6.0-cdh5.15.2.tar.gz 基于ZooKeeper搭建高可用集群】(部分图片来源于网络)
【4月更文挑战第1天】Hadoop【环境搭建 04】【hadoop-2.6.0-cdh5.15.2.tar.gz 基于ZooKeeper搭建高可用集群】(部分图片来源于网络)
82 3
|
13天前
|
Java 网络安全
分布式系统详解--框架(Zookeeper-简介和集群搭建)
分布式系统详解--框架(Zookeeper-简介和集群搭建)
108 0
|
2月前
|
存储 Java 网络安全
ZooKeeper【搭建 03】apache-zookeeper-3.6.0 伪集群版(一台服务器实现三个节点的ZooKeeper集群)
【4月更文挑战第10天】ZooKeeper【搭建 03】apache-zookeeper-3.6.0 伪集群版(一台服务器实现三个节点的ZooKeeper集群)
52 1
|
2月前
|
存储 Java 网络安全
ZooKeeper【搭建 02】apache-zookeeper-3.6.0 集群版(准备+安装配置+启动验证)
【4月更文挑战第8天】ZooKeeper【搭建 02】apache-zookeeper-3.6.0 集群版(准备+安装配置+启动验证)
30 1
|
2月前
|
存储 分布式计算 资源调度
centos 部署Hadoop-3.0-高性能集群(二)
centos 部署Hadoop-3.0-高性能集群(二)
31 0
centos 部署Hadoop-3.0-高性能集群(二)
|
2月前
|
负载均衡 监控 Linux
CentOS6.5高可用集群LVS+Keepalived(DR模式)
CentOS6.5高可用集群LVS+Keepalived(DR模式)
|
2月前
|
架构师 Shell Apache
Zookeeper集群搭建
Zookeeper集群搭建
|
2月前
|
Java 网络安全 Apache
搭建Zookeeper集群:三台服务器,一场分布式之舞
搭建Zookeeper集群:三台服务器,一场分布式之舞
177 0
|
2月前
|
分布式计算 Hadoop Java
centos 部署Hadoop-3.0-高性能集群(一)安装
centos 部署Hadoop-3.0-高性能集群(一)安装
67 0