Zookeeper
一、下载zookeeper
解压到指定文件夹下:tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz -C /home/zk/
改个名字(这个随意) mv apache-zookeeper-3.5.8-bin.tar zookeeper
二、将解压后的zookeeper复制两份(一共三份)
* cp -r zookeeper zookeeper2
* cp -r zookeeper zookeeper3
三、修改配置文件进入zookeeper/conf下,将zoo_simple.cfg复制一份为zoo.cfg
cp zoo_simple.cfg zoo.cfg
然后vim编辑zoo.cfg
* tickTime:用于定义ZooKeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,即每隔tickTime毫秒就会发送一个心跳。上面设置的是2000毫秒。
* initLimit:用来设置ZooKeeper服务器集群中连接到Leader的Follower服务器最长能能接受("设定值"tickTime)毫秒时间的心跳。超过该时间后ZooKeeper服务器集群中的Follower服务器还没有返回信息,那么表明该Follower服务器连接失败。上面设置的是(102000)毫秒。该属性是针对ZooKeeper为集群模式或伪集群模式时使用的参数
* syncLimit:用于设置ZooKeeper服务器集群中Leader服务器与Follower服务器之间发送消息时请求和应答的最大时长,其时间长度为("设定值"tickTime)毫秒。上面设置的是(52000)毫秒。该属性是针对ZooKeeper为集群模式或伪集群模式时使用的参数
* dataDir:ZooKeeper保存数据的目录,默认情况下,ZooKeeper将写数据的日志文件也保存在这个目录里。
* dataLogDir:存放日志文件
* clientPort:客户端连接ZooKeeper服务器的端口,Zookeeper监听该端口并通过该端口接受客户端的访问请求
* server.0=localhost:2287:3387
server.1=localhost:2288:3388server.2=localhost:2289:3389server.myid=IP:Port1:Port2, myid是服务器的编号,一个正整数,一般是0、1、2、3等待,port1表示的是服务器与集群中的Leader服务器交换信息的端口,一般用2288,Port2表示的是万一集群中的Leader服务器宕机了,需要一个端口来重新进行宣讲,选出一个新的Leader,一般用3388
/home/zk/zookeeper2/conf下的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/zk/zookeeper2/zkdata
dataLogDir=/home/zk/zookeeper2/zkdatalog
# the port at which the clients will connect
clientPort=2182
server.0=127.0.0.1:2287:3887
server.1=127.0.0.1:2288:3888
server.2=127.0.0.1:2289:3889
# 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
/home/zk/zookeeper3/conf下的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/zk/zookeeper3/zkdata
dataLogDir=/home/zk/zookeeper3/zkdatalog
# the port at which the clients will connect
clientPort=2183
server.0=127.0.0.1:2287:3887
server.1=127.0.0.1:2288:3888
server.2=127.0.0.1:2289:3889
# 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
四、创建zkdata,和zkdatalog目录
- 在三个zookeeper文件下创建zkdata,和zkdatalog目录
- 在/home/zk/zookeeper/zkdata下创建myid文件,写入服务器编号
vim myid
0
1
- 在/home/zk/zookeeper3/zkdata下创建myid文件,写入服务器编号
vim myid
2
五、分别启动三个zookeeper
cd /home/zk/zookeeper/bin目录下,执行启动
./zkServer.sh start
另外两个一样。查看zookeeper状态在bin目录下 执行: ./zkServer.sh status 。
三个zookeeper状态如上,一主两从的集群模式就搭建好了