搭建之前,先自行下载安装文件,配置hosts文件等操作。
- 下载页面:http://zookeeper.apache.org/releases.html,下载apache-zookeeper-3.7.0-bin.tar.gz文件;
- 配置
/etc/hosts
文件,添加127.0.0.1 master
映射;
一、伪分布式部署
1.1创建三个数据目录
mkdir -p /home/michael/data/zk1
mkdir -p /home/michael/data/zk2
mkdir -p /home/michael/data/zk3
1.2查看zookeeper示例配置文件
[michael@chinahol conf]$ cat zoo_sample.cfg |grep -v ^# | grep -v ^$
#session的会话时间 以ms为单位
tickTime=2000
#服务器启动以后,master和slave通讯的时间
initLimit=10
#master和slave之间的心跳检测时间,检测slave是否存活
syncLimit=5
#保存zk的快照和数据
dataDir=/tmp/zookeeper
#客户端访问zk的端口
clientPort=2181
1.3将zoo_sample.cfg重命名为zoo1.cfg并更改配置
编辑配置文件时可以使用
:set list
显示隐藏字符,避免配置有误,参考:zookeeper启动报错:Address unresolved
[michael@chinahol conf]$ mv ./zoo_sample.cfg ./zoo1.cfg
更改配置:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/michael/data/zk1
#客户端访问zk的端口
clientPort=2181
#"server.1"中的1,即是该机器在数据文件夹中配置的myid,master对应于前面在hosts里面配置的主机映射 2888是数据同步和消息传递端口,3888是选举端口
server.1=master:2888:3888
server.2=master:2889:3889
server.3=master:2890:3890
1.4将zoo1.cfg复制一份为zoo2.cfg并更改配置
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/michael/data/zk2
#客户端访问zk的端口
clientPort=2182
server.1=master:2888:3888
server.2=master:2889:3889
server.3=master:2890:3890
1.5将zoo1.cfg复制一份为zoo3.cfg并更改配置
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/michael/data/zk3
#客户端访问zk的端口
clientPort=2183
server.1=master:2888:3888
server.2=master:2889:3889
server.3=master:2890:3890
1.6手动建立myid文件且指定在zk数据目录,也就是dataDir指定的路径(不管真分布还是伪分布都需要指定)
echo 1 >> /home/michael/data/zk1/myid
echo 2 >> /home/michael/data/zk2/myid
echo 3 >> /home/michael/data/zk3/myid
1.7启动并测试zookeeper分布式是否搭建成功
分别启动三个zookeeper:
cd /home/michael/apache-zookeeper-3.7.0-bin/bin
[michael@chinahol bin]$ ./zkServer.sh start /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo1.cfg
ZooKeeper JMX enabled by default
Using config: /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo1.cfg
Starting zookeeper ... STARTED
[michael@chinahol bin]$ ./zkServer.sh start /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo2.cfg
ZooKeeper JMX enabled by default
Using config: /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo2.cfg
Starting zookeeper ... STARTED
[michael@chinahol bin]$ ./zkServer.sh start /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo3.cfg
ZooKeeper JMX enabled by default
Using config: /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo3.cfg
Starting zookeeper ... STARTED
查看服务状态:
[michael@chinahol bin]$ ./zkServer.sh status /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo1.cfg
ZooKeeper JMX enabled by default
Using config: /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo1.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[michael@chinahol bin]$
[michael@chinahol bin]$
[michael@chinahol bin]$ ./zkServer.sh status /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo2.cfg
ZooKeeper JMX enabled by default
Using config: /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo2.cfg
Client port found: 2182. Client address: localhost. Client SSL: false.
Mode: leader
[michael@chinahol bin]$
[michael@chinahol bin]$
[michael@chinahol bin]$ ./zkServer.sh status /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo3.cfg
ZooKeeper JMX enabled by default
Using config: /home/michael/apache-zookeeper-3.7.0-bin/conf/zoo3.cfg
Client port found: 2183. Client address: localhost. Client SSL: false.
Mode: follower
1.8常用命令
启动:
./zkServer.sh start /path/to/your/config/file/zoo1.cfg
停止:
./zkServer.sh stop /path/to/your/config/file/zoo1.cfg
查看状态:
./zkServer.sh status /path/to/your/config/file/zoo1.cfg
二、Zookeeper真分布式部署在master、slave1、slave2 三台不同的服务器上
2.1 master服务器配置文件
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/michael/data/zk
#客户端访问zk的端口
clientPort=2181
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
2.2 slave1服务器配置文件
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/michael/data/zk
#客户端访问zk的端口
clientPort=2181
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
2.3 slave2服务器配置文件
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/michael/data/zk
#客户端访问zk的端口
clientPort=2181
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
References
最新评论
我的是ipv4网络,如何使用直播源啊!
我今天试了,不想啊,我的是新疆昌吉移动的网络。
收不到验证码电报
现在充值29起了