1、安装jdk环境
zookeeper官网
主机:10.1.1.161
2、修改hosts
10.1.1.161 edu-provider-01
3、创建服务存放目录
mkdir /home/wusc && cd /home/wusc
4、下载解压zookeeper
使用 3.4.10版本
tar xvf zookeeper-3.4.10.tar.gz
5、创建存放数据和日志的目录
cd zookeeper-3.4.10
mkdir data
mkdir logs
6、拷贝配置文件并修改
cd conf/
cp zoo_sample.cfg zoo.cfg
修改配置文件
vim zoo.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=
/home/wusc/zookeeper-3.4.10/data
dataLogDir=
/home/wusc/zookeeper-3.4.10/logs
# the port at which the clients will connect
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
server.1=edu-provider-01:2888:3888
#2888端口是zookeeper服务之间通信的端口
#3888端口是zookeeper与其他应用程序通信的端口
7、创建myid文件
cd ../data/
vim myid
1
## "1"是在zoo.cfg中配置的server.1
8、添加zookeeper环境
vim /etc/profile
## zookooper
export ZOOKEEPER_HOME=/home/wusc/zookeeper-3.4.10
export PATH=$ZOOKEEPER_HOME/bin:$PATH
使配置文件生效
source /etc/profile
9、修改防火墙或关闭防火墙
vim /etc/sysconfig/iptables
# zookeeper
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT
重启iptables
service iptables restart
10、启动测试zookeeper
cd bin/
sh zkServer.sh start
Using config: /home/wusc/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
查看状态:
# sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/wusc/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode:
standalone
重启
# sh zkServer.sh restart
1、安装jdk环境
zookeeper官网
主机:10.1.1.161
2、修改hosts
10.1.1.161 edu-provider-01
3、创建服务存放目录
mkdir /home/wusc && cd /home/wusc
4、下载解压zookeeper
使用 3.4.10版本
5、创建存放数据和日志的目录
cd zookeeper-3.4.10
mkdir data
mkdir logs
6、拷贝配置文件并修改
cd conf/
cp zoo_sample.cfg zoo.cfg
修改配置文件
vim zoo.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=
/home/wusc/zookeeper-3.4.10/data
dataLogDir=
/home/wusc/zookeeper-3.4.10/logs
# the port at which the clients will connect
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
server.1=edu-provider-01:2888:3888
#2888端口是zookeeper服务之间通信的端口
#3888端口是zookeeper与其他应用程序通信的端口
7、创建myid文件
cd ../data/
vim myid
1
## "1"是在zoo.cfg中配置的server.1
8、添加zookeeper环境
vim /etc/profile
## zookooper
export ZOOKEEPER_HOME=/home/wusc/zookeeper-3.4.10
export PATH=$ZOOKEEPER_HOME/bin:$PATH
使配置文件生效
source /etc/profile
9、修改防火墙或关闭防火墙
vim /etc/sysconfig/iptables
# zookeeper
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT
重启iptables
service iptables restart
10、启动测试zookeeper
cd bin/
sh zkServer.sh start
Using config: /home/wusc/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
查看状态:
# sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/wusc/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode:
standalone
重启
# sh zkServer.sh restart
zookeeper 要求必须是奇数台
为什么要使用zookeeper
»大部分分布式应用需要一个主控、协调器或控制器来管理物理分布的子进程(如资源、任务分配等)
»目前,大部分应用需要开发私有的协调程序,缺乏一个通用的机制
»协调程序的反复编写浪费,且难以形成通用、伸缩性好的协调器
»ZooKeeper:提供通用的分布式锁服务,用以协调分布式应用
zookeeper能干什么
»Hadoop2.0,使用Zookeeper的事件处理确保整个集群只有一个活跃的NameNode,存储配置信息等.
»HBase,使用Zookeeper的事件处理确保整个集群只有一个HMaster,察觉HRegionServer联机和宕机,存储访问控制列表等.
3 zookeeper的配置
zookeeper的默认配置文件为zookeeper/conf/zoo_sample.cfg,需要将其修改为zoo.cfg。其中各配置项的含义,解释如下:
1.tickTime:CS通信心跳时间(cs: client serve)
Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
tickTime=2000
2.initLimit:LF初始通信时限
集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
initLimit=5
3.syncLimit:LF同步通信时限
集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
syncLimit=2
4.dataDir:数据文件目录
Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
dataDir=/home/michael/opt/zookeeper/data
5.clientPort:客户端连接端口
客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
clientPort=2181
6.服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口)
这个配置项的书写格式比较特殊,规则如下:
server.N=YYY:A:B
server.1=mazhongyi05:2888:3888
server.2=mazhongyi06:2888:3888