Install the Zookeeper cluster on CentOS7. Install java software on the Zookeeper cluster test machine on CentOS7 $ rpm-qa | grepjava $ sudoyuminstall-yjava-1.8.0-openjdk.x86_64 $ java-versionopenjdkversion1.8.0_6 install Zookeeper cluster on CentOS 7
Java software must be installed on the testing machine
$ Rpm-qa | grep java
$ Sudo yum install-y java-1.8.0-openjdk.x86_64
$ Java-version
Openjdk version "1.8.0 _ 65"
OpenJDK Runtime Environment (build 1.8.0 _ 65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
1. create a user: bjrenrui0001 ~ 0003
Sudo groupadd zookeeper
Sudo useradd-g zookeeper
Echo "zookeeper @1234" | sudo passwd zookeeper-stdin
2. create a working directory
Bjrenrui0001:
Sudo mkdir/yanfa/mq
Sudo ln-s/yanfa/mq
Sudo chown-R dreamjobs. dreamjobs/mq
Bjrenrui0002 ~ 0003:
Sudo mkdir mq
Sudo chown dreamjobs. dreamjobs mq
Sudo ln-s/home/backupfile/mq
Sudo chown dreamjobs. dreamjobs mq
1. Standalone mode)
Download and decompress
Cd/mq
Wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.7/zookeeper-3.4.7.tar.gz
Tar zxvf zookeeper-3.4.7.tar.gz-C/mq
Ln-s/mq/zookeeper-3.4.7 zookeeper
Start
The default mode is the standalone mode.
Cd/mq/zookeeper/
Cp./conf/zoo_sample.cfg./conf/zoo. cfg
Sh./bin/zkServer. sh start
Firewall enables port 2181
Check Service Status:
[Dreamjobs @ bjrenrui0001 bin] $ sh zkServer. sh status
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Mode: standalone
Use a java client to connect to ZooKeeper
./Bin/zkCli. sh-server 127.0.0.1: 2181
Then you can use various commands, which are similar to File operation commands. enter help to view all commands.
Close
Sh bin/zkServer. sh stop
2. Distributed mode)
In the production environment, you must configure the distributed mode to make full use of the power.
A ZooKeeper cluster is generally called ZooKeeper ensemble (integrated) or quorum (quorum ).
Prepare 3 machines
Assume that there are three machines, and the relationship between hostname and ip address is:
192.168.100.200 bjrenrui0001
192.168.100.201 bjrenrui0002
192.168.100.202 bjrenrui0003
ZooKeeper does not have an obvious master/slave relationship. each node is a server. if the leader fails, it will immediately elect a leader from follower.
Because there is no master-slave relationship, and there is no need to configure SSH and password-less login, each zk server is started by itself, and data is exchanged between them through the TCP port.
Create a log and Data Directory:
Bjrenrui0001 ~ 0003
Cd/mq/zookeeper
Mkdir-p zookeeperdatadir/{logs, data}
Modify the configuration file conf/zoo. cfg of bjrenrui0001:
[Dreamjobs @ bjrenrui0001 conf] $ grep-vE '^ ($ | #) 'Zoo. cfg
TickTime = 2000
InitLimit = 10
SyncLimit = 5
DataDir =/mq/zookeeper/zookeeperdatadir/data
DataLogDir =/mq/zookeeper/zookeeperdatadir/logs
ClientPort = 2181
Server.1 = bjrenrui0001: 2888: 3888
Server.2 = bjrenrui0002: 2888: 3888
Server.3 = bjrenrui0003: 2888: 3888
Copy the modification to bjrenrui0002 and bjrenrui0003.
Myid file:
Create a new myid file under dataDir of each machine and store a number to identify the current host.
Bjrenrui0001: echo "1">/mq/zookeeper/zookeeperdatadir/data/myid
Bjrenrui0002: echo "2">/mq/zookeeper/zookeeperdatadir/data/myid
Bjrenrui0003: echo "3">/mq/zookeeper/zookeeperdatadir/data/myid
Start the zookeeper service on each machine:
Bjrenrui0001: sh/mq/zookeeper/bin/zkServer. sh start
Bjrenrui0002: sh/mq/zookeeper/bin/zkServer. sh start
Bjrenrui0003: sh/mq/zookeeper/bin/zkServer. sh start
Stop the zookeeper service on each machine:
Bjrenrui0001: sh/mq/zookeeper/bin/zkServer. sh stop
Bjrenrui0002: sh/mq/zookeeper/bin/zkServer. sh stop
Bjrenrui0003: sh/mq/zookeeper/bin/zkServer. sh stop
Because the three nodes are started sequentially, when the three nodes are started one after another, some errors will be reported when the node that is started first connects to the node that is not started, can be ignored.
The Firewall enables port 2181:
Sudo vi/etc/sysconfig/iptables
-A input-p tcp-s 192.168.100.0/24-j ACCEPT
Sudo systemctl restart iptables. service
View status
[Dreamjobs @ bjrenrui0001 conf] $ gmbjyf. sh bjyfnbserver "cat/mq/zookeeper/zookeeperdatadir/data/myid"
Bjrenrui0001
1
Bjrenrui0002
2
Bjrenrui0003
3
$ Gmbjyf. sh bjyfnbserver "sh/mq/zookeeper/bin/zkServer. sh restart"
Bjrenrui0001
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Stopping zookeeper... STOPPED
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Starting zookeeper... STARTED
Bjrenrui0002
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Stopping zookeeper... STOPPED
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Starting zookeeper... STARTED
Bjrenrui0003
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Stopping zookeeper... STOPPED
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Starting zookeeper... STARTED
$ Gmbjyf. sh bjyfnbserver "sh/mq/zookeeper/bin/zkServer. sh status"
Bjrenrui0001
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Mode: follower
Bjrenrui0002
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Mode: leader
Bjrenrui0003
ZooKeeper JMX enabled by default
Using config:/mq/zookeeper/bin/../conf/zoo. cfg
Mode: follower
Use a java client to connect to the ZooKeeper cluster
Find a machine and decompress the zookeeper package. you can use the java client to connect to any server in the ZooKeeper cluster without configuration.
$ Sh/mq/zookeeper/bin/zkCli. sh-server bjrenrui0001: 2181
$ Sh/mq/zookeeper/bin/zkCli. sh-server bjrenrui0002: 2181
$ Sh/mq/zookeeper/bin/zkCli. sh-server bjrenrui0003: 2181
Install java software $ rpm-qa | grep java $ sudo yum install-y java-1.8.0-openjdk.x86_64 $ java-version openjdk version "1.8.0 _ 6...