ZooKeeper cluster Installation
ZooKeeper is a distributed service coordination system provided by Apache and widely used.
Kafka MQ is used in the project, while Kafka fully uses ZooKeeper to implement service coordination between Kafka components, including Broker and Consumer.
The Linux commands in this document start with # As the root user and start with $ as the zk user.
Create zk user
# Groupadd zk
# Useradd-g zk
# Passwd zk
Prepare the installation directory to create the ZooKeeper data storage directory:
# Mkdir-p/data/zookeeper
# Chown-R zk: zk/data/zookeeper
Use zk users to create data and log directories:
$ Mkdir/data/zookeeper/data
$ Mkdir/data/zookeeper/log
Install ZooKeeper to decompress the ZooKeeper Binary Package:
# Cd/usr/local/src
# Tar -zxvfzookeeper-3.4.6.tar.gz-C/usr/local/
# Chown-R zk: zk/usr/local/zookeeper-3.4.6 modify ZooKeeper configuration file:
$ Cd/usr/local/The zookeeper-3.4.6/conf
$ Cp zoo_sample.cfg zoo. cfg
$ Vi zoo. cgf
For details about how to modify the configuration, see dataDir, dataLogDir, and the list of Three ZooKeeper servers.
$ Vi log4j. prZ runtime? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcGVydGllczwvcD4KPHA + forward + CjxwPjxpbWcgc3JjPQ =" http://www.2cto.com/uploadfile/Collfiles/20140724/2014072413344752.png "alt =" \ ">
Create a ZooKeeperServerId File
Create a file named myid in the data directory of ZooKeeper with the content ServerId number. In the preceding configuration file, the myid content of the three ZooKeeper files is distributed as 1, 2, and 3.
$ Cd/data/zookeeper/data
$ Cat> myid
Enter 1, press Enter, and then press Ctrl + d. Modify the zk user's environment variables:
$ Vi ~ /. Bash_profile
Add the red box to the file:
$ Source ~ /. Bash_profile
Repeat the preceding steps to install ZooKeeper to the other two and build one or three ZooKeeper clusters.
Start ZooKeeper
All ZooKeeper in the cluster can be started using the following command:
$ ZkServer. sh start
Normally:
JMX enabled by default
Using config:/usr/local/zookeeper-3.4.6/bin/../conf/zoo. cfg
Starting zookeeper... STARTED
Run the following command to check whether ZooKeeper is successfully started:
$ ZkServer. sh status
If the startup is successful, it is displayed on the Leader's machine:
On the Follower machine, the following information is displayed:
Stop
$ ZkServer. sh stop