People, always inevitable knot, limit themselves, difficult to move forward. The understanding of zookeeper, as well as the practice has dragged on for a long time, today to learn a little bit, fill some dry.
First, briefly zookeeper is Google's chubby an open source implementation, is a highly effective and reliable collaborative work system, zookeeper can be used to elect leader (based on Fast Paxos protocol), configuration information maintenance, in a distributed environment, Requires a master instance or stores some configuration information to ensure consistency of file writes. Zookeeper is a distributed, open-source, distributed application Coordination service that contains a simple set of primitives that is an important component of Hadoop and HBase, providing both Java and C interfaces. The Zookeeper code version provides a distributed, exclusive lock, election, queue interface. Where the distribution locks and queues have Java and C two versions, the election is only Java version. Second, the configuration services I directly on the Ubuntu server to open, skip the download, installation and other basic operations, straight to the topic. Zookeeper recommends using hostname, not IP. This requires the host's
/etc/hostnameAnd
/etc/hostsDo the host binding. The zookeeper is based on the fast Paxos algorithm and is used to complete the leader elections, so at least 3 nodes are required. To do this, I prepared the following 3 nodes: 192.168.158.135 ubuntu-zookeeper-01
192.168.158.151 ubuntu-zookeeper-02
192.168.158.152 ubuntu-zookeeper-03
First, configure your own hostname for each host:
- sudo vim/etc/hostname
For example, configuring/etc/hostname on the 192.168.158.135 machine is:
Ubuntu-zookeeper-01
Then, configure the host bindings for the individual hosts:
- sudo vim/etc/hosts
sudo vim/etc/hosts
For example:
Host bindings are done on the hosts.
The following effect is achieved, indicating that the configuration Ok[email protected]:~$ Ping ubuntu-zookeeper-02
PING ubuntu-zookeeper-02 (192.168.158.151) bytes of data.
Bytes from ubuntu-zookeeper-02 (192.168.158.151): icmp_seq=1 ttl=64 time=5.64 ms
Bytes from ubuntu-zookeeper-02 (192.168.158.151): icmp_seq=2 ttl=64 time=0.643 ms
Bytes from ubuntu-zookeeper-02 (192.168.158.151): icmp_seq=3 ttl=64 time=0.821 ms
Bytes from ubuntu-zookeeper-02 (192.168.158.151): icmp_seq=4 ttl=64 time=0.873 ms
^c
---ubuntu-zookeeper-02 ping statistics---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
RTT Min/avg/max/mdev = 0.643/1.994/5.641/2.107 ms
Next, configure the zookeeper to run quickly.
Configure the hostname you have just prepared in this file:
- sudo vim/etc/zookeeper/conf/zoo.cfg
sudo vim/etc/zookeeper/conf/zoo.cfg
Description of the configuration file:
-
- Ticktime: The base event unit, in milliseconds. This time is the interval between Zookeeper servers or between the client and server, which means that each ticktime time sends a heartbeat.
- DataDir: The location of the database snapshot stored in memory, 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 listens to the port and accepts the client's access request.
- Initlimit: This configuration item is used to configure the maximum number of heartbeat intervals that Zookeeper accepts when a client initiates a connection, and the server has not received the return information of the client after 5 heartbeat (that is, ticktime) length Zookeeper This indicates that the client connection failed. The total length of time is 5*2000=10 seconds.
- Synclimit: This configuration item identifies the length of time that a message, request and response is sent between Leader and Follower, the maximum number of ticktime, and the total length of time is 2*2000=4 seconds
- Server. A = B:c:d:a indicates this is the number of server, B is the IP address of this server, C is the server and the cluster of Leader server exchange information port; D means that in case the Leader server in the cluster is hung up, a port is needed to re-elect a new Leader
Next, make the server.1~server.3 correspond to the /etc/zookeeper/conf/myid of each host :
- sudo vim/etc/zookeeper/conf/myid
sudo vim/etc/zookeeper/conf/myid
For example,ubuntu-zookeeper-01 corresponds to Server.1 , and its myID value is 1 .
$ Cat/etc/zookeeper/conf/myid
1
If a similar error occurs:
[Email protected]:~$ sudo/usr/share/zookeeper/bin/zkserver.sh Status
JMX enabled by default
Using Config:/etc/zookeeper/conf/zoo.cfg
Error contacting service. It is probably not running.
Note that the corresponding label in the myID file is inconsistent with the hostname, that is, ubuntu-zookeeper-01 corresponds to server.1 , and the value ofmyID should be 1.
Now, we can start the service:
- sudo/usr/share/zookeeper/bin/zkserver.sh start
sudo/usr/share/zookeeper/bin/zkserver.sh start
The specific commands available are:
{Start|start-foreground|stop|restart|status|upgrade|print-cmd}
Finally, observe the boot log:
- Tail-f/var/log/zookeeper/zookeeper.log
Exactly which machine becomes leader:
[Email protected]:~$ sudo/usr/share/zookeeper/bin/zkserver.sh Status
JMX enabled by default
Using Config:/etc/zookeeper/conf/zoo.cfg
Mode:follower
[Email protected]:~$ sudo/usr/share/zookeeper/bin/zkserver.sh Status
JMX enabled by default
Using Config:/etc/zookeeper/conf/zoo.cfg
Mode:follower
[Email protected]:~$ sudo/usr/share/zookeeper/bin/zkserver.sh Status
JMX enabled by default
Using Config:/etc/zookeeper/conf/zoo.cfg
Mode:leader
Services are started, ubuntu-zookeeper-03 become leader node ~
Transferred from: http://snowolf.iteye.com/blog/2156019
Linux->zookeeper Cluster Construction