Zookeeper Cluster construction

Source: Internet
Author: User
Tags redis cluster

Guide Preparing for the Codis cluster as the primary caching solution due to improved corporate caching scenarios (CODIS: Redis cluster solution developed by domestic pea pods, open source, GitHub address: Https://github.com/CodisLabs/codis), Codis cluster relies on zookeeper cluster, this paper introduces the implementation of zookeeper cluster.

I. Introduction to the principle of zookeeper

Zookeeper is an open source distributed Application Coordination Service that contains a simple set of primitives that can be used by distributed applications to implement synchronization services, configure maintenance and naming services, and so on.

Zookeeper Design Purpose
    • Final consistency: The client connects to that server, and the same view is presented to it.
    • Reliability: With simple, robust, good performance, if message M is received by a server, then message M will be received by all servers.
    • Real-time: Zookeeper guarantees that the client will get updates to the server at a time interval, or information that the server is failing. However, due to network delay and other reasons, zookeeper cannot guarantee that two clients can get the newly updated data at the same time, if you need the latest data, you should call the sync () interface before reading the data.
    • Wait irrelevant (Wait-free): Slow or invalid client must not interfere with fast client requests, so that each client can effectively wait.
    • Atomicity: Updates can only succeed or fail with no intermediate state.
    • Sequence: including global order and partial order: Global order is that if message A is published before message B on a server, message A will be published in front of message B on all servers, and the partial order means that if a message B is published by the same sender after message A, a will be in front of B.
Zookeeper Working principle

1, in the Zookeeper cluster, each node has the following 3 roles and 4 states:

Role: Leader,follower,observer
Status: Leading,following,observing,looking

The core of zookeeper is atomic broadcasting, a mechanism that guarantees synchronization between the various servers. The protocol that implements this mechanism is called the Zab Protocol (ZooKeeper Atomic Broadcast Protocol). The ZAB protocol has two modes, namely the recovery Mode (recovery) and broadcast mode (broadcast synchronization). When the service is started or after the leader crashes, the Zab enters the recovery mode, and when the leader is elected and most of the servers are synchronized with the leader state, the recovery mode is finished. State synchronization ensures that the leader and server have the same system state.

To ensure the sequential consistency of transactions, zookeeper uses an incremented transaction ID number (ZXID) to identify transactions. All the proposals (proposal) were added to the ZXID when they were presented. The implementation of ZXID is a 64-bit number, it is 32 bits high is the epoch used to identify whether the leader relationship changes, each time a leader is chosen, it will have a new epoch, marking the current period of the reign of the leader. The low 32 bits are used to increment the count.

Each server has 4 states in the process of working:

Looking: Current server does not know who leader is, is searching.

Leading: The current server is an elected leader.

The Following:leader has been elected and the current server is in sync with it.

Observing:observer's actions are in most cases identical to those of follower, but they do not participate in elections and polls, but only accept the results of (observing) elections and voting.

Zookeeper cluster Nodes
    • The more zookeeper nodes are deployed, the higher the reliability of the service, the more likely it is to deploy an odd number of nodes, because the zookeeper cluster can take up to half the number of outages to make the entire cluster outage.
    • Need to give each zookeeper 1G of memory, if possible, preferably have a separate disk, because the independent disk can ensure that the zookeeper is high performance. If your cluster is heavily loaded, don't run zookeeper and regionserver on the same machine, just like Datanodes and Tasktrackers.
Experimental Environment
Host Name System IP Address
Linux-node1 CentOS Release 6.8 192.168.1.148
Linux-node2 CentOS Release 6.8 192.168.1.149
Linux-node2 CentOS Release 6.8 192.168.1.150
second, zookeeper installation

Zookeeper run requires a Java environment, need to install JDK, note: Each server needs to install zookeeper, JDK, recommended to download the required installation package locally and then upload to the server, the server above the download speed is too slow.

2.1. JDK Installation

Jdk:http://www.oracle.com/technetwork/java/javase/downloads/index.html

RPM-IVH jdk-8u101-linux-x64.rpm

2.2, Zookeeper installation

Zookeeper Link: http://zookeeper.apache.org/

wget Http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz-P/usr/local/src/tar ZXVF Zookeeper-3.4.8.tar.gz-c/optcd/opt && mv zookeeper-3.4.8 zookeepercd ZOOKEEPERCP conf/zoo_sample.cfg Conf/zoo . cfg

#把zookeeper加入到环境变量

Echo-e "# Append Zk_env\nexport path= $PATH:/opt/zookeeper/bin" >>/etc/profile
three, zookeeper cluster configuration

Note: When building a zookeeper cluster, you must first stop the zookeeper node that has already been started.

3.1. Zookeeper configuration file Modification

#修改过后的配置文件zoo. CFG, as follows:

Egrep-v "^#|^$" zoo.cfg
ticktime=2000initlimit=10synclimit=5datalogdir=/opt/zookeeper/logsdatadir=/opt/zookeeper/dataclientport= 2181autopurge.snapretaincount=500autopurge.purgeinterval=24server.1= 192.168.1.148:2888:3888server.2= 192.168.1.149:2888:3888server.3= 192.168.1.150:2888:3888

#创建相关目录, all three nodes need

Mkdir-p/opt/zookeeper/{logs,data}

#其余zookeeper节点安装完成之后, synchronize the configuration file zoo.cfg.

3.2. Configuration parameter Description

Ticktime this time is the time interval between the zookeeper server or between the client and the server to maintain the heartbeat, meaning that each ticktime time sends a heartbeat.

Initlimit This configuration item is used to configure the Zookeeper accept client (the client here is not the client that connects the zookeeper server, but the leader that is connected to follower in the Zookeeper server cluster) Server) The maximum number of heartbeat intervals that can be tolerated when a connection is initialized.

The client connection failed when the zookeeper server has not received the return information of the client after 10 heartbeats (that is, ticktime) length. The total length of time is 10*2000=20 seconds.

Synclimit This configuration item identifies the length of time that a message is sent between leader and follower, the duration of the request and response, and the maximum number of ticktime, the total length of time is 5*2000=10 seconds.

DataDir as the name implies is zookeeper to save the data directory, by default zookeeper will write the data log file is also stored in this directory;

ClientPort This port is the port that the client connects to the zookeeper server, zookeeper will listen to this port to accept the client's access request;

Server. A=b:c:d in A is a number, indicating this is the first server, B is the IP address of this server, C the first port for the cluster members of the exchange of information, indicating that the server and the cluster of leader server exchange information of the port, D is the port used exclusively for election leader when the leader is hung out.

3.3. Create ServerID logo

In addition to modifying the Zoo.cfg configuration file, the Zookeeper cluster mode also configures a myID file, which needs to be placed in the DataDir directory.

One of the data in this file is the value of a (which is a in the server.a=b:c:d in the Zoo.cfg file), and the myID file is created in the DataDir path configured in the Zoo.cfg file.

Create the myID file on the #在192.168.1.148 server and set the value to 1, consistent with the Server.1 in the Zoo.cfg file, as follows

echo "1" >/opt/zookeeper/data/myid

Create the myID file on the #在192.168.1.149 server and set the value to 1, consistent with the SERVER.2 in the Zoo.cfg file, as follows

echo "2" >/opt/zookeeper/data/myid

Create the myID file on the #在192.168.1.150 server and set the value to 1, consistent with the SERVER.3 in the Zoo.cfg file, as follows

echo "3" >/opt/zookeeper/data/myid

In this connection, the configuration is complete

Four, zookeeper cluster view
1. Start the Zookeeper node above each server:

#linux-node1, Linux-node2, Linux-node3

/opt/zookeeper/bin/zkserver.sh start

Note: Error troubleshooting

Zookeeper node can not start the possible cause: Zoo.cfg configuration file is wrong, iptables not off.

2. Review the status of each node after the boot is complete

#linux-node1

#linux-node2

#linux-node3

#从上面可以看出, linux-node1,linux-node3 Two server zookeeper state is follow mode, linux-node2 This server zookeeper state is leader mode.

Five, zookeeper cluster connection

After the zookeeper cluster is built, the client script can be connected to the zookeeper cluster, for the client, the zookeeper cluster is a whole, connected to the zookeeper cluster actually feel the entire cluster of services.
#在linux-node1 Test

You can see that the entire zookeeper cluster has been built and tested for completion.
#Zookeeper原理:
http://blog.csdn.net/wuliu_forever/article/details/52053557
Http://www.cnblogs.com/luxiaoxun/p/4887452.html

Original address of this article: http://www.linuxprobe.com/ethernet-channel-bonding.html

Zookeeper Cluster construction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.