我是靠谱客的博主 乐观铅笔,最近开发中收集的这篇文章主要介绍centos7+Zookeeper1. 前置配置2. 基础安装配置3. Zookeeper配置,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1. 前置配置

1.1 基础环境

三台 Centos7虚拟机

1.2 主机规划

IP主机名节点
192.168.20.129zookeeper1集群节点
192.168.20.133zookeeper2集群节点
192.168.20.134zookeeper3集群节点

2. 基础安装配置

2.1 修改主机名

1. zookeeper1:
[root@localhost ~]# hostnamectl set-hostname zookeeper1
[root@localhost ~]# bash
[root@zookeeper1 ~]#
2. zookeeper2:
[root@localhost ~]# hostnamectl set-hostname zookeeper2
[root@localhost ~]# bash
[root@zookeeper2 ~]#
3. zookeeper3:
[root@localhost ~]# hostnamectl set-hostname zookeeper3
[root@localhost ~]# bash
[root@zookeeper3 ~]#

2.2 修改hosts文件

1. zookeeper1:

​ 添加三条配置

[root@zookeeper1 ~]# vim /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.20.129 zookeeper1
    192.168.20.133 zookeeper2
    192.168.20.134 zookeeper3
2. zookeeper2:
[root@zookeeper2 ~]# scp root@192.168.20.129:/etc/hosts /etc/host
The authenticity of host '192.168.20.129 (192.168.20.129)' can't be established.
ECDSA key fingerprint is SHA256:WeIKO1nEQ4QvOECVAWRTs/kfx9h8sMpf/cW3ruFQUnw.
ECDSA key fingerprint is MD5:ac:4c:40:e5:7d:61:e7:10:5c:79:7f:b6:21:b5:aa:3f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.20.129' (ECDSA) to the list of known hosts.
root@192.168.20.129's password:
hosts                                                                                                                100%  236   360.3KB/s   00:00
[root@zookeeper2 ~]#
3. zookeeper3:
[root@zookeeper3 ~]# scp root@192.168.20.129:/etc/hosts /etc/host
The authenticity of host '192.168.20.129 (192.168.20.129)' can't be established.
ECDSA key fingerprint is SHA256:WeIKO1nEQ4QvOECVAWRTs/kfx9h8sMpf/cW3ruFQUnw.
ECDSA key fingerprint is MD5:ac:4c:40:e5:7d:61:e7:10:5c:79:7f:b6:21:b5:aa:3f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.20.129' (ECDSA) to the list of known hosts.
root@192.168.20.129's password:
hosts                                                                                                                100%  236   414.2KB/s   00:00
[root@zookeeper3 ~]#

2.3 安装JDK环境

1. zookeeper1:
[root@zookeeper1 ~]# yum -y list java* | grep java-1.8.0-openjdk-devel
java-1.8.0-openjdk-devel.i686              1:1.8.0.342.b07-1.el7_9       updates
java-1.8.0-openjdk-devel.x86_64            1:1.8.0.342.b07-1.el7_9       updates
[root@zookeeper1 ~]# yum -y install java-1.8.0-openjdk-devel
[root@zookeeper1 ~]# java -version
openjdk version "1.8.0_342"
OpenJDK Runtime Environment (build 1.8.0_342-b07)
OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode)
2. zookeeper2:
[root@zookeeper2 ~]# yum -y list java* | grep java-1.8.0-openjdk-devel
java-1.8.0-openjdk-devel.i686              1:1.8.0.342.b07-1.el7_9       updates
java-1.8.0-openjdk-devel.x86_64            1:1.8.0.342.b07-1.el7_9       updates
[root@zookeeper2 ~]# yum -y install java-1.8.0-openjdk-devel
[root@zookeeper2 ~]# java -version
openjdk version "1.8.0_342"
OpenJDK Runtime Environment (build 1.8.0_342-b07)
OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode)
3. zookeeper3:
[root@zookeeper3 ~]# yum -y list java* | grep java-1.8.0-openjdk-devel
java-1.8.0-openjdk-devel.i686              1:1.8.0.342.b07-1.el7_9       updates
java-1.8.0-openjdk-devel.x86_64            1:1.8.0.342.b07-1.el7_9       updates
[root@zookeeper3 ~]# yum -y install java-1.8.0-openjdk-devel
[root@zookeeper3 ~]# java -version
openjdk version "1.8.0_342"
OpenJDK Runtime Environment (build 1.8.0_342-b07)
OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode)

2.4 获取并解压zookeeper软件包

1. zookeeper1:

获取 zookeeper-3.4.9.tar.gz 软件包

[root@zookeeper1 ~]# cd /usr/local/src/
[root@zookeeper1 src]# wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
--2022-09-14 08:26:38--  https://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
正在解析主机 archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
正在连接 archive.apache.org (archive.apache.org)|138.201.131.134|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:22724574 (22M) [application/x-gzip]
正在保存至: “zookeeper-3.4.9.tar.gz”

100%[=============================================================================================================>] 22,724,574  3.81MB/s 用时 6.9s

2022-09-14 08:26:46 (3.15 MB/s) - 已保存 “zookeeper-3.4.9.tar.gz” [22724574/22724574])
[root@zookeeper1 src]# tar -zxvf zookeeper-3.4.9.tar.gz -C /usr/local/
[root@zookeeper1 src]# cd /usr/local/zookeeper-3.4.9/
[root@zookeeper1 zookeeper-3.4.9]#
2. zookeeper2:
[root@zookeeper2 ~]# cd /usr/local/src/
[root@zookeeper2 src]# scp root@192.168.20.129:/usr/local/src/zookeeper-3.4.9.tar.gz /usr/local/src/
root@192.168.20.129's password:
zookeeper-3.4.9.tar.gz                                                                                               100%   22MB  89.2MB/s   00:00
[root@zookeeper2 src]#
[root@zookeeper2 src]# tar -zxvf zookeeper-3.4.9.tar.gz -C /usr/local/
[root@zookeeper2 src]# cd /usr/local/zookeeper-3.4.9/
[root@zookeeper2 zookeeper-3.4.9]#
3. zookeeper3:
[root@zookeeper3 ~]# cd /usr/local/src/
[root@zookeeper3 src]# scp root@192.168.20.129:/usr/local/src/zookeeper-3.4.9.tar.gz /usr/local/src/
root@192.168.20.129's password:
zookeeper-3.4.9.tar.gz                                                                                               100%   22MB  91.2MB/s   00:00
[root@zookeeper3 src]#
[root@zookeeper3 src]# tar -zxvf zookeeper-3.4.9.tar.gz -C /usr/local/
[root@zookeeper3 src]# cd /usr/local/zookeeper-3.4.9/
[root@zookeeper3 zookeeper-3.4.9]#

3. Zookeeper配置

3.1 配置Zookeeper节点

1. zookeeper1:
[root@zookeeper1 zookeeper-3.4.9]# cd conf/
[root@zookeeper1 conf]# ls
configuration.xsl  log4j.properties  zoo_sample.cfg
[root@zookeeper1 conf]# cp zoo_sample.cfg zoo.cfg
[root@zookeeper1 conf]# vim zoo.cfg
    tickTime=2000 # Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔
    initLimit=10 # 允许follower连接并同步到Leader的初始化连接时间,以tickTime为单位。
    syncLimit=5 # 配置follower和leader之间发送消息,请求和应答的最大时间长度。
    dataDir=/tmp/zookeeper # 数据目录
    dataLogDir=/tmp/zookeeper/log # 日志目录
    clientPort=2181 # 客户端端口
    server.0=192.168.20.129:2888:3888 # server.id=ip:服务器之间的通信端口:Leader选举的端口
    server.1=192.168.20.133:2888:3888
    server.2=192.168.20.134:2888:3888

echo 数字 > /tmp/zookeeper/myid 和 server.数字=192... 对应

[root@zookeeper1 conf]# mkdir -p /tmp/zookeeper/log
[root@zookeeper1 conf]# echo 0 > /tmp/zookeeper/myid
2. zookeeper2:
[root@zookeeper2 src]# scp root@192.168.20.129:/usr/local/zookeeper-3.4.9/conf/zoo.cfg /usr/local/zookeeper-3.4.9/conf/
root@192.168.20.129's password:
zoo.cfg                                                                                                              100% 1024     1.3MB/s   00:00
[root@zookeeper2 src]# 
[root@zookeeper2 src]# mkdir -p /tmp/zookeeper/log
[root@zookeeper2 src]# echo 1 > /tmp/zookeeper/myid
3. zookeeper3:
[root@zookeeper3 src]# scp root@192.168.20.129:/usr/local/zookeeper-3.4.9/conf/zoo.cfg /usr/local/zookeeper-3.4.9/conf/
root@192.168.20.129's password:
zoo.cfg                                                                                                              100% 1024     1.6MB/s   00:00
[root@zookeeper3 src]#
[root@zookeeper3 src]# mkdir -p /tmp/zookeeper/log
[root@zookeeper3 src]# echo 2 > /tmp/zookeeper/myid

3.2 启动并验证Zookeeper

1. zookeeper1:
[root@zookeeper1 conf]# cd /usr/local/zookeeper-3.4.9/bin/
[root@zookeeper1 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper1 bin]#
2. zookeeper2:
[root@zookeeper2 src]# cd /usr/local/zookeeper-3.4.9/bin/
[root@zookeeper2 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper2 bin]#
3. zookeeper3:
[root@zookeeper3 src]# cd /usr/local/zookeeper-3.4.9/bin/
[root@zookeeper3 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper3 bin]#

全部节点启动后,分别查看节点端口是否开启了3888端口

1. zookeeper1:
[root@zookeeper1 log]# /usr/local/zookeeper-3.4.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: follower
[root@zookeeper1 log]#
2. zookeeper2:
[root@zookeeper2 log]# /usr/local/zookeeper-3.4.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader
[root@zookeeper2 log]#
3. zookeeper3:
[root@zookeeper3 zookeeper]# /usr/local/zookeeper-3.4.9/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: follower
[root@zookeeper3 zookeeper]#

最后

以上就是乐观铅笔为你收集整理的centos7+Zookeeper1. 前置配置2. 基础安装配置3. Zookeeper配置的全部内容,希望文章能够帮你解决centos7+Zookeeper1. 前置配置2. 基础安装配置3. Zookeeper配置所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部