Linux Zookeeper集群安装
由于只有一台电脑,所以搭建一个伪集群(伪集群就是在一台电脑上模拟搭建集群,走不同端口启动,真实的情况在每台机器上搭建一个zookeeper或者每台机器两个zookeeper等),道理是一样的,只不过要注意别被防火墙或者安全组规则挡住了zookeeper节点间的通信,每个节点直接的网络要是通的。
集群数量推荐奇数,这是由于zookeeper的选举规则决定的,不懂先看zookeeper入门的文章,这里只是安装教程。
-
下载并解压zookeeper tar包
https://apache.claz.org/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
此处将包下载解压到了/usr/local/share/下
#解压后的目录里的结构 root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin# ls bin conf docs lib LICENSE.txt logs NOTICE.txt README.md README_packaging.md #bin目录 root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin# cd bin root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin/bin# ls README.txt zkCli.cmd zkEnv.cmd zkServer.cmd zkServer.sh zkSnapShotToolkit.sh zkTxnLogToolkit.sh zkCleanup.sh zkCli.sh zkEnv.sh zkServer-initialize.sh zkSnapShotToolkit.cmd zkTxnLogToolkit.cmd #conf目录 root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin/conf# ls configuration.xsl log4j.properties zoo_sample.cfg #将bin目录添加到path去 echo 'export PATH=$PATH:/usr/local/share/apache-zookeeper-3.6.2-bin/bin' >> /etc/profile #加载 source /etc/profile
-
复制三份配置后面用三份不同配置启动三个zookeeper
#进conf目录 cd conf #编辑第一个配置文件(或者复制zoo_sample.cfg修改) vi zk1.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=/usr/local/zk1 # 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 ## Metrics Providers # # https://prometheus.io Metrics Exporter #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider #metricsProvider.httpPort=7000 #metricsProvider.exportJvmInfo=true server.1=127.0.0.1:2981:2982 server.2=127.0.0.1:2983:2984 server.3=127.0.0.1:2985:2986
- 然后保存退出
- 然后复制两份,命名为zk2.cfg和zk3.cfg
cp zk1.cfg zk2.cfg cp zk1.cfg zk3.cfg #然后编辑zk2.cfg修改dataDir为/usr/local/zk2 修改clientPort为2182 #然后编辑zk3.cfg修改dataDir为/usr/local/zk3 修改clientPort为2183 #均保存退出 #创建这三个data目录 mkdir /usr/local/zk1 /usr/local/zk2 /usr/local/zk3
-
启动三个zookeeper并查看状态
#在conf目录下执行 root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin/conf zkServer.sh start zk1.cfg zkServer.sh start zk2.cfg zkServer.sh start zk3.cfg
#查看三个zookeeper的状态,发现第二个是leader root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin/conf# zkServer.sh status zk1.cfg /usr/bin/java ZooKeeper JMX enabled by default Using config: /usr/local/share/apache-zookeeper-3.6.2-bin/bin/../conf/zk1.cfg Client port found: 2181. Client address: localhost. Client SSL: false. Mode: follower root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin/conf# zkServer.sh status zk2.cfg /usr/bin/java ZooKeeper JMX enabled by default Using config: /usr/local/share/apache-zookeeper-3.6.2-bin/bin/../conf/zk2.cfg Client port found: 2182. Client address: localhost. Client SSL: false. Mode: leader root@ubuntu:/usr/local/share/apache-zookeeper-3.6.2-bin/conf# zkServer.sh status zk3.cfg /usr/bin/java ZooKeeper JMX enabled by default Using config: /usr/local/share/apache-zookeeper-3.6.2-bin/bin/../conf/zk3.cfg Client port found: 2183. Client address: localhost. Client SSL: false. Mode: follower
本文来自博客园,作者:HumorChen99,转载请注明原文链接:https://www.cnblogs.com/HumorChen/p/18039688
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~