Basic information and installation of zk - Zookeeper01

First, the basic information of Zookeeper

1.1 Background

Whether in front of us learn hdfs, or learning redis clusters, we will use a zookeeper elections. This led to the creation of Redis.

We know that when we use the previous Zookeeper, we use three nodes. A leader node and two follower nodes elections. Therefore, in a clustered mode, there is a single point of failure leader of this node, in theory, but in fact, this is indeed a leader of its high available.

  Zookeeper有两种可运行的状态:1.可用状态。2.不可用状态。

  不可用状态恢复到可用状态应该越来越好。

1.2.Zookeeper not a database

Zookeeper is a file system, the structure is a tree structure (similar to the Linux directory tree), but there is no definition files and folders, the various branches of the tree, is merely a node (node), it is not save a lot of files and data. We look at some old projects, they often see such a phenomenon. Distributed project, during the transition time, beginning zk will use to store data, but with the development of technology, the new development will eliminate storage to use this feature, why?

zk在设计的时候,任何方向设计都是以“快速”优先,而速度快,往往带来的缺陷是在数据传输的时候,不能传输(大文件)。相反,我们学习过的redis,可以作为一个数据库进行使用。zk的node可以存储小量数据,这个数据量大小约1MB。

1.3. Temporary and permanent node node

Each client when connected clients, and will have a session. Relying on the session, we can know, some nodes are temporary and permanent node node.

With the presence of temporary nodes, a session is established, creating a lock when the session was in when there is a lock, when the session disappear, disappear lock, the lock does not need to go to other business logic design code.

1.4. Characteristics & protection

  • Sequential Consistency - the client application updates are sent sequentially
  • Atomicity - update success or failure, no partial results
  • Unified view - regardless of client connections that the server, the client will see the same view service
  • Reliability - Once the application has been updated since then it will continue to update the client coverage
  • Timeliness - Customer system view is guaranteed to be the latest in a specific time

Second, the installation

2.1. Getting the source

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz

2.2. Unpack, move to the opt directory

tar -xf apache-zookeeper-3.5.5-bin.tar.gz
mv apache-zookeeper-3.5.5-bin zookeeper-3.5.5
mv zookeeper-3.5.5 /opt

2.3. Modify Profile

mv zoo_sample.cfg zoo.cfg
vim zoo.cfg
修改dataDir=/var/zk

server.1=192.168.118.151:2888:3888
server.2=192.168.118.152:2888:3888
server.3=192.168.118.153:2888:3888
server.4=192.168.118.154:2888:3888

mkdir /var/zk

echo 1 >> /var/zk/myid
echo 2 >> /var/zk/myid
echo 3 >> /var/zk/myid
echo 4 >> /var/zk/myid

2.4. Editing ZOOKEEPER_HOME

vim /etc/profile

export ZOOKEEPER_HOME=/opt/zookeeper-3.5.5
export PATH=.:$PATH:$ZOOKEEPER_HOME/bin

source /etc/profile

2.5. Turn zk

zkServer.sh start

2.6. Turn zkcli.sh

zkcli.sh

2.7.zkcli.sh use

ls / 查看node
create /ooxx "" 创建一个ooxx节点
get -s /ooxx 获取一个ooxx
  • About cZxid, mZxid, pZxid
这个/ooxx的数据最大1M,这个数据也是二进制安全的

cZxid是事务id,递增的。 

cZxid,mZxid,pZxid 代表create modify parent

pZxid的子节点与最近一次创建/删除的时间,与本节点/子节点有关,与孙子节点无关
  • zkCli per session creates a SessionId, saved in a log file

  • Use port
    • 3888: election primary vote with
    • 2888: leader accepts write requests with

Guess you like

Origin www.cnblogs.com/littlepage/p/11543093.html