ZooKeeper Version: 3.4.5
I environment: a virtual machine to install three Linux workstation
host names are: hadoop / hadoop01 / hadoop02
the JDK version: 1.7
1: Unzip
tar -zxvf zookeeper-3.4.5.tar.gz(解压)
2: rename
mv zookeeper-3.4.5 zookeeper(重命名文件夹zookeeper-3.4.5为zookeeper)
3: Modify environment variables
vim /etc/profile(修改文件)
4: Recompile the modified configuration file to make it effective
source /etc/profile
Note: The above three zookeepers need to be modified
Next is the configuration and modification of the ZooKeeper environment
cd zookeeper/conf
cp zoo_sample.cfg zoo.cfg
, (zoo.cfg is the actual loading configuration file)
vi zoo.cfg
Add content
1. dataDir=/home/hadoop/zookeeper/data --注意其他主机路径是否一致
2. dataLogDir=/home/hadoop/zookeeper/log --注意其他主机路径是否一致
3. server.1=hadoop:2888:3888 (主机名, 心跳端口、数据端口)
4. server.2=hadoop01:2888:3888
5. server.3=hadoop02:2888:3888
Create folder
cd /home/hadoop/zookeeper/
mkdir -m 755 data
mkdir -m 755 log
Create a new myid file in the data folder. The content of the myid file is:
cd data
vi myid
Added content: 1
Distribute the cluster to other machines:
scp -r /home/hadoop/zookeeper hadoop@hadoop01:/home/hadoop/
scp -r /home/hadoop/zookeeper hadoop@hadoop02:/home/hadoop/
Modify the configuration files of other machines
到hadoop01上:修改myid为:2
到hadoop02上:修改myid为:3
So far, ZooKeeper has been installed and configured!
Before starting ZooKeeper, you need to do some configuration of the firewall, otherwise it will cause startup failure.
Take iptables as an example: the following is a success:
直接修改配置文件:
vi /etc/sysconfig/iptables @添加一下三行
-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
或者对指定端口做临时修改(重启之后失效,此种方式不许重启防火墙.)
iptables -I INPUT -p tcp --dport 2181 -j ACCEPT
iptables -I INPUT -p tcp --dport 2888 -j ACCEPT
iptables -I INPUT -p tcp --dport 3888 -j ACCEPT
重启防火墙:
service iptables restart
查看防火墙端口状态:
service iptables status
Then you can start ZooKeeper and
enter the zookeeper directory: zkServer.sh start
View process: jps (QuorumPeerMain is the zookeeper process)