Distributed service coordination technology zookeeper series (1) & mdash; zookeeper introduction and linux installation (single node), zookeeperlinux

Source: Internet
Author: User

Distributed service coordination technology zookeeper series (1) -- Introduction to zookeeper and installation on linux (single node), zookeeperlinux
Introduction to ZooKeeper

ZooKeeper is a Distributed Coordination Service framework. It is usually used to solve some management and coordination problems encountered in distributed projects, such as Uniform Naming Service, distributed configuration management, distributed lock, and cluster node status Coordination.

Download

Go to http://apache.fayea.com/zookeeper/download zookeeper-3.4.9, and upload ftpto Linux

Extract

[Root @ localhost ftpuser] # tar-zxvf zookeeper-3.4.9.tar.gz

Create a data log directory

Create the following two folders under the decompressed directory of zookeeper:

 

[Root @ localhost zookeeper-3.4.9] # mkdir data

[Root @ localhost zookeeper-3.4.9] # mkdir logs

 

Copy configuration file

Copy the zoo_sample.cfg file to the conf directory in the decompressed directory of zookeeper and name it zoo. cfg.

 

[Root @ localhost conf] # cp zoo_sample.cfg zoo. cfg

Modify configuration file

[Root @ localhost conf] # vi 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

# 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

# Synchronization phase can take

InitLimit = 10

# The number of ticks that can pass

# 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/ftpuser/zookeeper-3.4.9/data

DataLogDir =/home/ftpuser/zookeeper-3.4.9/logs

# The port at which the clients will connect

ClientPort = 2181

Server.1 = 192.168.2.129: 2888: 3888

# 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

# 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

 

Configure dataDir, dataLogDir, and server in zoo. cfg.

Server. A = B: C: D: where A is A number, indicating the server number. B is the service.

C Indicates the port on which the server exchanges information with the Leader server in the cluster. D indicates that if the Leader server in the cluster fails, A port is required for re-election and a new Leader is selected, which is the port used for server communication during the election.

 

The clientPort is the port connecting the client (Application) to the Zookeeper server. Zookeeper will listen on this port to accept access requests from the client.

Create a myid File

Go to/home/ftpuser/zookeeper-3.4.9/data and create the myid File

 

[Root @ localhost conf] # cd/home/ftpuser/zookeeper-3.4.9/data

[Root @ localhost data] # vi myid

1

 

Edit the myid file and enter the corresponding number on the machine of the corresponding IP address. For example, on zookeeper, myid

The file content is 1. If you only install and configure on a single point, there is only one server.1

Add Environment Variables

[Root @ localhost data] # vi/etc/profile

 

Add zookeeper environment variable at the end of the file

 

# Zookeeper env

Export ZOOKEEPER_HOME =/home/ftpuser/zookeeper-3.4.9/

Export PATH = $ ZOOKEEPER_HOME/bin: $ PATH

 

Run the source/etc/profile command to make the environment variable take effect. Run echo $ ZOOKEEPER_HOME to view

Open Port

Open the ports 2181, 2888, and 3888 to be used in the firewall. Open/etc/sysconfig/iptables and add the following three lines

 

[Root @ localhost data] # cat/etc/sysconfig/iptables

# Generated by iptables-save v1.4.7 on Thu Jun 2 22:41:13 2016

* Filter

: Input accept [5:320]

: Forward accept [0: 0]

: Output accept [4: 464]

-A input-p udp-m udp -- dport 23-j ACCEPT

-A input-p tcp-m tcp -- dport 23-j ACCEPT

-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

COMMIT

# Completed on Thu Jun 2 22:41:13 2016

 

[Root @ localhost data] #

 

View port startup status

 

[Root @ localhost data] # service iptables status

 

Start zookeeper

[Root @ localhost zookeeper-3.4.9] # cd bin

[Root @ localhost bin] # ll

Total 36

-Rwxr-xr-x. 1 1001 1001 232 Aug 23 README.txt

-Rwxr-xr-x. 1 1001 1001 1937 Aug 23 zkCleanup. sh

-Rwxr-xr-x. 1 1001 1001 1032 Aug 23 zkCli. cmd

-Rwxr-xr-x. 1 1001 1001 1534 Aug 23 zkCli. sh

-Rwxr-xr-x. 1 1001 1001 1579 Aug 23 zkEnv. cmd

-Rwxr-xr-x. 1 1001 1001 2696 Aug 23 zkEnv. sh

-Rwxr-xr-x. 1 1001 1001 1065 Aug 23 zkServer. cmd

-Rwxr-xr-x. 1 1001 1001 6773 Aug 23 zkServer. sh

[Root @ localhost bin] # zkServer. sh start

ZooKeeper JMX enabled by default

Using config:/home/ftpuser/zookeeper-3.4.9/bin/../conf/zoo. cfg

Starting zookeeper... STARTED

View zookeeper background logs

[Root @ localhost ~] # Tail-f/home/ftpuser/zookeeper-3.4.9/bin/zookeeper. out

View the zookeeper Process

[Root @ localhost bin] # jps

2011 QuorumPeerMain

1245 Bootstrap

Jps 2030

[Root @ localhost bin] #

 

Among them, QuorumPeerMain is the zookeeper process and starts normally. View status

 

[Root @ localhost bin] # zkServer. sh status

ZooKeeper JMX enabled by default

Using config:/home/ftpuser/zookeeper-3.4.9/bin/../conf/zoo. cfg

Mode: standalone

[Root @ localhost bin] #

Stop the zookeeper Process

[Root @ localhost bin] # zkServer. sh stop

ZooKeeper JMX enabled by default

Using config:/home/ftpuser/zookeeper-3.4.9/bin/../conf/zoo. cfg

Stopping zookeeper... STOPPED

[Root @ localhost bin] #

Connect the client to zookeeper

[Root @ localhost bin] #./zkCli. sh-server 192.168.2.129: 2181

 

Enter the help command to view the commands

 

[Zk: 192.168.2.129: 2181 (CONNECTED) 0] help

ZooKeeper-server host: port cmd args

Connect host: port

Get path [watch]

Ls path [watch]

Set path data [version]

Rmr path

Delquota [-n |-B] path

Quit

Printwatches on | off

Create [-s] [-e] path data acl

Stat path [watch]

Close

Ls2 path [watch]

History

Listquota path

SetAcl path acl

GetAcl path

Sync path

Redo upload No

Addauth scheme auth

Delete path [version]

Setquota-n |-B val path

[Zk: 192.168.2.129: 2181 (CONNECTED) 1]

Related Article

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.