zookeeper集群搭建

作者: localhost 分类: 中间件,大数据 发布时间: 2018-05-30 10:23

环境

  • Centos 7
  • 内网机器三台 spider25, spider28, spider29

下载zookeeper解压配置

# 下载
sudo wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

# 解压
tar -xzvf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10 /usr/local/zookeeper

#修改配置
cp /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg
vi /usr/local/zookeeper/conf/zoo.cfg

# 添加如下配置
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper/
clientPort=2181
# 设置集群机器的ip和端口(最好使用ip)
server.1=spider25:2888:3888
server.2=spider25:2888:3888
server.3=spider25:2888:3888


# scp发布spider25的zookeeper到另外两台机器
scp /usr/local/zookeeper -r hostname@ip:/home/hostname/
# 拷贝zookeeper到 /usr/local/zookeeper目录

运行集群

# 运行spider25
sudo /usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg
# 运行spider28
sudo /usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg
# 运行spider29
sudo /usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg

常用命令

  • 启动zookeeper
sudo /usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg
  • 停止zookeeper
sudo /usr/local/zookeeper/bin/zkServer.sh stop /usr/local/zookeeper/conf/zoo.cfg
  • 查看zookeeper输出日志
# 默认zookeeper会将日志输出到执行命令的当前目录
tail -f -n 200 /usr/local/zookeeper/bin/zookeeper.out
  • 查看zookeeper状态
sudo /usr/local/zookeeper/bin/zkServer.sh status /usr/local/zookeeper/conf/zoo.cfg
  • 连接zookeeper查看相关目录和节点
/usr/local/zookeeper/bin/zkCli.sh --server 127.0.0.1:2181
ls /

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注