Build a zookeeper learning cluster environment and a zookeeper Cluster

Source: Internet
Author: User

Build a zookeeper learning cluster environment and a zookeeper Cluster
I. installation environment

Zookeeper: 3.4.6

JDK: 1.8

Linux: centos6.5 64-bit

Host:

Server0: 192.168.0.20.
Server1: 192.168.0.225
Server2: 192.168.0.226

Ii. Installation
1. Decompress ZK to/usr/local/zookeeper.
2. modify the configuration file (configuration environment variable)/etc/profile
JAVA_HOME =/usr/local/jdk1.8ZOOKEEPER _ HOME =/usr/local/zookeeperPATH = $ JAVA_HOME/bin: $ ZOOKEEPER_HOME/bin: $ PATHCLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jarexport JAVA_HOME ZOOKEEPER_HOME PATH CLASSPATH
3. Set source/etc/profile to take effect.
4. modify the configuration file name of zk/usr/local/zookeeper/conf/zoo_sample.cfg [root @ rocketmq-nameserver1 conf] # mv zoo_sample.cfg zoo. cfg
5. Modify and configure zoo. cfg # data storage path dataDir =/usr/local/zookeeper/data
6. Create the myid file server0: 192.168.0.20.myid = 0server1: 192.168.0.225 myid = 1server2: 192.168.0.226 myid = 2 under/usr/local/zookeeper.
7. zoo. cfg configure the cluster node to add server.0 = 192.168.0.20.: 2888: 3888server at the end of the file. 1 = 192.168.0.225: 2888: 3888server. 2 = 192.168.0.226: 2888: 38888, zk startup for environment variable configuration: zkServer. sh start does not configure environment variables can be started in the zk bin directory [root @ rocketmq-nameserver1 bin] #. /zkServer. sh starts these three servers

1. startup exception:

[root@localhost bin]# ./zkServer.sh statusJMX enabled by defaultUsing config: /usr/local/zookeeper/bin/../conf/zoo.cfgError contacting service. It is probably not running.

If this happens, try to enable port 2181 (or disable the firewall)

/Sbin/iptables-I INPUT-p tcp -- dport 2181-j ACCEPT write modification/etc/init. d/iptables save modification service iptables restart firewall, modification takes effect

Service iptables stop disable Firewall

2. Check whether the startup is successful: view the three servers separately.

[root@localhost bin]# ./zkServer.sh statusJMX enabled by defaultUsing config: /usr/local/zookeeper/bin/../conf/zoo.cfgMode: follower
3. Configuration File
# The number of milliseconds of each tick # tickTime is used as The interval between The zookeeper server or between The client and The server to maintain The heartbeat, that is, each tickTime sends a heartbeat. TickTime = 2000 # The number of ticks that the initial # synchronization phase can take # initLimit this configuration item is used to configure zookeeper to accept The client (the client mentioned here is not The client where the user connects to The zookeeper server, instead, the follower server connecting to the leader in the zookeeper server cluster)
The maximum heartbeat interval that can be tolerated during connection initialization. # If the length of the heartbeat exceeds 10 (tickTime), the zookeeper server has not received the response from the client, which indicates that the connection to the client fails. The total length is 10*2000 = 20 seconds. InitLimit = 10 # The number of ticks that can pass between # sending a request and getting an acknowledgement # The length of The request and response time between The leader and follower, the maximum length of a tickTime is 5*2000 = 10 seconds. SyncLimit = 5 # the directory where the snapshot is stored. # do not use/tmp for storage,/tmp here is just # example sakes. # dataDir, as its name implies, is the directory where zookeeper saves data. By default, zookeeper stores the log files that write data in this directory; dataDir =/usr/local/zookeeper/data # the port at which the clients will connect # clientPort is the port on which the client connects to the Zookeeper server, zookeeper listens to this port to accept client access requests; clientPort = 2181 # 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 # server. A = B: C: D indicates the number of the server, B indicates the IP address of the server, and the first port of C is used to exchange information of cluster members, port used to exchange information between the server and the leader server in the cluster,
D is the port used for election leader when the leader fails. Server.0 = 192.168.0.133: 2888: 3888server. 1 = 192.168.0.225: 2888: 3888server. 2 = 192.168.0.226: 2888: 3888

Log File configuration: cat/usr/local/zookeeper/bin/zkEnv. sh

ZOOBINDIR="${ZOOBINDIR:-/usr/bin}"ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."if [ "x$ZOOCFGDIR" = "x" ]then  if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then    ZOOCFGDIR="$ZOOBINDIR/../conf"  else    ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper"  fifiif [ -f "${ZOOCFGDIR}/zookeeper-env.sh" ]; then  . "${ZOOCFGDIR}/zookeeper-env.sh"fiif [ "x$ZOOCFG" = "x" ]then    ZOOCFG="zoo.cfg"fiZOOCFG="$ZOOCFGDIR/$ZOOCFG"if [ -f "$ZOOCFGDIR/java.env" ]then    . "$ZOOCFGDIR/java.env"fiif [ "x${ZOO_LOG_DIR}" = "x" ]then    ZOO_LOG_DIR="/usr/local/zookeeper/logs"fiif [ "x${ZOO_LOG4J_PROP}" = "x" ]then    ZOO_LOG4J_PROP="INFO,CONSOLE"
Iv. Common commands

1. log on to the server: zkCli. sh-server localhost: 2181

2. View help:

[zk: 192.168.1.13:2181(CONNECTED) 0] helpZooKeeper -server host:port cmd args    stat path [watch]    set path data [version]    ls path [watch]    delquota [-n|-b] path    ls2 path [watch]    setAcl path acl    setquota -n|-b val path    history     redo cmdno    printwatches on|off    delete path [version]    sync path    listquota path    rmr path    get path [watch]    create [-s] [-e] path data acl    addauth scheme auth    quit     getAcl path    close     connect host:port

3. View nodes in a directory:

[zk: 192.168.1.13:2181(CONNECTED) 1] ls /[zookeeper]

4. Create a node: Create a New Znode node "zkTest" and its related content myData,

[zk: 192.168.1.13:2181(CONNECTED) 2] create /zkTest myDataCreated /zkTest

5. view the content in the node

[zk: 192.168.1.13:2181(CONNECTED) 4] get /zkTestmyDatacZxid = 0x300000002ctime = Wed Aug 16 19:48:01 CST 2017mZxid = 0x300000002mtime = Wed Aug 16 19:48:01 CST 2017pZxid = 0x300000002cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 6numChildren = 0

6. Modify node content

[zk: 192.168.1.13:2181(CONNECTED) 5] set /zkTest testSetcZxid = 0x300000002ctime = Wed Aug 16 19:48:01 CST 2017mZxid = 0x300000003mtime = Wed Aug 16 19:52:22 CST 2017pZxid = 0x300000002cversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 7numChildren = 0

7. delete a node

[zk: 192.168.1.13:2181(CONNECTED) 7] delete /zkTest[zk: 192.168.1.13:2181(CONNECTED) 9] ls /[zookeeper]

 

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.