一、安装说明
1.1、文档说明
文档用于使用3台服务器,通过Docker运行Zookeeper数据库集群。
1.2、参考文档
代码语言:javascript复制Zookeeper集群部署: https://zookeeper.apache.org/doc/r3.6.0/zookeeperAdmin.html
二、系统环境
2.1、服务器配置要求
资源 | 最低要求 | 推荐配置 |
---|---|---|
CPU | 2 | 4 |
内存 | 4 | 16 |
磁盘 | 50 | 500 |
操作系统 | ubuntu 16.04 | ubuntu 18.04 |
2.2、软件要求
软件 | 版本 |
---|---|
Docker | 17.03 |
Zookeeper | 3.6.0 |
2.3、端口使用
应用 | 协议 | 端口 |
---|---|---|
Zookeeper | TCP | 2818,2888,3888 |
2.4、部署信息
三节点,一主两从,选举产生
172.30.3.231 | 172.30.3.234 | 172.30.3.238 |
---|---|---|
Zookeeper | Zookeeper | Zookeeper |
2.5、服务器设置,三节点
服务器时区设置为北京,三台服务器时间应保持一致
代码语言:javascript复制sudo tzselect
(依次输入4911)
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
2.6系统设置
调整允许用户打开文件句柄数
代码语言:javascript复制sudo vim /etc/security/limits.conf
增加以下配置
代码语言:javascript复制* soft nofile 65535
* hard nofile 65535
重启服务器
2.7、安装规范
代码语言:javascript复制1、 安装过程中应尽量使用普通用户进行操作
2、 所有安装涉及到的文件均放置在/work目录中,可以使用root用户或普通用户创建该目录,创建完成后应修改所有者以及所有组为普通用户。
3、 应用目录类似/work/project/app/{bin,data,conf,logs}
三、config安装配置
3.1、创建目录,三节点
代码语言:javascript复制mkdir -p /work/zookeeper-cluster/zookeeper/{bin,data,conf,logs}
3.2、编辑启动脚本,三节点
代码语言:javascript复制vim /work/zookeeper-cluster/zookeeper/bin/start.sh
内容
代码语言:javascript复制docker run -d --hostname zookeeper
--network=host
--log-opt max-size=10m
-v /etc/localtime:/etc/localtime:ro
-v /etc/timezone:/etc/timezone
-v /work/zookeeper-cluster/zookeeper/data:/data
-v /work/zookeeper-cluster/zookeeper/conf/zoo.cfg:/conf/zoo.cfg
-v /work/zookeeper-cluster/zookeeper/conf/java.env:/conf/java.env
-v /work/zookeeper-cluster/zookeeper/logs:/datalog
--name zookeeper zookeeper:3.6.0
代码语言:javascript复制chmod 755 /work/zookeeper-cluster/zookeeper/bin/start.sh
3.3、编辑配置文件,三节点
代码语言:javascript复制vim /work/zookeeper-cluster/zookeeper/conf/zoo.cfg
内容
代码语言:javascript复制dataDir=/data
dataLogDir=/datalog
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=false
admin.enableServer=true
server.1=172.30.3.231:2888:3888;2181
server.2=172.30.3.234:2888:3888;2181
server.3=172.30.3.238:2888:3888;2181
设置内存限制
代码语言:javascript复制vim /work/zookeeper-cluster/zookeeper/conf/java.env
代码语言:javascript复制#!/bin/bash
export JVMFLAGS="-Xms512m -Xmx1024m $JVMFLAGS"
3.5、设置myid
主机:172.30.3.231
代码语言:javascript复制vim /work/zookeeper-cluster/zookeeper/data/myid
内容
代码语言:javascript复制1
主机:172.30.3.234
代码语言:javascript复制vim /work/zookeeper-cluster/zookeeper/data/myid
内容
代码语言:javascript复制2
主机:172.30.3.238
代码语言:javascript复制vim /work/zookeeper-cluster/zookeeper/data/myid
内容
代码语言:javascript复制3
3.6、启动应用
代码语言:javascript复制/work/zookeeper-cluster/zookeeper/bin/start.sh
3.7、查看状态
连接任意节点
代码语言:javascript复制docker exec -it config mongo --port 27018
初始化副本
代码语言:javascript复制redis-cli --cluster create 172.30.3.231:30001 172.30.3.231:30002 172.30.3.234:30001 172.30.3.234:30002 172.30.3.238:30001 172.30.3.238:30002 --cluster-replicas 1
返回值
代码语言:javascript复制{
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1586588112, 1),
"electionId" : ObjectId("000000000000000000000000")
},
"lastCommittedOpTime" : Timestamp(0, 0)
}
3.8、查询状态
代码语言:javascript复制rs.status()
返回值
代码语言:javascript复制{
"set" : "configs",
"date" : ISODate("2020-04-11T06:55:43.899Z"),
"myState" : 1,
"term" : NumberLong(1),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"configsvr" : true,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1586588143, 1),
"t" : NumberLong(1)
},
"lastCommittedWallTime" : ISODate("2020-04-11T06:55:43.562Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1586588143, 1),
"t" : NumberLong(1)
},
"readConcernMajorityWallTime" : ISODate("2020-04-11T06:55:43.562Z"),
"appliedOpTime" : {
"ts" : Timestamp(1586588143, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1586588143, 1),
"t" : NumberLong(1)
},
"lastAppliedWallTime" : ISODate("2020-04-11T06:55:43.562Z"),
"lastDurableWallTime" : ISODate("2020-04-11T06:55:43.562Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1586588123, 1),
"lastStableCheckpointTimestamp" : Timestamp(1586588123, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "electionTimeout",
"lastElectionDate" : ISODate("2020-04-11T06:55:22.969Z"),
"electionTerm" : NumberLong(1),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1586588112, 1),
"t" : NumberLong(-1)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2020-04-11T06:55:23.013Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2020-04-11T06:55:23.593Z")
},
"members" : [
{
"_id" : 0,
"name" : "172.30.3.231:27018",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 283,
"optime" : {
"ts" : Timestamp(1586588143, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-04-11T06:55:43Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1586588122, 1),
"electionDate" : ISODate("2020-04-11T06:55:22Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.30.3.234:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 31,
"optime" : {
"ts" : Timestamp(1586588131, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1586588131, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-04-11T06:55:31Z"),
"optimeDurableDate" : ISODate("2020-04-11T06:55:31Z"),
"lastHeartbeat" : ISODate("2020-04-11T06:55:42.991Z"),
"lastHeartbeatRecv" : ISODate("2020-04-11T06:55:42.499Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.30.3.238:27018",
"syncSourceHost" : "172.30.3.238:27018",
"syncSourceId" : 2,
"infoMessage" : "",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "172.30.3.238:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 31,
"optime" : {
"ts" : Timestamp(1586588131, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1586588131, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-04-11T06:55:31Z"),
"optimeDurableDate" : ISODate("2020-04-11T06:55:31Z"),
"lastHeartbeat" : ISODate("2020-04-11T06:55:42.991Z"),
"lastHeartbeatRecv" : ISODate("2020-04-11T06:55:42.003Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.30.3.231:27018",
"syncSourceHost" : "172.30.3.231:27018",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
}
],
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1586588112, 1),
"electionId" : ObjectId("7fffffff0000000000000001")
},
"lastCommittedOpTime" : Timestamp(1586588143, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1586588143, 1),
"signature" : {
"hash" : BinData(0,"y6G4iMqVbLG/vu3tmPZy2421Y3s="),
"keyId" : NumberLong("6814344100507025437")
}
},
"operationTime" : Timestamp(1586588143, 1)
}