下载zk

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz

解压

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

copy配置成3份

# 进入zk的conf目录
cd conf # copy1
cp zoo.cfg zoo1.cfg # copy2
cp zoo.cfg zoo2.cfg # copy3
cp zoo.cfg zoo3.cfg
zoo1.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/zk/zookeeper/data/zk1
dataLogDir=/usr/local/zk/zookeeper/log/log1
# the port at which the clients will connect #客户端连接 zk 服务器的端口,zk 监听这个端口,接受客户端请求
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
quorumListenOnAllIPs=true
server.1=47.103.72.160:2887:3887
server.2=47.103.72.160:2888:3888
server.3=47.103.72.160:2889:3889
#server.a=b:c:d , a:表示第几号服务器,b:服务器的ip地址,
#c:集群中与 leader 交换信息的端口,d:当 leader 服务器挂了,通过这个端口来重新选举 leader
#因为是在同一台机器上搭建的伪集群,所有 c,d 都不能一样
zoo2.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/zk/zookeeper/data/zk2
dataLogDir=/usr/local/zk/zookeeper/log/log2
# the port at which the clients will connect
clientPort=2182
# 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
quorumListenOnAllIPs=true
server.1=47.103.72.160:2887:3887
server.2=47.103.72.160:2888:3888
server.3=47.103.72.160:2889:3889
zoo3.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/zk/zookeeper/data/zk3
dataLogDir=/usr/local/zk/zookeeper/log/log3
# the port at which the clients will connect
clientPort=2183
# 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
quorumListenOnAllIPs=true
server.1=47.103.72.160:2887:3887
server.2=47.103.72.160:2888:3888
server.3=47.103.72.160:2889:3889

修改clientPort属性 (客户端连接 zk 服务器的端口,zk 监听这个端口,接受客户端请求)

修改dataDir属性(数据保存地址)

修改dataLogDir属性(日志保存地址)

server.n (集群地址,n 是dataDir目录下的myid文件中内容,用来标记该服务器在集群中的地址)

日志路径创建3份

# 进入log
cd log # 创建zk1日志目录
mkdir log1 # 创建zk2日志目录
mkdir log2 # 创建zk3日志目录
mkdir log4

数据路径创建3份

# 进入data
cd data # 创建zk1保存数据目录
mkdir zk1
cd zk1
vim myid
输入:1
保存退出 # 创建zk2保存数据目录
mkdir zk2
cd zk2
vim myid
输入:2
保存退出 # 创建zk3保存数据目录
mkdir zk3
cd zk3
vim myid
输入:3
保存退出

zk命令

cd bin

# 启动
sh zkServer.sh start zoo1.cfg
sh zkServer.sh start zoo2.cfg
sh zkServer.sh start zoo3.cfg # 状态
sh zkServer.sh status zoo1.cfg
sh zkServer.sh status zoo2.cfg
sh zkServer.sh status zoo3.cfg # 关闭
sh zkServer.sh stop zoo1.cfg
sh zkServer.sh stop zoo2.cfg
sh zkServer.sh stop zoo3.cfg

最新文章

  1. Seo的几个境界
  2. 我们都遇到过的 Replace Blank Space
  3. 浅谈JS执行环境及作用域
  4. python处理csv数据
  5. Linux下访问文件的基本模式
  6. whm 设置共享IP
  7. RX系列四 | RxAndroid | 加载图片 | 提交表单
  8. HTML基础-------HTML标签(2)
  9. JS的javascript:void(0)用法
  10. 《Java开发学习大纲文档》V6.0(已经不公布了,请查看第七版)
  11. Robberies HDU - 2955
  12. Swift -- 中文版两大官方文档汇总
  13. canvas元素绘制太极图
  14. 【ZeroMQ】1、ZeroMQ(java)入门之Requerst/Response模式
  15. Mongo分片集群脚本
  16. Python: pyinstaller打包exe(含file version信息)
  17. js图片自适应尺寸居中函数处理
  18. ORACLE11G 字符集更改(这里更改为AL32UTF8)
  19. Vue中引入jquery方法
  20. 1.1 - python基础语法 - 总结练习题

热门文章

  1. 单点登录(SSO)实现原理(转)
  2. Android常用开源库(转)
  3. 重新梳理调度器——GMP 调度模型
  4. 阿里云PTS分享-用性能测试工具JMeter实现基于供应链业务上对于WebSocket 协议的压测
  5. c语言函数的嵌套使用和矩阵运算
  6. [刘阳Java]_CSS图片画廊
  7. ES6 Class类
  8. Lesson 11 Not guilty
  9. Docker简易安装教程
  10. IPV6改造?华为云如此简单