Zookeeper (a) - cluster environment deployment

Zookeeper Brief

Zookeeper is an open source distributed application coordination service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. Zookeeper provides a simple API for handling complex distributed coordination problems to the user. Detailed action:

  • Name service life: by name identifies the cluster node
  • Configuration Management: Add new or recent node configuration information
  • Cluster management: real-time joining / leaving nodes in the cluster or node status
  • Election algorithm: a node election as leader of the purpose of coordination
  • Locking and synchronization service - lock data while modifying data. This mechanism can help you automatically failover when connected to other distributed applications (such as Apache HBase)
  • Highly reliable data registry - can be obtained even when turned off in one or several data nodes
    official website: https://zookeeper.apache.org/
    Mirror Address: http://mirror.bit.edu.cn/apache/ zookeeper /

Cluster structures

Server ready

The zookeeper er brief
Zookeeper is an open source distributed application coordination service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. Zookeeper provides a simple API for handling complex distributed coordination problems to the user. Detailed action:

  • Name service life: by name identifies the cluster node
  • Configuration Management: Add new or recent node configuration information
  • Cluster management: real-time joining / leaving nodes in the cluster or node status
  • Election algorithm: a node election as leader of the purpose of coordination
  • Locking and synchronization service - lock data while modifying data. This mechanism can help you automatically failover when connected to other distributed applications (such as Apache HBase)
  • Highly reliable data registry - can be obtained even when turned off in one or several data nodes
    official website: https://zookeeper.apache.org/
    Mirror Address: http://mirror.bit.edu.cn/apache/ zookeeper /

Cluster structures

Preparing the Environment

1. Machine number
zookeeper server should be set to an odd number which is due to fault tolerance zookeeper, i.e., the number of machines running the cluster zookeeper greater than the number of downtime, which can then zookeeper normal service. So three machines can allow one down, and two machines down after a station can not work. Machine downtime can be two to five, and six machines can only be down two, so there is no need to use six, and therefore generally deployed odd units.
2.java environment
running java zookeeper need to prepare the environment and set the environment variable.

Zookeeper deployment

1. In the mirror node compressed download the desired version
2. extract to the specified directory

[zookeeper@VM_0_10_centos ~]$ ll
total 35824
drwxrwxr-x  3 zookeeper zookeeper     4096 Aug 30 09:04 data
drwxrwxr-x  3 zookeeper zookeeper     4096 Aug 27 16:07 logs
drwxr-xr-x 10 zookeeper zookeeper     4096 Mar 27  2018 zookeeper-3.4.12
-rw-r--r--  1 root      root      36667596 Aug 20 09:03 zookeeper-3.4.12.tar.gz

3. Modify the configuration file
exists zoo_sample.cfg originally in the conf directory, you should rename this profile zoo.conf, and modify the corresponding configuration items:
DOC file Zookeeper official website gives the profile of the interpretation and meaning
https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_minimumConfiguration
lowest cluster configuration can be as follows

# 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 between 
# sending a request and getting an acknowledgement
syncLimit=5
dataDir=/app/zookeeper/data
dataLogDir=/app/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
server.1=0.0.0.0:2888:3888
server.2=*.*.*.*:2888:3888
server.3=*.*.*.*:2888:3888

tickTime:
time unit of Zookeeper. Zookeeper All times are integer multiples with this (2000) to configure the unit time. For example, the minimum time-out session is 2 * tickTime, the maximum time-out of the session 20 is tickTime, after version 3.3.0, the configuration server and introduces minSessionTimeout maxSessionTimeout, these two parameters will limit the time a session connection , timeout client settings will be uploaded to the zookeeper's service, and the service will end this time than the size of the two parameters above, if in intermediate, client parameters take effect, if it exceeds the upper limit (maxSessionTimeout) will be to maxSessionTimeout a session timeout, similarly to below the lower limit will prevail minSessionTimeout configuration. If in the absence of these two parameters, it will order [2 tickTime, 20 is tickTime] for the upper and lower bounds. The default configuration values tickTime is 2000, if tickTime configuration items are not, the default value is 3000. connected to the client's attention paid to these parameters (unit: ms)

minSessionTimeout : (No Java system property) New in 3.3.0: the minimum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 2 times the tickTime.

maxSessionTimeout : (No Java system property) New in 3.3.0: the maximum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 20 times the tickTime.

initLimit:
When the Observer and Follower started, when the latest data from the synchronous Leader, Leader permitted initLimit * tickTime time to complete. If a larger amount of data synchronization is large, it can be provided corresponding to this value. The default value is 10
syncLimit:
indicates the maximum waiting time and Observer Follower Leader interact with, only after the synchronization is completed and Leader, when entering the timeout request message interaction like a normal forward or ping.
dataDir:
transaction logs, and data snapshots are written in the directory. Myid while the node number stored in the directory should also dataDir the
dataLogDir:
used to set the transaction log path
clientPort:
port number of client connections zookeeper
server.x:
server.x = [hostname]: nnnnn [: nnnnn], where X represents the node number, it should be expressed in numbers consistent with myid. hostname for the ip service node, you can configure the right number two port for data communication and synchronization and communication voting Leader elections. Note, ip of the machine should be set to 0.0.0.0.:nnnn:nnnn
create 4. dataDir and dataLogDir
attention to create the path and directory name should be consistent with maintaining the configuration file

[zookeeper@VM_0_10_centos ~]$ pwd
/app/zookeeper
[zookeeper@VM_0_10_centos ~]$ mkdir data

Myid created in the data directory, configuration and zoo.cfg in server.x label consistent

The cluster starts

1. Start command
startup script should be in the bin directory under

[zookeeper@VM_0_10_centos bin]$ pwd
/app/zookeeper/zookeeper-3.4.12/bin
[zookeeper@VM_0_10_centos bin]$ ll
total 172
-rwxr-xr-x 1 zookeeper zookeeper    232 Mar 27  2018 README.txt
-rwxr-xr-x 1 zookeeper zookeeper   1937 Mar 27  2018 zkCleanup.sh
-rwxr-xr-x 1 zookeeper zookeeper   1056 Mar 27  2018 zkCli.cmd
-rwxr-xr-x 1 zookeeper zookeeper   1534 Mar 27  2018 zkCli.sh
-rwxr-xr-x 1 zookeeper zookeeper   1759 Mar 27  2018 zkEnv.cmd
-rwxr-xr-x 1 zookeeper zookeeper   2696 Mar 27  2018 zkEnv.sh
-rwxr-xr-x 1 zookeeper zookeeper   1089 Mar 27  2018 zkServer.cmd
-rwxr-xr-x 1 zookeeper zookeeper   6773 Mar 27  2018 zkServer.sh

Start Service

[zookeeper@VM_0_10_centos bin]$ ./zkServer.sh start

2. Note
the best according to myid small to large order to start the service node
3. Check the state

[zookeeper@VM_0_10_centos bin]$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /app/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: leader

Use ./zkServer.sh status view the boot state, if the cluster started successfully, there will be more than (leader node) state, if it is follwer node, it is

[app@ecs-s6-medium-2-linux-20190828164230 bin]$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /app/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower

4. error conditions View
If you view the status of the server start is a failure, need to see the wrong reasons

[zookeeper@vultr bin]$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /app/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

In zookeeper.out can view files in the bin directory

-rw-rw-r-- 1 zookeeper zookeeper 23615 Aug 28 16:27 zookeeper.out

Guess you like

Origin www.cnblogs.com/limushu/p/11458633.html