Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zookeeper安装部署(单点/集群) #25

Open
johnnian opened this issue Jul 31, 2017 · 0 comments

Comments

1 participant
@johnnian
Copy link
Owner

commented Jul 31, 2017

Zookeeper 是个分布式开源框架,之前在做分布式日志收集的时候,就使用到,Zookeeper搭建比较简单。

下载

目前最新稳定版本:3.4.10, 下载地址

进入 stable 目录下载:

1

下载后解压:

[root@1c271ed316ca ~]#  tar zxvf zookeeper-3.4.10.tar.gz 

单点模式启动

使用默认配置,启动监听端口:2181

[root@1c271ed316ca ~]#  cd zookeeper-3.4.10
[root@1c271ed316ca zookeeper-3.4.10 ]#  cp conf/zoo_sample.cfg conf/zoo.cfg
[root@1c271ed316ca zookeeper-3.4.10 ]#  bin/zkServer.sh start

默认情况下,zkServer.sh 加载 ../conf/zoo.cfg 配置文件,配置文件主要有下面内容:

可以修改 dataDir 的目录,Zookeeper暴露给客户端的端口。

# 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=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181

集群模式

步骤1:配置文件增加节点信息
分别在不同的节点A、B、C机器上下载Zookeeper,并且解压,在默认配置文件基础上,添加下面的节点信息:

server.1=xx.xx.xx.xx:2888:3888 # A节点IP
server.2=xx.xx.xx.xx:2888:3888 # B节点IP
server.2=xx.xx.xx.xx:2888:3888 # C节点IP

说明:

  1. 2888 端口: Zookeeper 各个节点之间的通信端口;
  2. 3888端口: Zookeeper 选择Leader的端口;
  3. 这些端口可以自行修改,需要指定好 当前节点的ID(myid)即可,Zookeeper在启动服务后,会开启当前节点的端口配置;

步骤2:配置当前节点的ID

[root@1c271ed316ca ~]# echo "X"  > /tmp/zookeeper/myid

注意:

  1. "X" 改为当前节点的编号,对应于配置文件中 server.X
  2. /tmp/zookeeper 改为实际 Zookeeper 配置文件中的 dataDir 路径;

Zookeeper 服务启动的时候,会在 Zookeeper DataDir 目录查找 myid文件,里面的数字即表示当前的节点是 server.X.

步骤3:各个节点分别启动服务

[root@A节点 zookeeper-3.4.10 ]#  bin/zkServer.sh start
[root@B节点 zookeeper-3.4.10 ]#  bin/zkServer.sh start
[root@C节点 zookeeper-3.4.10 ]#  bin/zkServer.sh start

参考链接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.